use metrics::{counter, describe_counter, describe_gauge, gauge};
use std::sync::Once;
static DESCRIBE: Once = Once::new();
fn describe() {
DESCRIBE.call_once(|| {
describe_counter!(
"faucet_pipeline_sla_violations_total",
"SLA violations detected post-run, by kind (staleness | min_rows | volume)"
);
describe_gauge!(
"faucet_pipeline_sla_baseline_runs",
"Successful runs currently in the rolling SLA volume baseline"
);
});
}
pub fn record_violation(pipeline: &str, row: &str, kind: &'static str) {
describe();
counter!(
"faucet_pipeline_sla_violations_total",
"pipeline" => pipeline.to_owned(),
"row" => row.to_owned(),
"kind" => kind,
)
.increment(1);
}
pub fn set_baseline_runs(pipeline: &str, row: &str, n: usize) {
describe();
gauge!(
"faucet_pipeline_sla_baseline_runs",
"pipeline" => pipeline.to_owned(),
"row" => row.to_owned(),
)
.set(n as f64);
}
#[cfg(test)]
mod tests {
#[test]
fn emitting_without_recorder_is_a_noop() {
super::record_violation("p", "r", "staleness");
super::set_baseline_runs("p", "r", 3);
}
}