faucet_cli/notify/
metrics.rs1use metrics::{counter, describe_counter, describe_histogram, histogram};
15use std::sync::Once;
16
17static DESCRIBE: Once = Once::new();
18
19fn describe() {
20 DESCRIBE.call_once(|| {
21 describe_counter!(
22 "faucet_notifications_sent_total",
23 "Notification deliveries attempted, by channel/event/outcome"
24 );
25 describe_counter!(
26 "faucet_notifications_dropped_total",
27 "Notifications dropped before/at delivery, by channel/reason"
28 );
29 describe_histogram!(
30 "faucet_notification_dispatch_duration_seconds",
31 "Per-delivery notification dispatch latency in seconds"
32 );
33 });
34}
35
36pub fn record_sent(channel: &'static str, event: &'static str, ok: bool) {
38 describe();
39 counter!(
40 "faucet_notifications_sent_total",
41 "channel" => channel,
42 "event" => event,
43 "outcome" => if ok { "ok" } else { "error" },
44 )
45 .increment(1);
46}
47
48pub fn record_dropped(channel: &'static str, reason: &'static str) {
50 describe();
51 counter!(
52 "faucet_notifications_dropped_total",
53 "channel" => channel,
54 "reason" => reason,
55 )
56 .increment(1);
57}
58
59pub fn record_duration(channel: &'static str, secs: f64) {
61 describe();
62 histogram!("faucet_notification_dispatch_duration_seconds", "channel" => channel).record(secs);
63}
64
65#[cfg(test)]
66mod tests {
67 #[test]
71 fn emitting_without_recorder_is_a_noop() {
72 super::record_sent("slack", "run_failure", true);
73 super::record_dropped("slack", "coalesced");
74 super::record_duration("slack", 0.01);
75 }
76}