From a7affe5939e4d2e219988600291482a5f50e68a0 Mon Sep 17 00:00:00 2001 From: jaydenelliott Date: Tue, 14 Mar 2023 11:56:02 +1100 Subject: [PATCH] Add .get() to Family hashmap wrapper Signed-off-by: jaydenelliott --- src/metrics/family.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/metrics/family.rs b/src/metrics/family.rs index 3b70eeb9..066ecacf 100644 --- a/src/metrics/family.rs +++ b/src/metrics/family.rs @@ -248,6 +248,23 @@ impl> Family, Counter>::default(); + /// + /// if let Some(metric) = family.get(&vec![("method".to_owned(), "GET".to_owned())]) { + /// metric.inc(); + /// }; + /// ``` + pub fn get(&self, label_set: &S) -> Option> { + RwLockReadGuard::try_map(self.metrics.read(), |metrics| metrics.get(label_set)).ok() + } + /// Remove a label set from the metric family. /// /// Returns a bool indicating if a label set was removed or not.