Skip to content

Commit 829f0ad

Browse files
gautamg795Convex, Inc.
authored andcommitted
Convert a bunch of gauges (#34513)
GitOrigin-RevId: 0889bfc972867ec934018ab0f117ea2b8a754c92
1 parent c3f7195 commit 829f0ad

File tree

12 files changed

+43
-102
lines changed

12 files changed

+43
-102
lines changed

crates/application/src/application_function_runner/metrics.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use metrics::{
66
log_counter,
77
log_counter_with_labels,
88
log_distribution,
9-
log_gauge_with_labels,
9+
log_distribution_with_labels,
1010
register_convex_counter,
11-
register_convex_gauge,
1211
register_convex_histogram,
1312
StaticMetricLabel,
1413
StatusTimer,
@@ -69,7 +68,7 @@ pub enum OutstandingFunctionState {
6968
Waiting,
7069
}
7170

72-
register_convex_gauge!(
71+
register_convex_histogram!(
7372
APPLICATION_FUNCTION_RUNNER_OUTSTANDING_TOTAL,
7473
"The number of currently outstanding functions of a given type. Includes both running and \
7574
waiting functions",
@@ -88,7 +87,7 @@ pub fn log_outstanding_functions(
8887
OutstandingFunctionState::Waiting => "waiting",
8988
},
9089
);
91-
log_gauge_with_labels(
90+
log_distribution_with_labels(
9291
&APPLICATION_FUNCTION_RUNNER_OUTSTANDING_TOTAL,
9392
total as f64,
9493
vec![udf_type.metric_label(), state_label, env.metric_label()],

crates/application/src/cache/metrics.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ pub fn log_validate_system_time_in_the_future() {
165165
log_counter(&CACHE_VALIDATE_SYSTEM_TIME_IN_THE_FUTURE_TOTAL, 1);
166166
}
167167

168+
// n.b. this gauge is safe in a multi-instance context because it is shared
169+
// across all instances.
168170
register_convex_gauge!(CACHE_SIZE_BYTES, "Size of the cache in bytes");
169171
pub fn log_cache_size(size: usize) {
170172
log_gauge(&CACHE_SIZE_BYTES, size as f64)
@@ -194,6 +196,8 @@ register_convex_counter!(
194196
QUERY_CACHE_EVICTED_TOTAL,
195197
"The total number of records evicted",
196198
);
199+
// n.b. this gauge is safe in a multi-instance context because it is shared
200+
// across all instances.
197201
register_convex_gauge!(
198202
QUERY_CACHE_EVICTED_AGE_SECONDS,
199203
"The age of the last evicted entry",

crates/application/src/cron_jobs/metrics.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use errors::ErrorMetadataAnyhowExt;
44
use metrics::{
55
log_counter_with_labels,
66
log_distribution,
7-
log_gauge,
87
register_convex_counter,
9-
register_convex_gauge,
108
register_convex_histogram,
119
StaticMetricLabel,
1210
STATUS_LABEL,
@@ -38,7 +36,7 @@ pub fn log_cron_job_failure(e: &anyhow::Error) {
3836
)
3937
}
4038

41-
register_convex_gauge!(CRON_JOB_EXECUTION_LAG_SECONDS, "Cron job execution lag");
39+
register_convex_histogram!(CRON_JOB_EXECUTION_LAG_SECONDS, "Cron job execution lag");
4240
pub fn log_cron_job_execution_lag(lag: Duration) {
43-
log_gauge(&CRON_JOB_EXECUTION_LAG_SECONDS, lag.as_secs_f64());
41+
log_distribution(&CRON_JOB_EXECUTION_LAG_SECONDS, lag.as_secs_f64());
4442
}

crates/application/src/metrics.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use metrics::{
22
log_counter_with_labels,
33
log_distribution_with_labels,
4-
log_gauge_with_labels,
54
register_convex_counter,
6-
register_convex_gauge,
75
register_convex_histogram,
86
StaticMetricLabel,
97
StatusTimer,
@@ -53,28 +51,15 @@ pub struct AppWorkerStatus {
5351

5452
impl Drop for AppWorkerStatus {
5553
fn drop(&mut self) {
56-
log_worker_status(false, self.name);
54+
tracing::debug!("Worker {} finished", self.name);
5755
}
5856
}
5957

60-
register_convex_gauge!(
61-
APP_WORKER_IN_PROGRESS_TOTAL,
62-
"1 if a worker is working, 0 otherwise",
63-
&["worker"],
64-
);
6558
pub fn log_worker_starting(name: &'static str) -> AppWorkerStatus {
66-
log_worker_status(true, name);
59+
tracing::debug!("Worker {} started", name);
6760
AppWorkerStatus { name }
6861
}
6962

70-
fn log_worker_status(is_working: bool, name: &'static str) {
71-
log_gauge_with_labels(
72-
&APP_WORKER_IN_PROGRESS_TOTAL,
73-
if is_working { 1f64 } else { 0f64 },
74-
vec![StaticMetricLabel::new("worker", name)],
75-
)
76-
}
77-
7863
register_convex_counter!(
7964
TABLE_SUMMARY_CHECKPOINT_TOTAL,
8065
"Number of table summary checkpoint writes",

crates/application/src/scheduled_jobs/metrics.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ use std::time::Duration;
33
use errors::ErrorMetadataAnyhowExt;
44
use metrics::{
55
log_counter_with_labels,
6+
log_distribution,
67
log_distribution_with_labels,
7-
log_gauge,
88
prometheus::VMHistogram,
99
register_convex_counter,
10-
register_convex_gauge,
1110
register_convex_histogram,
1211
StaticMetricLabel,
1312
Timer,
@@ -50,20 +49,20 @@ pub fn log_scheduled_job_failure(e: &anyhow::Error, prev_failures: u32) {
5049
);
5150
}
5251

53-
register_convex_gauge!(
52+
register_convex_histogram!(
5453
SCHEDULED_JOB_EXECUTION_LAG_SECONDS,
5554
"Schedule job execution lag"
5655
);
5756
pub fn log_scheduled_job_execution_lag(lag: Duration) {
58-
log_gauge(&SCHEDULED_JOB_EXECUTION_LAG_SECONDS, lag.as_secs_f64());
57+
log_distribution(&SCHEDULED_JOB_EXECUTION_LAG_SECONDS, lag.as_secs_f64());
5958
}
6059

61-
register_convex_gauge!(
60+
register_convex_histogram!(
6261
SCHEDULED_JOB_NUM_RUNNING_TOTAL,
6362
"Number of currently executing scheduled jobs"
6463
);
6564
pub fn log_num_running_jobs(num_running: usize) {
66-
log_gauge(&SCHEDULED_JOB_NUM_RUNNING_TOTAL, num_running as f64);
65+
log_distribution(&SCHEDULED_JOB_NUM_RUNNING_TOTAL, num_running as f64);
6766
}
6867

6968
register_convex_histogram!(

crates/common/src/metrics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub fn log_undefined_filter() {
4343
log_counter(&COMMON_UNDEFINED_FILTER_TOTAL, 1);
4444
}
4545

46+
// Note: These Codel queue gauges are incorrect if the process contains multiple
47+
// queues.
4648
register_convex_gauge!(COMMON_CODEL_QUEUE_LENGTH_TOTAL, "Length of the CoDel queue");
4749
pub fn log_codel_queue_size(size: usize) {
4850
log_gauge(&COMMON_CODEL_QUEUE_LENGTH_TOTAL, size as f64)

crates/database/src/index_worker.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ use crate::{
9999
metrics::{
100100
log_index_backfilled,
101101
log_num_indexes_to_backfill,
102-
log_worker_starting,
103102
},
104103
retention::LeaderRetentionManager,
105104
Database,
@@ -295,7 +294,6 @@ impl<RT: Runtime> IndexWorker<RT> {
295294
async fn run(&mut self) -> anyhow::Result<()> {
296295
tracing::info!("Starting IndexWorker");
297296
loop {
298-
let status = log_worker_starting("IndexWorker");
299297
// Get all the documents from the `_index` table.
300298
let mut tx = self.database.begin(Identity::system()).await?;
301299
// Index doesn't have `by_creation_time` index, and thus can't be queried via
@@ -357,7 +355,6 @@ impl<RT: Runtime> IndexWorker<RT> {
357355
if self.should_terminate {
358356
return Ok(());
359357
}
360-
drop(status);
361358

362359
let token = tx.into_token()?;
363360
let subscription = self.database.subscribe(token).await?;

crates/database/src/index_workers/fast_forward.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ use crate::{
5757
retriable_worker::RetriableWorker,
5858
timeout_with_jitter,
5959
},
60-
metrics::log_worker_starting,
6160
text_index_worker::fast_forward::TextFastForward,
6261
vector_index_worker::fast_forward::VectorFastForward,
6362
Database,
@@ -120,7 +119,6 @@ impl FastForwardIndexWorker {
120119
let mut vector_search_last_fast_forward_info: Option<LastFastForwardInfo> = None;
121120

122121
loop {
123-
let status = log_worker_starting("TextSearchFastForward");
124122
tracing::debug!("FastForwardWorker checking if we can fast forward");
125123
Self::fast_forward::<RT, TextSnapshotVersion, TextFastForward>(
126124
"TextSearch",
@@ -129,16 +127,13 @@ impl FastForwardIndexWorker {
129127
&mut text_search_last_fast_forward_info,
130128
)
131129
.await?;
132-
drop(status);
133-
let status = log_worker_starting("VectorSearchFastForward");
134130
Self::fast_forward::<RT, (), VectorFastForward>(
135131
"VectorSearch",
136132
rt,
137133
db,
138134
&mut vector_search_last_fast_forward_info,
139135
)
140136
.await?;
141-
drop(status);
142137

143138
backoff.reset();
144139
timeout_with_jitter(rt, *DATABASE_WORKERS_POLL_INTERVAL).await

crates/database/src/index_workers/search_worker.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use crate::{
4040
timeout_with_jitter,
4141
writer::SearchIndexMetadataWriter,
4242
},
43-
metrics::log_worker_starting,
4443
text_index_worker::{
4544
compactor::{
4645
new_text_compactor,
@@ -215,9 +214,7 @@ impl<RT: Runtime> SearchIndexWorker<RT> {
215214
backoff: &mut Backoff,
216215
) -> anyhow::Result<()> {
217216
loop {
218-
let status = log_worker_starting(name);
219217
let (metrics, token) = self.step().await?;
220-
drop(status);
221218

222219
if !metrics.is_empty() {
223220
// We did some useful work this loop iteration that we expect is committed.

crates/database/src/metrics.rs

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use metrics::{
1212
log_counter_with_labels,
1313
log_distribution,
1414
log_distribution_with_labels,
15-
log_gauge,
16-
log_gauge_with_labels,
1715
register_convex_counter,
18-
register_convex_gauge,
1916
register_convex_histogram,
2017
IntoLabel,
2118
StaticMetricLabel,
@@ -33,25 +30,25 @@ use crate::{
3330
Transaction,
3431
};
3532

36-
register_convex_gauge!(
33+
register_convex_histogram!(
3734
DOCUMENTS_SIZE_BYTES,
3835
"Total size of document store in bytes"
3936
);
4037
pub fn log_document_store_size(total_size: u64) {
41-
log_gauge(&DOCUMENTS_SIZE_BYTES, total_size as f64);
38+
log_distribution(&DOCUMENTS_SIZE_BYTES, total_size as f64);
4239
}
4340

44-
register_convex_gauge!(DOCUMENTS_KEYS_TOTAL, "Total number of document keys");
41+
register_convex_histogram!(DOCUMENTS_KEYS_TOTAL, "Total number of document keys");
4542
pub fn log_num_keys(num_keys: u64) {
46-
log_gauge(&DOCUMENTS_KEYS_TOTAL, num_keys as f64);
43+
log_distribution(&DOCUMENTS_KEYS_TOTAL, num_keys as f64);
4744
}
4845

49-
register_convex_gauge!(
46+
register_convex_histogram!(
5047
INDEXES_TO_BACKFILL_TOTAL,
5148
"Number of indexes needing backfill"
5249
);
5350
pub fn log_num_indexes_to_backfill(num_indexes: usize) {
54-
log_gauge(&INDEXES_TO_BACKFILL_TOTAL, num_indexes as f64);
51+
log_distribution(&INDEXES_TO_BACKFILL_TOTAL, num_indexes as f64);
5552
}
5653

5754
register_convex_counter!(INDEXES_BACKFILLED_TOTAL, "Number of indexes backfilled");
@@ -406,49 +403,49 @@ pub fn retention_delete_document_chunk_timer() -> Timer<VMHistogram> {
406403
Timer::new(&RETENTION_DELETE_DOCUMENT_CHUNK_SECONDS)
407404
}
408405

409-
register_convex_gauge!(RETENTION_CURSOR_AGE_SECONDS, "Age of the retention cursor");
406+
register_convex_histogram!(RETENTION_CURSOR_AGE_SECONDS, "Age of the retention cursor");
410407
pub fn log_retention_cursor_age(age_secs: f64) {
411-
log_gauge(&RETENTION_CURSOR_AGE_SECONDS, age_secs)
408+
log_distribution(&RETENTION_CURSOR_AGE_SECONDS, age_secs)
412409
}
413410

414-
register_convex_gauge!(
411+
register_convex_histogram!(
415412
RETENTION_CURSOR_LAG_SECONDS,
416413
"Lag between the retention cursor and the min index snapshot"
417414
);
418415
pub fn log_retention_cursor_lag(age_secs: f64) {
419-
log_gauge(&RETENTION_CURSOR_LAG_SECONDS, age_secs)
416+
log_distribution(&RETENTION_CURSOR_LAG_SECONDS, age_secs)
420417
}
421418

422-
register_convex_gauge!(
419+
register_convex_histogram!(
423420
DOCUMENT_RETENTION_CURSOR_AGE_SECONDS,
424421
"Age of the document retention cursor"
425422
);
426423
pub fn log_document_retention_cursor_age(age_secs: f64) {
427-
log_gauge(&DOCUMENT_RETENTION_CURSOR_AGE_SECONDS, age_secs)
424+
log_distribution(&DOCUMENT_RETENTION_CURSOR_AGE_SECONDS, age_secs)
428425
}
429426

430-
register_convex_gauge!(
427+
register_convex_histogram!(
431428
DOCUMENT_RETENTION_CURSOR_LAG_SECONDS,
432429
"Lag between the retention cursor and the min document snapshot"
433430
);
434431
pub fn log_document_retention_cursor_lag(age_secs: f64) {
435-
log_gauge(&DOCUMENT_RETENTION_CURSOR_LAG_SECONDS, age_secs)
432+
log_distribution(&DOCUMENT_RETENTION_CURSOR_LAG_SECONDS, age_secs)
436433
}
437434

438-
register_convex_gauge!(
435+
register_convex_counter!(
439436
RETENTION_MISSING_CURSOR_INFO,
440437
"Index retention has no cursor"
441438
);
442439
pub fn log_retention_no_cursor() {
443-
log_gauge(&RETENTION_MISSING_CURSOR_INFO, 1.0)
440+
log_counter(&RETENTION_MISSING_CURSOR_INFO, 1)
444441
}
445442

446-
register_convex_gauge!(
443+
register_convex_counter!(
447444
DOCUMENT_RETENTION_MISSING_CURSOR_INFO,
448445
"Document retention has no cursor"
449446
);
450447
pub fn log_document_retention_no_cursor() {
451-
log_gauge(&DOCUMENT_RETENTION_MISSING_CURSOR_INFO, 1.0)
448+
log_counter(&DOCUMENT_RETENTION_MISSING_CURSOR_INFO, 1)
452449
}
453450

454451
register_convex_counter!(
@@ -645,34 +642,6 @@ pub fn log_virtual_table_query() {
645642
log_counter(&VIRTUAL_TABLE_QUERY_REQUESTS_TOTAL, 1);
646643
}
647644

648-
pub struct DatabaseWorkerStatus {
649-
name: &'static str,
650-
}
651-
652-
impl Drop for DatabaseWorkerStatus {
653-
fn drop(&mut self) {
654-
log_worker_status(false, self.name);
655-
}
656-
}
657-
658-
register_convex_gauge!(
659-
DATABASE_WORKER_IN_PROGRESS_TOTAL,
660-
"1 if a worker is working, 0 otherwise",
661-
&["worker"],
662-
);
663-
pub fn log_worker_starting(name: &'static str) -> DatabaseWorkerStatus {
664-
log_worker_status(true, name);
665-
DatabaseWorkerStatus { name }
666-
}
667-
668-
fn log_worker_status(is_working: bool, name: &'static str) {
669-
log_gauge_with_labels(
670-
&DATABASE_WORKER_IN_PROGRESS_TOTAL,
671-
if is_working { 1f64 } else { 0f64 },
672-
vec![StaticMetricLabel::new("worker", name)],
673-
)
674-
}
675-
676645
register_convex_histogram!(
677646
SEARCH_AND_VECTOR_BOOTSTRAP_SECONDS,
678647
"Time taken to bootstrap text and vector indexes",

0 commit comments

Comments
 (0)