metrics_tracing_context/
label_filter.rsuse std::collections::HashSet;
use metrics::{KeyName, Label};
pub trait LabelFilter {
fn should_include_label(&self, name: &KeyName, label: &Label) -> bool;
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct IncludeAll;
impl LabelFilter for IncludeAll {
fn should_include_label(&self, _name: &KeyName, _label: &Label) -> bool {
true
}
}
#[derive(Debug, Clone)]
pub struct Allowlist {
label_names: HashSet<String>,
}
impl Allowlist {
pub fn new<I, S>(allowed: I) -> Allowlist
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
Self { label_names: allowed.into_iter().map(|s| s.as_ref().to_string()).collect() }
}
}
impl LabelFilter for Allowlist {
fn should_include_label(&self, _name: &KeyName, label: &Label) -> bool {
self.label_names.contains(label.key())
}
}