Skip to content

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

@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.

2 participants