Skip to main content

relay_knowledge/domain/operations/
diagnostics.rs

1//! Technology-neutral health and graph inspection projections.
2
3use serde::{Deserialize, Serialize};
4
5use crate::domain::{
6    CodeParseStatusCounts, CodeRepositoryTotals, FileIndexDiagnostics, GraphVersion, IndexCursor,
7    IndexRefreshDiagnostics, IndexStatus,
8};
9
10/// Aggregated graph status for diagnostics.
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
12pub struct GraphInspection {
13    pub graph_version: GraphVersion,
14    pub entity_count: usize,
15    pub evidence_count: usize,
16    pub relation_count: usize,
17    pub claim_count: usize,
18    pub event_count: usize,
19    pub mutation_count: usize,
20    pub code_file_count: usize,
21    pub code_symbol_count: usize,
22    pub code_reference_count: usize,
23    pub code_chunk_count: usize,
24    pub code_parse_status_counts: CodeParseStatusCounts,
25    #[serde(default)]
26    pub sqlite: SqliteStorageDiagnostics,
27}
28
29impl Default for GraphInspection {
30    fn default() -> Self {
31        Self {
32            graph_version: GraphVersion::ZERO,
33            entity_count: 0,
34            evidence_count: 0,
35            relation_count: 0,
36            claim_count: 0,
37            event_count: 0,
38            mutation_count: 0,
39            code_file_count: 0,
40            code_symbol_count: 0,
41            code_reference_count: 0,
42            code_chunk_count: 0,
43            code_parse_status_counts: CodeParseStatusCounts::default(),
44            sqlite: SqliteStorageDiagnostics::default(),
45        }
46    }
47}
48
49/// SQLite-specific health data included in shared graph diagnostics.
50#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
51pub struct SqliteStorageDiagnostics {
52    pub journal_mode: String,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub wal_size_bytes: Option<u64>,
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub last_maintenance_at_ms: Option<u64>,
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub last_maintenance_error: Option<String>,
59}
60
61/// Read-only storage view used by service health without mutating indexes.
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63pub struct HealthStorageSnapshot {
64    pub graph: GraphInspection,
65    pub repository_code_totals: CodeRepositoryTotals,
66    pub indexes: Vec<IndexStatus>,
67    pub index_cursors: Vec<IndexCursor>,
68    pub index_refresh: IndexRefreshDiagnostics,
69    pub file_index: FileIndexDiagnostics,
70}
71
72/// Storage health surfaced to diagnostics.
73#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
74pub struct StorageHealth {
75    pub graph_version: GraphVersion,
76    pub healthy: bool,
77    pub detail: String,
78}