@@ -71,7 +71,7 @@ use webpki::types::ServerName;
7171#[ cfg( feature = "metrics" ) ]
7272use {
7373 hyper_util:: client:: legacy:: {
74- pool:: { ConnectionEvent , EventHandler , Tag } ,
74+ pool:: { EventHandler , PoolEvent } ,
7575 PoolKey ,
7676 } ,
7777 std:: any:: Any ,
@@ -209,7 +209,7 @@ impl HttpChannelBuilder {
209209 #[ cfg( feature = "metrics" ) ]
210210 {
211211 let cluster_name = self . cluster_name . unwrap_or_default ( ) ;
212- client_builder. event_handler ( EventHandler :: new ( update_upstream_stats, cluster_name) ) ;
212+ client_builder. pool_event_handler ( EventHandler :: new ( update_upstream_stats, cluster_name) ) ;
213213 }
214214
215215 client_builder
@@ -318,51 +318,89 @@ impl HttpChannelBuilder {
318318
319319#[ cfg( feature = "metrics" ) ]
320320#[ allow( clippy:: needless_pass_by_value) ]
321- fn update_upstream_stats ( event : ConnectionEvent , key : & dyn Any , tag : & dyn Tag ) {
321+ fn update_upstream_stats ( event : PoolEvent , tag : & dyn Any , keys : & [ & PoolKey ] ) {
322322 use tracing:: debug;
323- let cluster_name = * ( tag. as_any ( ) . downcast_ref :: < & str > ( ) . unwrap_or ( & "" ) ) ;
323+ let cluster_name = * ( tag. downcast_ref :: < & str > ( ) . unwrap_or ( & "" ) ) ;
324324 let shard_id = std:: thread:: current ( ) . id ( ) ;
325- if let Some ( pk) = key. downcast_ref :: < PoolKey > ( ) {
326- debug ! ( "HttpClient: {:?} for cluster {:?} (pool_key: {:?})" , event, cluster_name, pk) ;
325+
326+ for key in keys {
327+ debug ! ( "HttpClient: {:?} for cluster {:?} (pool_key: {:?})" , event, cluster_name, key) ;
327328 }
328329
330+ let num_events = keys. len ( ) as u64 ;
329331 match event {
330- ConnectionEvent :: NewConnection => {
331- with_metric ! ( clusters:: UPSTREAM_CX_TOTAL , add, 1 , shard_id, & [ KeyValue :: new( "cluster" , cluster_name) ] ) ;
332- with_metric ! ( clusters:: UPSTREAM_CX_ACTIVE , add, 1 , shard_id, & [ KeyValue :: new( "cluster" , cluster_name) ] ) ;
332+ PoolEvent :: NewConnection => {
333+ with_metric ! (
334+ clusters:: UPSTREAM_CX_TOTAL ,
335+ add,
336+ num_events,
337+ shard_id,
338+ & [ KeyValue :: new( "cluster" , cluster_name) ]
339+ ) ;
340+ with_metric ! (
341+ clusters:: UPSTREAM_CX_ACTIVE ,
342+ add,
343+ num_events,
344+ shard_id,
345+ & [ KeyValue :: new( "cluster" , cluster_name) ]
346+ ) ;
333347 } ,
334- ConnectionEvent :: IdleConnectionClosed => {
335- with_metric ! ( clusters:: UPSTREAM_CX_DESTROY , add, 1 , shard_id, & [ KeyValue :: new( "cluster" , cluster_name) ] ) ;
348+ PoolEvent :: IdleConnectionClosed => {
349+ with_metric ! (
350+ clusters:: UPSTREAM_CX_DESTROY ,
351+ add,
352+ num_events,
353+ shard_id,
354+ & [ KeyValue :: new( "cluster" , cluster_name) ]
355+ ) ;
336356 with_metric ! (
337357 clusters:: UPSTREAM_CX_IDLE_TIMEOUT ,
338358 add,
339- 1 ,
359+ num_events,
360+ shard_id,
361+ & [ KeyValue :: new( "cluster" , cluster_name) ]
362+ ) ;
363+ with_metric ! (
364+ clusters:: UPSTREAM_CX_ACTIVE ,
365+ sub,
366+ num_events,
340367 shard_id,
341368 & [ KeyValue :: new( "cluster" , cluster_name) ]
342369 ) ;
343- with_metric ! ( clusters:: UPSTREAM_CX_ACTIVE , sub, 1 , shard_id, & [ KeyValue :: new( "cluster" , cluster_name) ] ) ;
344370 } ,
345- ConnectionEvent :: ConnectionError => {
371+ PoolEvent :: ConnectionError => {
346372 with_metric ! (
347373 clusters:: UPSTREAM_CX_CONNECT_FAIL ,
348374 add,
349- 1 ,
375+ num_events ,
350376 shard_id,
351377 & [ KeyValue :: new( "cluster" , cluster_name) ]
352378 ) ;
353379 } ,
354- ConnectionEvent :: ConnectionTimeout => {
380+ PoolEvent :: ConnectionTimeout => {
355381 with_metric ! (
356382 clusters:: UPSTREAM_CX_CONNECT_TIMEOUT ,
357383 add,
358- 1 ,
384+ num_events ,
359385 shard_id,
360386 & [ KeyValue :: new( "cluster" , cluster_name) ]
361387 ) ;
362388 } ,
363- ConnectionEvent :: ConnectionClosed => {
364- with_metric ! ( clusters:: UPSTREAM_CX_DESTROY , add, 1 , shard_id, & [ KeyValue :: new( "cluster" , cluster_name) ] ) ;
365- with_metric ! ( clusters:: UPSTREAM_CX_ACTIVE , sub, 1 , shard_id, & [ KeyValue :: new( "cluster" , cluster_name) ] ) ;
389+ PoolEvent :: ConnectionClosed => {
390+ with_metric ! (
391+ clusters:: UPSTREAM_CX_DESTROY ,
392+ add,
393+ num_events,
394+ shard_id,
395+ & [ KeyValue :: new( "cluster" , cluster_name) ]
396+ ) ;
397+ with_metric ! (
398+ clusters:: UPSTREAM_CX_ACTIVE ,
399+ sub,
400+ num_events,
401+ shard_id,
402+ & [ KeyValue :: new( "cluster" , cluster_name) ]
403+ ) ;
366404 } ,
367405 }
368406}
0 commit comments