diff --git a/crates/scanner-metrics/src/metrics.rs b/crates/scanner-metrics/src/metrics.rs index 9a107a96a6..3346a896de 100644 --- a/crates/scanner-metrics/src/metrics.rs +++ b/crates/scanner-metrics/src/metrics.rs @@ -2871,6 +2871,19 @@ impl Metrics { } } + /// Record the site runtime's durable admission decision. Replaying an existing operation does not queue a new run. + pub fn record_site_resync_admission(&self, result: &Result) { + let work = ScannerSourceWorkUpdate { + checked: 1, + queued: u64::from(matches!(result, Ok(true))), + skipped: u64::from(matches!(result, Ok(false))), + missed: u64::from(result.is_err()), + ..Default::default() + }; + self.record_scanner_source_work(ScannerWorkSource::SiteReplication, work); + self.record_scanner_replication_repair_work(ScannerReplicationRepairKind::SiteActiveResync, work); + } + fn record_last_cycle_scanner_source_work(&self, source: ScannerWorkSource, work: ScannerSourceWorkUpdate) { if let Some(counters) = self.last_scan_cycle_source_work.get(source.index()) { counters.add(work); @@ -4356,6 +4369,36 @@ mod tests { assert_eq!(value["cycles_completed_at"][0].as_str(), Some("2023-11-14T22:14:20.987654Z")); } + #[tokio::test] + async fn site_resync_admission_distinguishes_new_work_replays_and_rejections() { + let metrics = Metrics::new(); + for admission in [Ok(true), Ok(false), Err(())] { + metrics.record_site_resync_admission(&admission); + } + let report = metrics.report().await; + let site = report + .source_work + .iter() + .find(|work| work.source == "site_replication") + .unwrap(); + let active = report + .replication_repair + .iter() + .find(|work| work.kind == "active_resync") + .unwrap(); + assert_eq!((site.checked, site.queued, site.skipped, site.missed, site.executed), (3, 1, 1, 1, 0)); + assert_eq!( + (active.checked, active.queued, active.skipped, active.missed, active.executed), + (3, 1, 1, 1, 0) + ); + let bucket = report + .source_work + .iter() + .find(|work| work.source == "bucket_replication") + .unwrap(); + assert_eq!((bucket.checked, bucket.queued), (0, 0)); + } + #[tokio::test] async fn close_disk_guard_runs_cleanup_when_an_early_return_drops_it() { let (closed_tx, closed_rx) = tokio::sync::oneshot::channel(); diff --git a/crates/scanner/src/scanner_folder.rs b/crates/scanner/src/scanner_folder.rs index f2ca528a22..a2d10bd7fe 100644 --- a/crates/scanner/src/scanner_folder.rs +++ b/crates/scanner/src/scanner_folder.rs @@ -391,7 +391,7 @@ fn record_scanner_heal_admission(metrics: &Metrics, scan_mode: HealScanMode, adm ), Ok(HealAdmissionResult::Full | HealAdmissionResult::Dropped(_)) | Err(_) => (ScannerSourceWorkUpdate::missed(1), false), }; - metrics.record_scanner_source_work(scanner_heal_source(scan_mode), work); + metrics.record_scanner_source_work(scanner_heal_source(scan_mode), ScannerSourceWorkUpdate { checked: 1, ..work }); admitted } diff --git a/crates/scanner/src/scanner_folder/tests.rs b/crates/scanner/src/scanner_folder/tests.rs index bdc2654a14..e596f3ebb8 100644 --- a/crates/scanner/src/scanner_folder/tests.rs +++ b/crates/scanner/src/scanner_folder/tests.rs @@ -1071,6 +1071,7 @@ async fn test_scanner_heal_admission_accounting_maps_normal_scan_to_heal() { .find(|work| work.source == ScannerWorkSource::Bitrot.as_str()) .expect("bitrot source work should be visible"); + assert_eq!((heal.checked, bitrot.checked), (5, 0)); assert_eq!(heal.queued, 1); assert_eq!(heal.skipped, 1); assert_eq!(heal.missed, 3); @@ -1098,6 +1099,7 @@ async fn test_scanner_heal_admission_accounting_maps_deep_scan_to_bitrot() { .find(|work| work.source == ScannerWorkSource::Bitrot.as_str()) .expect("bitrot source work should be visible"); + assert_eq!((bitrot.checked, heal.checked), (3, 0)); assert_eq!(bitrot.queued, 1); assert_eq!(bitrot.skipped, 1); assert_eq!(bitrot.missed, 1); diff --git a/rustfs/src/admin/handlers/site_replication.rs b/rustfs/src/admin/handlers/site_replication.rs index f84f236c1d..76270a3fd8 100644 --- a/rustfs/src/admin/handlers/site_replication.rs +++ b/rustfs/src/admin/handlers/site_replication.rs @@ -5881,7 +5881,11 @@ async fn start_site_bucket_resync(bucket: &str, target_arn: &str, resync_id: &st let _committed_targets = match replication::commit_resync_target( targets, opts, - move |opts| async move { admission_pool.admit_bucket_resync(opts).await }, + move |opts| async move { + let admission = admission_pool.admit_bucket_resync(opts).await; + rustfs_scanner_metrics::metrics::global_metrics().record_site_resync_admission(&admission); + admission + }, move |encoded| async move { metadata_sys::update_bucket_targets_under_transaction_lock(&transaction_guard, bucket, encoded) .await