diff options
| -rw-r--r-- | src/sync/mod.rs | 12 | ||||
| -rw-r--r-- | tests/sync/metrics.rs | 7 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/sync/mod.rs b/src/sync/mod.rs index b6cd00a..c78c0e1 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs | |||
| @@ -1208,13 +1208,23 @@ impl SyncManager { | |||
| 1208 | } | 1208 | } |
| 1209 | 1209 | ||
| 1210 | // Mark as connected in relay sync index | 1210 | // Mark as connected in relay sync index |
| 1211 | { | 1211 | // Track whether this is a new relay for metrics |
| 1212 | let is_new_relay = { | ||
| 1212 | let mut index = relay_sync_index.write().await; | 1213 | let mut index = relay_sync_index.write().await; |
| 1214 | let is_new = !index.contains_key(&relay_url); | ||
| 1213 | let state = index.entry(relay_url.clone()).or_default(); | 1215 | let state = index.entry(relay_url.clone()).or_default(); |
| 1214 | state.connection_status = ConnectionStatus::Connected; | 1216 | state.connection_status = ConnectionStatus::Connected; |
| 1215 | state.is_bootstrap = is_bootstrap; | 1217 | state.is_bootstrap = is_bootstrap; |
| 1216 | state.last_connected = Some(Timestamp::now()); | 1218 | state.last_connected = Some(Timestamp::now()); |
| 1217 | state.disconnected_at = None; | 1219 | state.disconnected_at = None; |
| 1220 | is_new | ||
| 1221 | }; | ||
| 1222 | |||
| 1223 | // Increment tracked count for new relays | ||
| 1224 | if is_new_relay { | ||
| 1225 | if let Some(ref metrics) = self.metrics { | ||
| 1226 | metrics.inc_tracked_count(); | ||
| 1227 | } | ||
| 1218 | } | 1228 | } |
| 1219 | 1229 | ||
| 1220 | // Store connection in HashMap BEFORE sending notification | 1230 | // Store connection in HashMap BEFORE sending notification |
diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs index 98ce4f3..26d379d 100644 --- a/tests/sync/metrics.rs +++ b/tests/sync/metrics.rs | |||
| @@ -374,8 +374,6 @@ async fn test_startup_sync_event_count() { | |||
| 374 | /// This test validates that when sync cannot connect to a source relay, | 374 | /// This test validates that when sync cannot connect to a source relay, |
| 375 | /// the connection_attempts_total counter with result="failure" increases. | 375 | /// the connection_attempts_total counter with result="failure" increases. |
| 376 | /// | 376 | /// |
| 377 | /// NOTE: This test may fail until sync metrics recording is fully wired up. | ||
| 378 | /// The test documents the expected behavior. | ||
| 379 | #[tokio::test] | 377 | #[tokio::test] |
| 380 | async fn test_connection_failure_increments_counter() { | 378 | async fn test_connection_failure_increments_counter() { |
| 381 | let mut harness = MetricsTestHarness::with_sources(0).await; // No sources | 379 | let mut harness = MetricsTestHarness::with_sources(0).await; // No sources |
| @@ -489,8 +487,6 @@ async fn test_relay_connected_status() { | |||
| 489 | /// This test validates that `ngit_sync_relay_status` gauge transitions from | 487 | /// This test validates that `ngit_sync_relay_status` gauge transitions from |
| 490 | /// healthy (1) to degraded (2) or dead (3) when a relay cannot be connected to. | 488 | /// healthy (1) to degraded (2) or dead (3) when a relay cannot be connected to. |
| 491 | /// | 489 | /// |
| 492 | /// NOTE: This test may fail until sync metrics recording is fully wired up. | ||
| 493 | /// The test documents the expected behavior. | ||
| 494 | #[tokio::test] | 490 | #[tokio::test] |
| 495 | async fn test_health_state_degrades_on_failure() { | 491 | async fn test_health_state_degrades_on_failure() { |
| 496 | use crate::common::sync_helpers::MetricsTestHarness; | 492 | use crate::common::sync_helpers::MetricsTestHarness; |
| @@ -533,10 +529,7 @@ async fn test_health_state_degrades_on_failure() { | |||
| 533 | /// Note: Current implementation may only support one sync source, so this tests | 529 | /// Note: Current implementation may only support one sync source, so this tests |
| 534 | /// with one source, verifying tracked=1 and connected=1, then connected=0 after stopping. | 530 | /// with one source, verifying tracked=1 and connected=1, then connected=0 after stopping. |
| 535 | /// | 531 | /// |
| 536 | /// NOTE: This test may fail until sync metrics recording is fully wired up. | ||
| 537 | /// The test documents the expected behavior. | ||
| 538 | #[tokio::test] | 532 | #[tokio::test] |
| 539 | #[ignore] // Enable when relay tracking metrics are wired up | ||
| 540 | async fn test_multi_source_aggregate_counts() { | 533 | async fn test_multi_source_aggregate_counts() { |
| 541 | use crate::common::sync_helpers::MetricsTestHarness; | 534 | use crate::common::sync_helpers::MetricsTestHarness; |
| 542 | 535 | ||