question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Counter allows no way to reset to zero

See original GitHub issue

Currently, 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:closed
  • Created 6 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

35reactions
joeySchentrupcommented, Apr 7, 2020

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.

9reactions
zscncommented, Jan 7, 2020

Hi @sandersaares ,

The official Prometheus doc mentioned it might be useful to create a reset function for Counter

Counter is a monotonically increasing counter. It MUST NOT allow the value to decrease, however it MAY be reset to 0 (such as by server restart).

is it worth to consider adding a reset function?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is the counter not being reset to 0 in a recursive ...
1 Answer 1 ... counter is a variable local to the method. This means that each recursive stack frame (each new method call...
Read more >
Is it possible to reset a counter reading back to 0
Use IK11, after entering Measuring Point, go to Edit>Replace Counter. This allows you to reset the counter to zero (or actual value on ......
Read more >
How to reset a counter to 0? : r/factorio
Use a decider combinator for the counter instead of an arithmetic combinator. Set it to some condition (for example: green signal = 0,...
Read more >
counter-reset
Zero is the default initial value, so if you omit it, it will be reset to zero by default. Negative values are allowed....
Read more >
JK Flip-Flop Counter: How to reset a counter?
The trivial solution is to just tie RESET to the reset pin of all the flip flops. The more interesting case is when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found