relay_knowledge/api/contracts/
watcher_diagnostics.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
4pub struct WatcherDiagnostics {
5 #[serde(default)]
6 pub state: String,
7 pub watched_repository_count: usize,
8 pub total_events_received: u64,
9 pub total_events_filtered: u64,
10 pub total_index_tasks_queued: u64,
11 pub total_events_dropped: u64,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pub last_error: Option<String>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub degraded_reason: Option<String>,
16}
17
18impl WatcherDiagnostics {
19 pub fn default_disabled() -> Self {
20 Self {
21 state: "disabled".to_owned(),
22 watched_repository_count: 0,
23 total_events_received: 0,
24 total_events_filtered: 0,
25 total_index_tasks_queued: 0,
26 total_events_dropped: 0,
27 last_error: None,
28 degraded_reason: None,
29 }
30 }
31
32 pub fn from_watcher_state(inner: &crate::watcher::WatcherDiagnostics) -> Self {
33 Self {
34 state: inner.state.as_str().to_owned(),
35 watched_repository_count: inner.watched_repository_count,
36 total_events_received: inner.total_events_received,
37 total_events_filtered: inner.total_events_filtered,
38 total_index_tasks_queued: inner.total_index_tasks_queued,
39 total_events_dropped: inner.total_events_dropped,
40 last_error: inner.last_error.clone(),
41 degraded_reason: inner.degraded_reason.clone(),
42 }
43 }
44}