Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clear/reset methods for histograms and counters #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zakcutner
Copy link

Thanks for this great project! I noticed that families have a clear method, 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.

Signed-off-by: Zak Cutner <zak@cloudflare.com>
Signed-off-by: Zak Cutner <zak@cloudflare.com>
@mxinden
Copy link
Member

mxinden commented Jun 4, 2024

Hi @zakcutner, thank you for your contribution!

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.

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?

@zakcutner
Copy link
Author

Thanks for getting back to me @mxinden!

Is there a use-case for this outside of testing?

Not that I've encountered 🙂

Are you aware of any Prometheus client libraries in other languages that offer these methods?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants