Skip to content

Commit 2de5b4a

Browse files
nipunn1313Convex, Inc.
authored andcommitted
Add lag metric for system table cleanup cursor (#35994)
To track lag on the cleanup worker. GitOrigin-RevId: 09511f1d3e3f286e8ae14f347e6a5f9a2273395f
1 parent ca0c120 commit 2de5b4a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

crates/application/src/system_table_cleanup/metrics.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use chrono::Utc;
2+
use common::document::CreationTime;
13
use metrics::{
24
log_counter,
35
log_counter_with_labels,
6+
log_distribution_with_labels,
47
prometheus::VMHistogram,
58
register_convex_counter,
69
register_convex_histogram,
@@ -37,3 +40,18 @@ register_convex_counter!(
3740
pub fn log_exports_s3_cleanup() {
3841
log_counter(&EXPORT_TABLE_CLEANUP_ROWS_TOTAL, 1)
3942
}
43+
44+
register_convex_histogram!(
45+
SYSTEM_TABLE_CLEANUP_CURSOR_LAG_SECONDS,
46+
"Lag between system table cleanup cursor and now",
47+
&["table"]
48+
);
49+
pub fn log_system_table_cursor_lag(table_name: &TableName, cursor: CreationTime) {
50+
let now = Utc::now().timestamp_millis();
51+
let delay_ms = (now as f64) - f64::from(cursor);
52+
log_distribution_with_labels(
53+
&SYSTEM_TABLE_CLEANUP_CURSOR_LAG_SECONDS,
54+
delay_ms / 1000.0,
55+
vec![StaticMetricLabel::new("table", table_name.to_string())],
56+
)
57+
}

crates/application/src/system_table_cleanup/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ use keybroker::Identity;
5555
use metrics::{
5656
log_exports_s3_cleanup,
5757
log_system_table_cleanup_rows,
58+
log_system_table_cursor_lag,
5859
system_table_cleanup_timer,
5960
};
6061
use model::{
@@ -334,6 +335,9 @@ impl<RT: Runtime> SystemTableCleanupWorker<RT> {
334335
.await?;
335336
tracing::info!("deleted {deleted_count} documents from {table}");
336337
log_system_table_cleanup_rows(table, deleted_count);
338+
if let Some(cursor) = cursor {
339+
log_system_table_cursor_lag(table, *cursor);
340+
}
337341
Ok(deleted_count)
338342
}
339343

0 commit comments

Comments
 (0)