Counter allows no way to reset to zero
See original GitHub issueCurrently, the Counter
class provides as its only way to alter the value the Inc()
method. This method only takes values >= 0, which means that there is no way to reset the Counter
and no way to decrement its value.
I am using the Counter
class to mirror a value from a Windows performance counter, which acts as a counter. Because I have no way to interact with the Counter
other than increment it, I am required to track each value that I retrieve from the performance counter, and compare it against each new sample, and do the math myself to determine how much it’s incremented.
It’s my understanding that the Prometheus server itself does this math. The documentation at https://prometheus.io/docs/instrumenting/writing_clientlibs/ allows client libraries to offer a method to reset Counter values to zero. I believe this would be a useful functionality, but it is not enough alone to eliminate the requirement for client code to maintain the previously sampled value and compare the current value.
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (4 by maintainers)
Use case: Unit testing. I have one unit test that runs incrementing the counter then would like to reset it to 0 for the next one. Really inconvenient to have to unregister the reregister it.
Hi @sandersaares ,
The official Prometheus doc mentioned it might be useful to create a reset function for Counter
is it worth to consider adding a reset function?