Skip to main content

max / makenotwork

2.4 KB · 89 lines History Blame Raw
1 //! route alert/recovery messages. Domain half of the Alerter split;
2 //! shared dispatch/cooldown plumbing lives in the parent module.
3
4 use tracing::instrument;
5
6 use super::{AlertCategory, AlertMeta, Alerter};
7
8 impl Alerter {
9 #[instrument(skip_all)]
10 pub async fn send_route_failure_alert(
11 &self,
12 target: &str,
13 label: &str,
14 failed_paths: &[String],
15 ) {
16 let alert_key = format!("route:{target}");
17 let n = failed_paths.len();
18 let subject = format!("[PoM] {label}: {n} route(s) failing");
19 let body = format!(
20 "Target: {label} ({target})\n\
21 Failed routes:\n{}\n\
22 Instance: {}\n\
23 Time: {}\n\n\
24 - PoM",
25 failed_paths
26 .iter()
27 .map(|p| format!(" - {p}"))
28 .collect::<Vec<_>>()
29 .join("\n"),
30 self.instance_name,
31 chrono::Utc::now().to_rfc3339(),
32 );
33
34 self.fire_failure(
35 &subject,
36 &body,
37 "high",
38 "pom-routes",
39 Some(target),
40 AlertMeta {
41 key: &alert_key,
42 category: AlertCategory::RouteFailure,
43 from: None,
44 to: None,
45 error: None,
46 },
47 )
48 .await;
49 }
50
51 #[instrument(skip_all)]
52 pub async fn send_route_recovery_alert(
53 &self,
54 target: &str,
55 label: &str,
56 recovered_paths: &[String],
57 ) {
58 let alert_key = format!("route:{target}");
59 let subject = format!("[PoM] {label}: routes recovered");
60 let body = format!(
61 "Target: {label} ({target})\n\
62 Recovered routes:\n{}\n\
63 Instance: {}\n\
64 Time: {}\n\n\
65 - PoM",
66 recovered_paths
67 .iter()
68 .map(|p| format!(" - {p}"))
69 .collect::<Vec<_>>()
70 .join("\n"),
71 self.instance_name,
72 chrono::Utc::now().to_rfc3339(),
73 );
74
75 self.fire_recovery(
76 &subject,
77 &body,
78 AlertMeta {
79 key: &alert_key,
80 category: AlertCategory::RouteRecovery,
81 from: None,
82 to: None,
83 error: None,
84 },
85 )
86 .await;
87 }
88 }
89