1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use 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())
    }
}