File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed
Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 1212use std:: fmt:: Debug ;
1313use std:: num:: NonZeroI64 ;
1414use std:: sync:: Arc ;
15- use std:: time:: Duration ;
15+ use std:: time:: { Duration , Instant } ;
1616
1717use async_trait:: async_trait;
1818use 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
Original file line number Diff line number Diff line change 1111
1212use mz_ore:: metric;
1313use 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 ) ]
1718pub 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
2830impl 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments