rustfs_notify/
status_view.rs1use crate::integration::{NotificationMetricSnapshot, NotificationMetrics};
16use hashbrown::HashMap;
17use std::sync::Arc;
18
19#[derive(Clone)]
20pub struct NotifyStatusView {
21 metrics: Arc<NotificationMetrics>,
22}
23
24impl NotifyStatusView {
25 pub fn new(metrics: Arc<NotificationMetrics>) -> Self {
26 Self { metrics }
27 }
28
29 pub fn get_status(&self) -> HashMap<String, String> {
30 let mut status = HashMap::new();
31
32 status.insert("uptime_seconds".to_string(), self.metrics.uptime().as_secs().to_string());
33 status.insert("processing_events".to_string(), self.metrics.processing_count().to_string());
34 status.insert("processed_events".to_string(), self.metrics.processed_count().to_string());
35 status.insert("failed_events".to_string(), self.metrics.failed_count().to_string());
36 status.insert("skipped_events".to_string(), self.metrics.skipped_count().to_string());
37
38 status
39 }
40
41 pub fn snapshot_metrics(&self) -> NotificationMetricSnapshot {
42 self.metrics.snapshot()
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::NotifyStatusView;
49 use crate::integration::NotificationMetrics;
50 use std::sync::Arc;
51
52 #[test]
53 fn status_view_reports_empty_metrics_snapshot() {
54 let status_view = NotifyStatusView::new(Arc::new(NotificationMetrics::new()));
55
56 let snapshot = status_view.snapshot_metrics();
57 assert_eq!(snapshot.current_send_in_progress, 0);
58 assert_eq!(snapshot.events_errors_total, 0);
59 assert_eq!(snapshot.events_sent_total, 0);
60 assert_eq!(snapshot.events_skipped_total, 0);
61 }
62
63 #[test]
64 fn status_view_exposes_status_map_keys() {
65 let status_view = NotifyStatusView::new(Arc::new(NotificationMetrics::new()));
66 let status = status_view.get_status();
67
68 assert!(status.contains_key("uptime_seconds"));
69 assert!(status.contains_key("processing_events"));
70 assert!(status.contains_key("processed_events"));
71 assert!(status.contains_key("failed_events"));
72 assert!(status.contains_key("skipped_events"));
73 }
74}