tikv / rust-prometheus

Prometheus instrumentation library for Rust applications
Apache License 2.0
1.07k stars 182 forks source link

Add `GenericCounter::set()` operation #471

Closed tyranron closed 1 year ago

tyranron commented 1 year ago

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

lucab commented 1 year ago

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 https://github.com/tikv/rust-prometheus/pull/303 with enough consensus, as such I'm closing this PR.