Skip to content

Commit

Permalink
add compaction reason to timer before finishing in case it fails (#31…
Browse files Browse the repository at this point in the history
…800)

GitOrigin-RevId: 749ca85213ebafbbf769de04b33f5a785d918ad0
  • Loading branch information
emmaling27 authored and Convex, Inc. committed Nov 26, 2024
1 parent d9de191 commit 912bde7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
6 changes: 2 additions & 4 deletions crates/database/src/index_workers/search_compactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -168,7 +167,7 @@ impl<RT: Runtime, T: SearchIndex> SearchIndexCompactor<RT, T> {
}

async fn build_one(&self, job: CompactionJob<T>) -> anyhow::Result<u64> {
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,
Expand Down Expand Up @@ -218,8 +217,7 @@ impl<RT: Runtime, T: SearchIndex> SearchIndexCompactor<RT, T> {
.collect::<anyhow::Result<Vec<_>>>()?,
Self::format(&new_segment, &job.developer_config)?,
);

finish_compaction_timer(timer, job.compaction_reason);
timer.finish();
Ok(total_compacted_segments)
}

Expand Down
16 changes: 5 additions & 11 deletions crates/database/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::LazyLock;

use ::search::metrics::{
SearchType,
SEARCH_TYPE_LABEL,
Expand Down Expand Up @@ -889,26 +887,22 @@ impl CompactionReason {
StaticMetricLabel::new(COMPACTION_REASON_LABEL, label)
}
}
static UNKNOWN_COMPACTION_LABEL: LazyLock<StaticMetricLabel> =
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",
Expand Down

0 comments on commit 912bde7

Please sign in to comment.