Skip to main content

relay_knowledge/api/contracts/
watcher_diagnostics.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
4pub struct WatcherDiagnostics {
5    #[serde(default)]
6    pub state: String,
7    #[serde(default)]
8    pub enabled: bool,
9    #[serde(default)]
10    pub commit_reconcile_interval_ms: u64,
11    pub watched_repository_count: usize,
12    pub total_events_received: u64,
13    pub total_events_filtered: u64,
14    pub total_index_tasks_queued: u64,
15    #[serde(default)]
16    pub total_commit_reconciliations: u64,
17    #[serde(default)]
18    pub total_commit_tasks_queued: u64,
19    #[serde(default)]
20    pub total_commit_reconcile_failures: u64,
21    pub total_events_dropped: u64,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub last_error: Option<String>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub degraded_reason: Option<String>,
26}
27
28impl WatcherDiagnostics {
29    pub fn default_disabled() -> Self {
30        Self {
31            state: "disabled".to_owned(),
32            enabled: false,
33            commit_reconcile_interval_ms: 0,
34            watched_repository_count: 0,
35            total_events_received: 0,
36            total_events_filtered: 0,
37            total_index_tasks_queued: 0,
38            total_commit_reconciliations: 0,
39            total_commit_tasks_queued: 0,
40            total_commit_reconcile_failures: 0,
41            total_events_dropped: 0,
42            last_error: None,
43            degraded_reason: None,
44        }
45    }
46
47    pub fn from_watcher_state(inner: &crate::watcher::WatcherDiagnostics) -> Self {
48        Self {
49            state: inner.state.as_str().to_owned(),
50            enabled: inner.state != crate::watcher::WatcherState::Disabled,
51            commit_reconcile_interval_ms: 0,
52            watched_repository_count: inner.watched_repository_count,
53            total_events_received: inner.total_events_received,
54            total_events_filtered: inner.total_events_filtered,
55            total_index_tasks_queued: inner.total_index_tasks_queued,
56            total_commit_reconciliations: inner.total_commit_reconciliations,
57            total_commit_tasks_queued: inner.total_commit_tasks_queued,
58            total_commit_reconcile_failures: inner.total_commit_reconcile_failures,
59            total_events_dropped: inner.total_events_dropped,
60            last_error: inner.last_error.clone(),
61            degraded_reason: inner.degraded_reason.clone(),
62        }
63    }
64}