@@ -21,18 +21,16 @@ use crate::server::metrics::{LabelsProxy, Metrics};
2121
2222// Proxy ---------------------------------------------------------------
2323
24- pub ( crate ) trait Proxy < P >
25- where
26- P : ProxyInner ,
27- {
24+ pub ( crate ) trait Proxy {
2825 fn on_connect (
2926 metrics : Arc < Metrics > ,
3027 client_connections_count : Arc < AtomicI64 > ,
28+ proxy_name : String ,
3129 ) -> impl Fn ( & dyn Any , & mut Extensions ) {
3230 move |connection, extensions| {
3331 {
3432 let val = client_connections_count. fetch_add ( 1 , Ordering :: Relaxed ) + 1 ;
35- let metric_labels = LabelsProxy { proxy : P :: name ( ) } ;
33+ let metric_labels = LabelsProxy { proxy : proxy_name . clone ( ) } ;
3634
3735 metrics. client_connections_active_count . get_or_create ( & metric_labels) . set ( val) ;
3836 metrics. client_connections_established_count . get_or_create ( & metric_labels) . inc ( ) ;
7573
7674 extensions. insert ( ProxyConnectionGuard :: new (
7775 id,
78- P :: name ( ) ,
76+ & proxy_name ,
7977 remote_addr,
8078 local_addr,
8179 & metrics,
@@ -86,28 +84,22 @@ where
8684 }
8785}
8886
89- // ProxyInner ----------------------------------------------------------
90-
91- pub ( crate ) trait ProxyInner : ' static {
92- fn name ( ) -> & ' static str ;
93- }
94-
9587// ProxyConnectionGuard ------------------------------------------------
9688
9789pub struct ProxyConnectionGuard {
9890 pub id : Uuid ,
9991 pub remote_addr : Option < String > ,
10092 pub local_addr : Option < String > ,
10193
102- proxy_name : & ' static str ,
94+ proxy_name : String ,
10395 metrics : Arc < Metrics > ,
10496 client_connections_count : Arc < AtomicI64 > ,
10597}
10698
10799impl ProxyConnectionGuard {
108100 fn new (
109101 id : Uuid ,
110- proxy_name : & ' static str ,
102+ proxy_name : & str ,
111103 remote_addr : Option < String > ,
112104 local_addr : Option < String > ,
113105 metrics : & Arc < Metrics > ,
@@ -117,7 +109,7 @@ impl ProxyConnectionGuard {
117109 id,
118110 remote_addr,
119111 local_addr,
120- proxy_name,
112+ proxy_name : proxy_name . to_string ( ) ,
121113 metrics : metrics. clone ( ) ,
122114 client_connections_count,
123115 }
@@ -128,7 +120,7 @@ impl Drop for ProxyConnectionGuard {
128120 fn drop ( & mut self ) {
129121 let val = self . client_connections_count . fetch_sub ( 1 , Ordering :: Relaxed ) - 1 ;
130122
131- let metric_labels = LabelsProxy { proxy : self . proxy_name } ;
123+ let metric_labels = LabelsProxy { proxy : self . proxy_name . clone ( ) } ;
132124
133125 self . metrics . client_connections_active_count . get_or_create ( & metric_labels) . set ( val) ;
134126 self . metrics . client_connections_closed_count . get_or_create ( & metric_labels) . inc ( ) ;
0 commit comments