Add clear/reset methods for histograms and counters#199
Add clear/reset methods for histograms and counters#199zakcutner wants to merge 2 commits intoprometheus:masterfrom
Conversation
Signed-off-by: Zak Cutner <zak@cloudflare.com>
Signed-off-by: Zak Cutner <zak@cloudflare.com>
3c27c22 to
90f6836
Compare
|
Hi @zakcutner, thank you for your contribution!
Is there a use-case for this outside of testing? Are you aware of any Prometheus client libraries in other languages that offer these methods? |
|
Thanks for getting back to me @mxinden!
Not that I've encountered 🙂
I'm only familiar with the official client library for Golang, and it doesn't look like that one has clear/reset methods. It also doesn't seem to have a clear method for families, like this library already does. |
Thanks for this great project! I noticed that families have a
clearmethod, but nothing like this exists for histograms and counters. I figured out that you can get around this for counters with.inner().store(0, Ordering::Relaxed)(although using.inner()does not feel so nice to me), but I couldn't find a way to do this for histograms.I've found that clearing/resetting metrics is particularly useful for testing, to avoid needing to compare each metric to the value it was at the beginning of the test. Therefore, I've added methods to clear/reset histograms and counters in this PR. I'm also happy to first create an issue if some discussion on adding these methods is needed.