Closed kathoum closed 6 months ago
Hello! 👋🏻
I would definitely approve a PR for both of those, since they're simple enough.
Out of curiosity: what's your use case for the "retain" calls?
The use case of 'retain' is similar to the usage of Recency in PrometheusRecorder, to delete metrics based on some internal property, and it can be achieved in the same way (clone all the handles and iterate).
The reason is that I was surprised when my first attempt to do it with registry.visit_counters(|key, counter| { if (...) { registry.delete_counter(key) } })
didn't work, and I think having an obvious way to do that can be useful.
Yeah, that's reasonable. 👍🏻
I merged your other PR too fast (😂) but feel free to submit a other for the retain functionality and we can get it merged pretty quickly.
Closing as this has been addressed in #457 and #461.
Currently the Registry object exposes a limited API: get_or_create, get_handles, visit, delete, clear.
Would you consider adding the following public functions?
get_counter(&self, key: &K) -> Option<S::Counter>
retain_counters(&mut self, f: impl FnMut(&K, &S::Counter) -> bool)
and the corresponding functions for gauges and histograms, that work like
HashMap::get
andHashMap::retain
, respectively.Proposed PR for the
get
functions: https://github.com/metrics-rs/metrics/pull/457