Skip to content

Commit e2dde82

Browse files
committed
Add a gauge which tracks the number of pending activity records
1 parent a4a6cce commit e2dde82

File tree

1 file changed

+14
-1
lines changed
  • crates/handlers/src/activity_tracker

1 file changed

+14
-1
lines changed

crates/handlers/src/activity_tracker/worker.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use chrono::{DateTime, Utc};
1010
use mas_storage::{RepositoryAccess, RepositoryError, user::BrowserSessionRepository};
1111
use opentelemetry::{
1212
Key, KeyValue,
13-
metrics::{Counter, Histogram},
13+
metrics::{Counter, Gauge, Histogram},
1414
};
1515
use sqlx::PgPool;
1616
use tokio_util::sync::CancellationToken;
@@ -45,6 +45,7 @@ struct ActivityRecord {
4545
pub struct Worker {
4646
pool: PgPool,
4747
pending_records: HashMap<(SessionKind, Ulid), ActivityRecord>,
48+
pending_records_gauge: Gauge<u64>,
4849
message_counter: Counter<u64>,
4950
flush_time_histogram: Histogram<u64>,
5051
}
@@ -80,9 +81,17 @@ impl Worker {
8081
.with_unit("ms")
8182
.build();
8283

84+
let pending_records_gauge = METER
85+
.u64_gauge("mas.activity_tracker.pending_records")
86+
.with_description("The number of pending activity records")
87+
.with_unit("{records}")
88+
.build();
89+
pending_records_gauge.record(0, &[]);
90+
8391
Self {
8492
pool,
8593
pending_records: HashMap::with_capacity(MAX_PENDING_RECORDS),
94+
pending_records_gauge,
8695
message_counter,
8796
flush_time_histogram,
8897
}
@@ -165,6 +174,10 @@ impl Worker {
165174
let _ = tx.send(());
166175
}
167176
}
177+
178+
// Update the gauge
179+
self.pending_records_gauge
180+
.record(self.pending_records.len() as u64, &[]);
168181
}
169182

170183
// Flush one last time

0 commit comments

Comments
 (0)