-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add retain functions to Registry #461
Conversation
Design-wise, I'm not sure about the choice on the function signature: I went with But I understand if we prefer not allowing |
Following the standard library, it might be best just to make it an immutable reference. Thinking more about it as well, mutable access really shouldn't even be a big deal since all metric types inevitably have to support concurrent immutable access for normal usage via |
PR updated, changed the visitors to accept immutable references |
metrics-util/src/registry/mod.rs
Outdated
registry.get_or_create_counter(&Key::from_name("baz"), |_| ()); | ||
|
||
let mut n = 0; | ||
registry.retain_counters(|k, _| { | ||
n += 1; | ||
k.name().starts_with("foo") | ||
}); | ||
assert_eq!(n, 2); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'd want to copy the assert from lines 512-513 and stick them after adding the baz
counter, to show that we now have two counters in the registry. After that, do the same thing after the retain_counters
call to show it goes back down to one counter after it deletes baz
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. 👍🏻
Released in Thanks again for your contribution! |
This adds public functions retain_counters, retain_gauges, retain_histograms, that work like HashMap::retain