metrics-rs / metrics

A metrics ecosystem for Rust.
MIT License
1.11k stars 156 forks source link

Extend the public Registry interface #459

Closed kathoum closed 6 months ago

kathoum commented 7 months ago

Currently the Registry object exposes a limited API: get_or_create, get_handles, visit, delete, clear.

Would you consider adding the following public functions?

and the corresponding functions for gauges and histograms, that work like HashMap::get and HashMap::retain, respectively.

Proposed PR for the get functions: https://github.com/metrics-rs/metrics/pull/457

tobz commented 7 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?

kathoum commented 7 months ago

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.

tobz commented 7 months ago

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.

kathoum commented 6 months ago

https://github.com/metrics-rs/metrics/pull/461

tobz commented 6 months ago

Closing as this has been addressed in #457 and #461.