diff --git a/src/metrics/family.rs b/src/metrics/family.rs index 2f23b198..330e23e9 100644 --- a/src/metrics/family.rs +++ b/src/metrics/family.rs @@ -288,6 +288,26 @@ impl> Family, Counter>::default(); + /// let get = vec![("method".to_owned(), "GET".to_owned())]; + /// let post = vec![("method".to_owned(), "POST".to_owned())]; + /// + /// // Create the metric with labels `method="GET"`. + /// family.get_or_create(&get).inc(); + /// + /// assert!(family.contains(&get), "a `method=\"GET\"`-labeled metric exists"); + /// assert!(!family.contains(&post), "a `method=\"POST\"`-labeled metric does NOT exist"); + /// ``` + pub fn contains(&self, label_set: &S) -> bool { + self.metrics.read().get(label_set).is_some() + } + pub(crate) fn read(&self) -> RwLockReadGuard> { self.metrics.read() }