use crate::monitor::event_lane::EventClass;
use super::window_records::rank_record_path;
use super::ClusterCoordinator;
impl ClusterCoordinator {
fn record_hosts(&self) -> Vec<&str> {
(0..self.world_size)
.map(|r| self.rank_hosts.get(r).map(|s| s.as_str()).unwrap_or(""))
.collect()
}
pub(super) fn alert_path_for_rank(&self, rank: usize) -> String {
rank_record_path(rank, &self.record_hosts())
}
pub(super) fn emit_alert(
&mut self,
class: EventClass,
path: String,
detail: String,
) {
let now = now_ms();
let records = self.event_lane.record(class, &path, detail, now);
self.push_alert_records(records);
}
pub(super) fn flush_alerts(&mut self) {
let records = self.event_lane.flush(now_ms());
self.push_alert_records(records);
}
fn push_alert_records(&mut self, records: Vec<serde_json::Value>) {
if records.is_empty() {
return;
}
for r in &records {
crate::msg!(
" ddp: [{}] {} {} — {} (x{})",
r["sev"].as_str().unwrap_or("?"),
r["class"].as_str().unwrap_or("?"),
r["path"].as_str().unwrap_or("?"),
r["detail"].as_str().unwrap_or(""),
r["count"],
);
}
if let Some(sink) = self.dashboard_sink.as_ref() {
sink.push_events(records);
}
}
}
pub(super) fn now_ms() -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_millis() as u64)
.unwrap_or(0)
}