use metrics::{counter, describe_counter, describe_histogram, histogram};
use std::sync::Once;
static DESCRIBE: Once = Once::new();
fn describe() {
DESCRIBE.call_once(|| {
describe_counter!(
"faucet_notifications_sent_total",
"Notification deliveries attempted, by channel/event/outcome"
);
describe_counter!(
"faucet_notifications_dropped_total",
"Notifications dropped before/at delivery, by channel/reason"
);
describe_histogram!(
"faucet_notification_dispatch_duration_seconds",
"Per-delivery notification dispatch latency in seconds"
);
});
}
pub fn record_sent(channel: &'static str, event: &'static str, ok: bool) {
describe();
counter!(
"faucet_notifications_sent_total",
"channel" => channel,
"event" => event,
"outcome" => if ok { "ok" } else { "error" },
)
.increment(1);
}
pub fn record_dropped(channel: &'static str, reason: &'static str) {
describe();
counter!(
"faucet_notifications_dropped_total",
"channel" => channel,
"reason" => reason,
)
.increment(1);
}
pub fn record_duration(channel: &'static str, secs: f64) {
describe();
histogram!("faucet_notification_dispatch_duration_seconds", "channel" => channel).record(secs);
}
#[cfg(test)]
mod tests {
#[test]
fn emitting_without_recorder_is_a_noop() {
super::record_sent("slack", "run_failure", true);
super::record_dropped("slack", "coalesced");
super::record_duration("slack", 0.01);
}
}