@@ -2,11 +2,12 @@ use std::{
22 borrow:: Cow ,
33 collections:: { HashMap , HashSet } ,
44 net:: SocketAddr ,
5- sync:: { Arc , RwLock } ,
5+ sync:: { Arc , OnceLock , RwLock } ,
66 time:: Duration ,
77} ;
88
99use notify:: { RecursiveMode , Watcher } ;
10+ use opentelemetry:: { KeyValue , metrics:: Counter } ;
1011use pool_nts:: {
1112 AlgorithmDescription , AlgorithmId , BufferBorrowingReader , MAX_MESSAGE_SIZE , ProtocolId ,
1213 ServerInformationRequest , ServerInformationResponse ,
@@ -166,6 +167,7 @@ fn calculate_auth_key(
166167
167168async fn fetch_support_data (
168169 mut connection : impl ServerConnection ,
170+ uuid : Arc < str > ,
169171 key : String ,
170172 allowed_protocols : & HashSet < ProtocolId > ,
171173 timeout : Duration ,
@@ -176,6 +178,15 @@ async fn fetch_support_data(
176178 ) ,
177179 PoolError ,
178180> {
181+ static SUPPORT_REQUEST_COUNTER : OnceLock < Counter < u64 > > = OnceLock :: new ( ) ;
182+
183+ let support_request_counter = SUPPORT_REQUEST_COUNTER . get_or_init ( || {
184+ opentelemetry:: global:: meter ( "PoolKe" )
185+ . u64_counter ( "support_info_requests" )
186+ . with_description ( "Number of requests to server about what is supported" )
187+ . build ( )
188+ } ) ;
189+
179190 match tokio:: time:: timeout ( timeout, async {
180191 ServerInformationRequest {
181192 key : key. into ( ) ,
@@ -209,8 +220,32 @@ async fn fetch_support_data(
209220 } )
210221 . await
211222 {
212- Ok ( v) => v,
213- Err ( _) => Err ( PoolError :: Timeout ) ,
223+ Ok ( v) => {
224+ support_request_counter. add (
225+ 1 ,
226+ & [
227+ KeyValue :: new ( "uuid" , uuid) ,
228+ KeyValue :: new (
229+ "outcome" ,
230+ match v {
231+ Ok ( _) => "success" ,
232+ Err ( _) => "error" ,
233+ } ,
234+ ) ,
235+ ] ,
236+ ) ;
237+ v
238+ }
239+ Err ( _) => {
240+ support_request_counter. add (
241+ 1 ,
242+ & [
243+ KeyValue :: new ( "uuid" , uuid) ,
244+ KeyValue :: new ( "outcome" , "timeout" ) ,
245+ ] ,
246+ ) ;
247+ Err ( PoolError :: Timeout )
248+ }
214249 }
215250}
216251
@@ -385,6 +420,7 @@ mod tests {
385420
386421 let ( protocols, algorithms) = fetch_support_data (
387422 connection,
423+ "uuid" . into ( ) ,
388424 "abcd" . into ( ) ,
389425 & HashSet :: from ( [ 0 , 1 ] ) ,
390426 Duration :: from_secs ( 1 ) ,
@@ -431,6 +467,7 @@ mod tests {
431467
432468 let ( protocols, algorithms) = fetch_support_data (
433469 connection,
470+ "uuid" . into ( ) ,
434471 "abcd" . into ( ) ,
435472 & HashSet :: from ( [ 0 , 1 ] ) ,
436473 Duration :: from_secs ( 1 ) ,
0 commit comments