use once_cell::sync::Lazy;
use prometheus::{HistogramVec, IntCounterVec};
use crate::metrics::{Direction, registry};
pub(crate) fn counter(
id: &str,
label: &str,
help: &str,
direction: Direction,
) -> prometheus::IntCounter {
static COUNTERS: Lazy<IntCounterVec> = Lazy::new(|| {
prometheus::register_int_counter_vec_with_registry! {
prometheus::opts! {
"quilkin_filter_int_counter",
"generic filter counter, see help label for more specific info",
},
&["id", "label", "help", Direction::LABEL],
registry(),
}
.unwrap()
});
COUNTERS.with_label_values(&[id, label, help, direction.label()])
}
pub(crate) fn histogram(
id: &str,
label: &str,
help: &str,
direction: Direction,
metadata: &[&str],
) -> prometheus::Histogram {
debug_assert!(
metadata.len() <= 1,
"shared metadata exceeds current label cardinality"
);
static HISTOGRAMS: Lazy<HistogramVec> = Lazy::new(|| {
prometheus::register_histogram_vec_with_registry! {
prometheus::histogram_opts! {
"filter_histogram",
"generic filter histogram, see help label for more specific info",
},
&["id", "label", "help", Direction::LABEL, "shared_metadata_1"],
registry(),
}
.unwrap()
});
HISTOGRAMS.with_label_values(&[
id,
label,
help,
direction.label(),
metadata.first().copied().unwrap_or_default(),
])
}