1+ use crate :: {
2+ metrics:: { self , Counter , FmtMetrics } ,
3+ svc,
4+ transport:: { labels, OrigDstAddr } ,
5+ } ;
16use linkerd_error:: Error ;
2- use linkerd_error_metrics:: { FmtLabels , LabelError , RecordErrorLayer } ;
3- use linkerd_metrics:: { metrics, Counter , FmtMetrics } ;
7+ use linkerd_error_metrics:: { FmtLabels , LabelError , RecordError } ;
48use linkerd_tls:: server:: DetectTimeout as TlsDetectTimeout ;
5- use std:: fmt;
9+ use parking_lot:: Mutex ;
10+ use std:: { collections:: HashMap , fmt} ;
611
7- metrics ! {
12+ metrics:: metrics ! {
813 inbound_tcp_accept_errors_total: Counter {
914 "The total number of inbound TCP connections that could not be processed due to a proxy error."
1015 } ,
@@ -15,9 +20,17 @@ metrics! {
1520}
1621
1722#[ derive( Clone , Debug ) ]
18- pub struct Registry ( linkerd_error_metrics:: Registry < AcceptErrors > ) ;
23+ pub struct Registry {
24+ scopes : metrics:: SharedStore < OrigDstAddr , Scope > ,
25+ metric : linkerd_error_metrics:: Metric ,
26+ }
27+
28+ type Scope = Mutex < HashMap < AcceptErrors , metrics:: Counter > > ;
29+
30+ type NewErrorMetrics < N , S > =
31+ metrics:: NewMetrics < N , OrigDstAddr , Scope , RecordError < LabelAcceptErrors , AcceptErrors , S > > ;
1932
20- #[ derive( Clone , Copy , Debug ) ]
33+ #[ derive( Clone , Copy , Debug , Default ) ]
2134pub struct LabelAcceptErrors ( ( ) ) ;
2235
2336#[ derive( Clone , Debug , Eq , PartialEq , Hash ) ]
@@ -27,32 +40,44 @@ pub enum AcceptErrors {
2740 Other ,
2841}
2942
30- pub type Layer = RecordErrorLayer < LabelAcceptErrors , AcceptErrors > ;
31-
3243// === impl Registry ===
3344
3445impl Registry {
3546 pub fn inbound ( ) -> Self {
36- Self ( linkerd_error_metrics:: Registry :: new (
37- inbound_tcp_accept_errors_total,
38- ) )
47+ Self {
48+ metric : inbound_tcp_accept_errors_total,
49+ scopes : Default :: default ( ) ,
50+ }
3951 }
4052
4153 pub fn outbound ( ) -> Self {
42- Self ( linkerd_error_metrics:: Registry :: new (
43- outbound_tcp_accept_errors_total,
44- ) )
54+ Self {
55+ metric : outbound_tcp_accept_errors_total,
56+ scopes : Default :: default ( ) ,
57+ }
4558 }
4659
47- pub fn layer ( & self ) -> Layer {
48- self . 0 . layer ( LabelAcceptErrors ( ( ) ) )
60+ pub fn layer < T , N : svc:: NewService < T > > (
61+ & self ,
62+ ) -> impl svc:: Layer < N , Service = NewErrorMetrics < N , N :: Service > > + Clone {
63+ metrics:: NewMetrics :: layer ( self . scopes . clone ( ) )
4964 }
5065}
5166
5267impl FmtMetrics for Registry {
53- #[ inline]
5468 fn fmt_metrics ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
55- self . 0 . fmt_metrics ( f)
69+ use metrics:: FmtMetric ;
70+ let errors = self . scopes . lock ( ) ;
71+
72+ self . metric . fmt_help ( f) ?;
73+ for ( OrigDstAddr ( a) , ms) in errors. iter ( ) {
74+ let ta = labels:: TargetAddr ( * a) ;
75+ for ( e, m) in ms. lock ( ) . iter ( ) {
76+ m. fmt_metric_labeled ( f, self . metric . name , ( ta, e) ) ?;
77+ }
78+ }
79+
80+ Ok ( ( ) )
5681 }
5782}
5883
0 commit comments