metrics_tracing_context/
label_filter.rs1use std::collections::HashSet;
4
5use metrics::{KeyName, Label};
6
7pub trait LabelFilter {
10 fn should_include_label(&self, name: &KeyName, label: &Label) -> bool;
13}
14
15#[derive(Debug, Copy, Clone, Eq, PartialEq)]
17pub struct IncludeAll;
18
19impl LabelFilter for IncludeAll {
20 fn should_include_label(&self, _name: &KeyName, _label: &Label) -> bool {
21 true
22 }
23}
24
25#[derive(Debug, Clone)]
27pub struct Allowlist {
28 label_names: HashSet<String>,
30}
31
32impl Allowlist {
33 pub fn new<I, S>(allowed: I) -> Allowlist
35 where
36 I: IntoIterator<Item = S>,
37 S: AsRef<str>,
38 {
39 Self { label_names: allowed.into_iter().map(|s| s.as_ref().to_string()).collect() }
40 }
41}
42
43impl LabelFilter for Allowlist {
44 fn should_include_label(&self, _name: &KeyName, label: &Label) -> bool {
45 self.label_names.contains(label.key())
46 }
47}