1313use std:: collections:: { BTreeMap , BTreeSet } ;
1414use std:: pin:: Pin ;
1515use std:: sync:: Arc ;
16- use std:: time:: Duration ;
16+ use std:: time:: { Duration , Instant } ;
1717
1818use fail:: fail_point;
1919use maplit:: { btreemap, btreeset} ;
@@ -67,8 +67,15 @@ impl Coordinator {
6767 session : Option < & Session > ,
6868 ops : Vec < catalog:: Op > ,
6969 ) -> Result < ( ) , AdapterError > {
70- self . catalog_transact_with_context ( session. map ( |session| session. conn_id ( ) ) , None , ops)
71- . await
70+ let start = Instant :: now ( ) ;
71+ let result = self
72+ . catalog_transact_with_context ( session. map ( |session| session. conn_id ( ) ) , None , ops)
73+ . await ;
74+ self . metrics
75+ . catalog_transact_seconds
76+ . with_label_values ( & [ "catalog_transact" ] )
77+ . observe ( start. elapsed ( ) . as_secs_f64 ( ) ) ;
78+ result
7279 }
7380
7481 /// Same as [`Self::catalog_transact_with_context`] but takes a [`Session`]
@@ -93,6 +100,8 @@ impl Coordinator {
93100 ) -> Pin < Box < dyn Future < Output = ( ) > + ' a > >
94101 + ' static ,
95102 {
103+ let start = Instant :: now ( ) ;
104+
96105 let ( table_updates, catalog_updates) = self
97106 . catalog_transact_inner ( ctx. as_ref ( ) . map ( |ctx| ctx. session ( ) . conn_id ( ) ) , ops)
98107 . await ?;
@@ -129,6 +138,11 @@ impl Coordinator {
129138 )
130139 . await ;
131140
141+ self . metrics
142+ . catalog_transact_seconds
143+ . with_label_values ( & [ "catalog_transact_with_side_effects" ] )
144+ . observe ( start. elapsed ( ) . as_secs_f64 ( ) ) ;
145+
132146 Ok ( ( ) )
133147 }
134148
@@ -146,6 +160,8 @@ impl Coordinator {
146160 ctx : Option < & mut ExecuteContext > ,
147161 ops : Vec < catalog:: Op > ,
148162 ) -> Result < ( ) , AdapterError > {
163+ let start = Instant :: now ( ) ;
164+
149165 let conn_id = conn_id. or_else ( || ctx. as_ref ( ) . map ( |ctx| ctx. session ( ) . conn_id ( ) ) ) ;
150166
151167 let ( table_updates, catalog_updates) = self . catalog_transact_inner ( conn_id, ops) . await ?;
@@ -176,6 +192,11 @@ impl Coordinator {
176192 "coordinator inconsistency detected"
177193 ) ;
178194
195+ self . metrics
196+ . catalog_transact_seconds
197+ . with_label_values ( & [ "catalog_transact_with_context" ] )
198+ . observe ( start. elapsed ( ) . as_secs_f64 ( ) ) ;
199+
179200 Ok ( ( ) )
180201 }
181202
@@ -197,6 +218,8 @@ impl Coordinator {
197218 + Sync
198219 + ' static ,
199220 {
221+ let start = Instant :: now ( ) ;
222+
200223 let Some ( Transaction {
201224 ops :
202225 TransactionOps :: DDL {
@@ -208,13 +231,22 @@ impl Coordinator {
208231 ..
209232 } ) = ctx. session ( ) . transaction ( ) . inner ( )
210233 else {
211- return self
234+ let result = self
212235 . catalog_transact_with_side_effects ( Some ( ctx) , ops, side_effect)
213236 . await ;
237+ self . metrics
238+ . catalog_transact_seconds
239+ . with_label_values ( & [ "catalog_transact_with_ddl_transaction" ] )
240+ . observe ( start. elapsed ( ) . as_secs_f64 ( ) ) ;
241+ return result;
214242 } ;
215243
216244 // Make sure our Catalog hasn't changed since openning the transaction.
217245 if self . catalog ( ) . transient_revision ( ) != * txn_revision {
246+ self . metrics
247+ . catalog_transact_seconds
248+ . with_label_values ( & [ "catalog_transact_with_ddl_transaction" ] )
249+ . observe ( start. elapsed ( ) . as_secs_f64 ( ) ) ;
218250 return Err ( AdapterError :: DDLTransactionRace ) ;
219251 }
220252
@@ -227,7 +259,7 @@ impl Coordinator {
227259 // Run our Catalog transaction, but abort before committing.
228260 let result = self . catalog_transact ( Some ( ctx. session ( ) ) , all_ops) . await ;
229261
230- match result {
262+ let result = match result {
231263 // We purposefully fail with this error to prevent committing the transaction.
232264 Err ( AdapterError :: TransactionDryRun { new_ops, new_state } ) => {
233265 // Sets these ops to our transaction, bailing if the Catalog has changed since we
@@ -244,7 +276,14 @@ impl Coordinator {
244276 }
245277 Ok ( _) => unreachable ! ( "unexpected success!" ) ,
246278 Err ( e) => Err ( e) ,
247- }
279+ } ;
280+
281+ self . metrics
282+ . catalog_transact_seconds
283+ . with_label_values ( & [ "catalog_transact_with_ddl_transaction" ] )
284+ . observe ( start. elapsed ( ) . as_secs_f64 ( ) ) ;
285+
286+ result
248287 }
249288
250289 /// Perform a catalog transaction. [`Coordinator::ship_dataflow`] must be
0 commit comments