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 GenericCounter::set() operation #471

Closed
wants to merge 2 commits into from

Conversation

tyranron
Copy link
Contributor

@tyranron tyranron commented Dec 12, 2022

Synopsis

I've written the metrics-prometheus crate, trying to pave the way for uniting ecosystems of prometheus and metrics crates. While being somewhat complete, there are still minor issues which I cannot resolve (at least I didn't find a way) without making contributions to upstream.

One of them is that metrics::CounterFn interface provides absolute() operation, while prometheus::GenericCounter's API doesn't provide a way to implement it atomically.

Solution

This PR adds GenericCounter::set() operation, allowing to cover this use case.

Checklist

  • Documentation added
  • Tests are added
  • CHANGELOG entry is added

Signed-off-by: tyranron <tyranron@gmail.com>
Signed-off-by: tyranron <tyranron@gmail.com>
@lucab
Copy link
Member

lucab commented Dec 13, 2022

Thanks for the PR, but please do note that in the larger Prometheus ecosystem by design Counters do not provide a set() method. They are meant to only increment, or to reset back to 0 in very rare cases.
You can read more about that at https://www.robustperception.io/setting-a-prometheus-counter/ and https://www.robustperception.io/how-does-a-prometheus-counter-work/.

This was already discussed in #303 with enough consensus, as such I'm closing this PR.

@lucab lucab closed this Dec 13, 2022
@tyranron tyranron deleted the counter-set-op branch December 14, 2022 19:18
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.

None yet

2 participants