diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-09 13:28:11 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-09 13:28:11 +0000 |
| commit | c34492069abacae67482af4c8356241958a524f7 (patch) | |
| tree | fd9b8ca3c26a96742bad4e9e359a20fc37c998aa /src/sync/metrics.rs | |
| parent | eb10e85f199266affd3bca0a3d4cd934f74f3e7f (diff) | |
feat(sync): add Syncing connection status to track historic sync progress
- Add ConnectionStatus::Syncing state between Connecting and Connected
- Track historic_sync_completed and historic_sync_completed_at in RelayState
- Auto-detect sync completion via check_and_complete_historic_sync()
- Update metrics: ngit_sync_relay_connected now shows 0-3 (disconnected/connecting/syncing/connected)
- Update Prometheus metric documentation with new status values
- Add state machine diagram showing Syncing transition
- Operators can now distinguish 'connected but catching up' vs 'fully synced'
Diffstat (limited to 'src/sync/metrics.rs')
| -rw-r--r-- | src/sync/metrics.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/sync/metrics.rs b/src/sync/metrics.rs index 453a79c..db7dd20 100644 --- a/src/sync/metrics.rs +++ b/src/sync/metrics.rs | |||
| @@ -53,7 +53,7 @@ impl SyncMetrics { | |||
| 53 | let relay_connected = IntGaugeVec::new( | 53 | let relay_connected = IntGaugeVec::new( |
| 54 | Opts::new( | 54 | Opts::new( |
| 55 | "ngit_sync_relay_connected", | 55 | "ngit_sync_relay_connected", |
| 56 | "Relay connection status (1=connected, 0=disconnected)", | 56 | "Relay connection status (0=disconnected, 1=connecting, 2=syncing, 3=connected)", |
| 57 | ), | 57 | ), |
| 58 | &["relay"], | 58 | &["relay"], |
| 59 | )?; | 59 | )?; |
| @@ -201,6 +201,33 @@ impl SyncMetrics { | |||
| 201 | .set(state_value); | 201 | .set(state_value); |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | /// Record relay connection status change. | ||
| 205 | /// | ||
| 206 | /// Maps connection status to numeric values for Prometheus: | ||
| 207 | /// - Disconnected = 0 (not connected) | ||
| 208 | /// - Connecting = 1 (connection attempt in progress) | ||
| 209 | /// - Syncing = 2 (connected, historic sync in progress) | ||
| 210 | /// - Connected = 3 (connected, historic sync complete) | ||
| 211 | /// | ||
| 212 | /// This is separate from health state and provides more granular connection lifecycle tracking. | ||
| 213 | /// | ||
| 214 | /// # Arguments | ||
| 215 | /// | ||
| 216 | /// * `relay` - The relay URL | ||
| 217 | /// * `status` - The current connection status | ||
| 218 | pub fn record_connection_status(&self, relay: &str, status: super::ConnectionStatus) { | ||
| 219 | use super::ConnectionStatus; | ||
| 220 | let status_value = match status { | ||
| 221 | ConnectionStatus::Disconnected => 0, | ||
| 222 | ConnectionStatus::Connecting => 1, | ||
| 223 | ConnectionStatus::Syncing => 2, | ||
| 224 | ConnectionStatus::Connected => 3, | ||
| 225 | }; | ||
| 226 | self.relay_connected | ||
| 227 | .with_label_values(&[relay]) | ||
| 228 | .set(status_value); | ||
| 229 | } | ||
| 230 | |||
| 204 | /// Record relay failure count. | 231 | /// Record relay failure count. |
| 205 | /// | 232 | /// |
| 206 | /// # Arguments | 233 | /// # Arguments |