tikv / rust-prometheus

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

Provide a way to create auto-unsetting metrics #456

Open joshualex opened 2 years ago

joshualex commented 2 years ago

I'm trying to create components that report metrics through holding an e.g. IntCounter generated from a registered IntCounterVec. I would like the set of labels attached to each component to be removed when the component is dropped, to avoid reporting the last value over and over again.

Currently this is very convoluted to achieve, since it requires holding a clone of the MetricVec, and the inner type of that MetricVec cannot be specified because it is behind a private submodule of the crate.

What is the best way to achieve this? e.g. to do something in impl Drop that will remove the set of labels for a counter, but will keep other labels intact?

vladimir-lu commented 6 months ago

Would exposing MetricVec::reset() on the gauges help to at least provide manual GC for metric values? Was misreading the code, seems it's already exposed. I suppose you can remove the values manually when you finish a request? Would need a reference to the underlying MetricVec but seems doable? The main issue I foresee is that you probably want a time delay due if you're not pushing metrics for the scraper to pick up the values.