Skip to content

Commit 6ef7bdf

Browse files
committed
catalog: add histogram metric for allocate_id
1 parent 1be6a6f commit 6ef7bdf

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/catalog/src/durable.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use std::fmt::Debug;
1313
use std::num::NonZeroI64;
1414
use std::sync::Arc;
15-
use std::time::Duration;
15+
use std::time::{Duration, Instant};
1616

1717
use async_trait::async_trait;
1818
use itertools::Itertools;
@@ -211,6 +211,9 @@ pub trait ReadOnlyDurableCatalogState: Debug + Send + Sync {
211211
/// NB: We may remove this in later iterations of Pv2.
212212
fn epoch(&self) -> Epoch;
213213

214+
/// Returns the metrics for this catalog state.
215+
fn metrics(&self) -> &Metrics;
216+
214217
/// Politely releases all external resources that can only be released in an async context.
215218
async fn expire(self: Box<Self>);
216219

@@ -323,12 +326,16 @@ pub trait DurableCatalogState: ReadOnlyDurableCatalogState {
323326
amount: u64,
324327
commit_ts: Timestamp,
325328
) -> Result<Vec<u64>, CatalogError> {
329+
let start = Instant::now();
326330
if amount == 0 {
327331
return Ok(Vec::new());
328332
}
329333
let mut txn = self.transaction().await?;
330334
let ids = txn.get_and_increment_id_by(id_type.to_string(), amount)?;
331335
txn.commit_internal(commit_ts).await?;
336+
self.metrics()
337+
.allocate_id_seconds
338+
.observe(start.elapsed().as_secs_f64());
332339
Ok(ids)
333340
}
334341

src/catalog/src/durable/metrics.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
1212
use mz_ore::metric;
1313
use mz_ore::metrics::{IntCounter, MetricsRegistry};
14-
use prometheus::{Counter, IntGaugeVec};
14+
use mz_ore::stats::histogram_seconds_buckets;
15+
use prometheus::{Counter, Histogram, IntGaugeVec};
1516

1617
#[derive(Debug, Clone)]
1718
pub struct Metrics {
@@ -23,6 +24,7 @@ pub struct Metrics {
2324
pub syncs: IntCounter,
2425
pub sync_latency_seconds: Counter,
2526
pub collection_entries: IntGaugeVec,
27+
pub allocate_id_seconds: Histogram,
2628
}
2729

2830
impl Metrics {
@@ -62,6 +64,11 @@ impl Metrics {
6264
help: "Total number of entries, after consolidation, per catalog collection.",
6365
var_labels: ["collection"],
6466
)),
67+
allocate_id_seconds: registry.register(metric!(
68+
name: "mz_catalog_allocate_id_seconds",
69+
help: "The time it takes to allocate IDs in the durable catalog.",
70+
buckets: histogram_seconds_buckets(0.001, 32.0),
71+
)),
6572
}
6673
}
6774
}

src/catalog/src/durable/persist.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,10 @@ impl ReadOnlyDurableCatalogState for PersistCatalogState {
15991599
.epoch
16001600
}
16011601

1602+
fn metrics(&self) -> &Metrics {
1603+
&self.metrics
1604+
}
1605+
16021606
#[mz_ore::instrument(level = "debug")]
16031607
async fn expire(self: Box<Self>) {
16041608
self.expire().await

0 commit comments

Comments
 (0)