Skip to main content

relay_knowledge/storage/contracts/
health.rs

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