diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 18:43:49 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 18:43:49 +0000 |
| commit | dd403b17e7c74db9443d0891a9de1f0f0f9f89eb (patch) | |
| tree | 177dd9f664dde3565492c1d11016dabfeda28bbc /src/metrics | |
| parent | 950c2e4e68448d2abcad90a31bfffaca6d7bc47e (diff) | |
feat(sync): Phase 6 - observability and production readiness
- Add SyncMetrics with full Prometheus integration
- Track sync gaps via catchup events
- Update Grafana dashboard with sync panels
- Document all sync configuration options
- Update design doc with implementation notes
Diffstat (limited to 'src/metrics')
| -rw-r--r-- | src/metrics/mod.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/metrics/mod.rs b/src/metrics/mod.rs index 4a4fe57..736414f 100644 --- a/src/metrics/mod.rs +++ b/src/metrics/mod.rs | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | //! - Git operation metrics (clone, fetch, push) | 5 | //! - Git operation metrics (clone, fetch, push) |
| 6 | //! - Repository bandwidth tracking (top-N only for cardinality control) | 6 | //! - Repository bandwidth tracking (top-N only for cardinality control) |
| 7 | //! - Nostr event metrics | 7 | //! - Nostr event metrics |
| 8 | //! - Sync metrics (GRASP-02 proactive sync) | ||
| 8 | //! | 9 | //! |
| 9 | //! # Privacy | 10 | //! # Privacy |
| 10 | //! IP addresses are NEVER exposed in metrics. The `ConnectionTracker` maintains | 11 | //! IP addresses are NEVER exposed in metrics. The `ConnectionTracker` maintains |
| @@ -14,6 +15,8 @@ | |||
| 14 | pub mod bandwidth; | 15 | pub mod bandwidth; |
| 15 | pub mod connection; | 16 | pub mod connection; |
| 16 | 17 | ||
| 18 | pub use crate::sync::SyncMetrics; | ||
| 19 | |||
| 17 | use std::sync::Arc; | 20 | use std::sync::Arc; |
| 18 | use std::time::Instant; | 21 | use std::time::Instant; |
| 19 | 22 | ||
| @@ -46,6 +49,9 @@ struct MetricsInner { | |||
| 46 | /// Repository bandwidth tracking (top-N only) | 49 | /// Repository bandwidth tracking (top-N only) |
| 47 | pub bandwidth_tracker: BandwidthTracker, | 50 | pub bandwidth_tracker: BandwidthTracker, |
| 48 | 51 | ||
| 52 | /// Sync metrics (GRASP-02 proactive sync) | ||
| 53 | pub sync_metrics: Option<crate::sync::SyncMetrics>, | ||
| 54 | |||
| 49 | // === WebSocket Metrics === | 55 | // === WebSocket Metrics === |
| 50 | /// Total WebSocket connections since startup | 56 | /// Total WebSocket connections since startup |
| 51 | pub websocket_connections_total: Counter, | 57 | pub websocket_connections_total: Counter, |
| @@ -97,6 +103,11 @@ impl Metrics { | |||
| 97 | } | 103 | } |
| 98 | } | 104 | } |
| 99 | 105 | ||
| 106 | /// Returns the sync metrics if registered. | ||
| 107 | pub fn sync_metrics(&self) -> Option<&crate::sync::SyncMetrics> { | ||
| 108 | self.inner.sync_metrics.as_ref() | ||
| 109 | } | ||
| 110 | |||
| 100 | /// Returns the connection tracker for WebSocket connection management. | 111 | /// Returns the connection tracker for WebSocket connection management. |
| 101 | pub fn connection_tracker(&self) -> &ConnectionTracker { | 112 | pub fn connection_tracker(&self) -> &ConnectionTracker { |
| 102 | &self.inner.connection_tracker | 113 | &self.inner.connection_tracker |
| @@ -248,6 +259,12 @@ impl MetricsInner { | |||
| 248 | // Create bandwidth tracker | 259 | // Create bandwidth tracker |
| 249 | let bandwidth_tracker = BandwidthTracker::new(®ISTRY); | 260 | let bandwidth_tracker = BandwidthTracker::new(®ISTRY); |
| 250 | 261 | ||
| 262 | // Create sync metrics (may fail if already registered in tests) | ||
| 263 | let sync_metrics = crate::sync::SyncMetrics::register(®ISTRY).ok(); | ||
| 264 | if sync_metrics.is_some() { | ||
| 265 | tracing::info!("Sync metrics registered with Prometheus"); | ||
| 266 | } | ||
| 267 | |||
| 251 | // WebSocket metrics | 268 | // WebSocket metrics |
| 252 | let websocket_connections_total = Counter::with_opts( | 269 | let websocket_connections_total = Counter::with_opts( |
| 253 | Opts::new( | 270 | Opts::new( |
| @@ -377,6 +394,7 @@ impl MetricsInner { | |||
| 377 | Self { | 394 | Self { |
| 378 | connection_tracker, | 395 | connection_tracker, |
| 379 | bandwidth_tracker, | 396 | bandwidth_tracker, |
| 397 | sync_metrics, | ||
| 380 | websocket_connections_total, | 398 | websocket_connections_total, |
| 381 | websocket_connection_duration, | 399 | websocket_connection_duration, |
| 382 | websocket_messages_received, | 400 | websocket_messages_received, |