Hello All,
I am facing similar issue when using counters with labels. I have counters to track some events that only increases over time, like no of users submitted a form. These forms belongs to a year.
I want to track no of forms submitted for year, say 2019/2020/2021 etc. I am using labeled counter to track this.
I am using increase function to track no of forms submitted for particular year, in a given time range like increase( forms_submitted { year=2019 } [ 2h ] ).
Below is the observation
First If we query prometheus, they query result is empty.
On first inc(), it is incremented to 0. after second inc() the sum is 1.
As a solution, I have initialised the counter to zero (by doing inc(0) ) for all labels in the application code as I know the labels in advance.
If we can initialise the counter at the time of building it it could have solve the above issue.
I know that counter can not have set() method.
Internally for labeled counters, there are independent counters (children).
What if we have initialise() method in Builder, which initialises the value of the counter for all labels while creating labeled counter ?