From 912bde73790f0ce29d0cea1d03605a71b451da84 Mon Sep 17 00:00:00 2001 From: Emma Forman Ling Date: Tue, 26 Nov 2024 12:09:53 -0800 Subject: [PATCH] add compaction reason to timer before finishing in case it fails (#31800) GitOrigin-RevId: 749ca85213ebafbbf769de04b33f5a785d918ad0 --- .../src/index_workers/search_compactor.rs | 6 ++---- crates/database/src/metrics.rs | 16 +++++----------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/crates/database/src/index_workers/search_compactor.rs b/crates/database/src/index_workers/search_compactor.rs index 1a8f8e51..a0ae18f3 100644 --- a/crates/database/src/index_workers/search_compactor.rs +++ b/crates/database/src/index_workers/search_compactor.rs @@ -40,7 +40,6 @@ use crate::{ }, metrics::{ compaction_build_one_timer, - finish_compaction_timer, log_compaction_compacted_segment_num_documents_total, log_compaction_total_segments, CompactionReason, @@ -168,7 +167,7 @@ impl SearchIndexCompactor { } async fn build_one(&self, job: CompactionJob) -> anyhow::Result { - let timer = compaction_build_one_timer(Self::search_type()); + let timer = compaction_build_one_timer(Self::search_type(), job.compaction_reason); let snapshot_ts = match job.on_disk_state { SearchOnDiskState::Backfilling(BackfillState { backfill_snapshot_ts, @@ -218,8 +217,7 @@ impl SearchIndexCompactor { .collect::>>()?, Self::format(&new_segment, &job.developer_config)?, ); - - finish_compaction_timer(timer, job.compaction_reason); + timer.finish(); Ok(total_compacted_segments) } diff --git a/crates/database/src/metrics.rs b/crates/database/src/metrics.rs index 9ec01093..5872c547 100644 --- a/crates/database/src/metrics.rs +++ b/crates/database/src/metrics.rs @@ -1,5 +1,3 @@ -use std::sync::LazyLock; - use ::search::metrics::{ SearchType, SEARCH_TYPE_LABEL, @@ -889,26 +887,22 @@ impl CompactionReason { StaticMetricLabel::new(COMPACTION_REASON_LABEL, label) } } -static UNKNOWN_COMPACTION_LABEL: LazyLock = - LazyLock::new(|| StaticMetricLabel::new(COMPACTION_REASON_LABEL, "unknown")); register_convex_histogram!( COMPACTION_BUILD_ONE_SECONDS, "Time to run a single vector/text index compaction", &[STATUS_LABEL[0], COMPACTION_REASON_LABEL, SEARCH_TYPE_LABEL], ); -pub fn compaction_build_one_timer(search_type: SearchType) -> StatusTimer { +pub fn compaction_build_one_timer( + search_type: SearchType, + reason: CompactionReason, +) -> StatusTimer { let mut timer = StatusTimer::new(&COMPACTION_BUILD_ONE_SECONDS); timer.add_label(search_type.tag()); - timer.add_label(UNKNOWN_COMPACTION_LABEL.clone()); + timer.add_label(reason.metric_label()); timer } -pub fn finish_compaction_timer(mut timer: StatusTimer, reason: CompactionReason) { - timer.replace_label(UNKNOWN_COMPACTION_LABEL.clone(), reason.metric_label()); - timer.finish(); -} - register_convex_histogram!( COMPACTION_COMPACTED_SEGMENTS_TOTAL, "Total number of compacted segments",