foyer_common/metrics/registry/
noop.rsuse crate::metrics::{CounterOps, CounterVecOps, GaugeOps, GaugeVecOps, HistogramOps, HistogramVecOps, RegistryOps};
#[derive(Debug)]
pub struct NoopMetricsRegistry;
impl CounterOps for NoopMetricsRegistry {
fn increase(&self, _: u64) {}
}
impl CounterVecOps for NoopMetricsRegistry {
fn counter(&self, _: &[&'static str]) -> impl CounterOps {
NoopMetricsRegistry
}
}
impl GaugeOps for NoopMetricsRegistry {
fn increase(&self, _: u64) {}
fn decrease(&self, _: u64) {}
fn absolute(&self, _: u64) {}
}
impl GaugeVecOps for NoopMetricsRegistry {
fn gauge(&self, _: &[&'static str]) -> impl GaugeOps {
NoopMetricsRegistry
}
}
impl HistogramOps for NoopMetricsRegistry {
fn record(&self, _: f64) {}
}
impl HistogramVecOps for NoopMetricsRegistry {
fn histogram(&self, _: &[&'static str]) -> impl HistogramOps {
NoopMetricsRegistry
}
}
impl RegistryOps for NoopMetricsRegistry {
fn register_counter_vec(&self, _: &'static str, _: &'static str, _: &'static [&'static str]) -> impl CounterVecOps {
NoopMetricsRegistry
}
fn register_gauge_vec(&self, _: &'static str, _: &'static str, _: &'static [&'static str]) -> impl GaugeVecOps {
NoopMetricsRegistry
}
fn register_histogram_vec(
&self,
_: &'static str,
_: &'static str,
_: &'static [&'static str],
) -> impl HistogramVecOps {
NoopMetricsRegistry
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test() {
let noop = NoopMetricsRegistry;
let cv = noop.register_counter_vec("test_counter_1", "test counter 1", &["label1", "label2"]);
let c = cv.counter(&["l1", "l2"]);
c.increase(42);
let gv = noop.register_gauge_vec("test_gauge_1", "test gauge 1", &["label1", "label2"]);
let g = gv.gauge(&["l1", "l2"]);
g.increase(514);
g.decrease(114);
g.absolute(114514);
let hv = noop.register_histogram_vec("test_histogram_1", "test histogram 1", &["label1", "label2"]);
let h = hv.histogram(&["l1", "l2"]);
h.record(114.514);
}
}