client_rust icon indicating copy to clipboard operation
client_rust copied to clipboard

Add clear/reset methods for histograms and counters

Open zakcutner opened this issue 1 year ago • 2 comments

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.

zakcutner avatar May 28 '24 16:05 zakcutner

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?

mxinden avatar Jun 04 '24 10:06 mxinden

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.

zakcutner avatar Jun 04 '24 14:06 zakcutner