11use crate :: proxy:: identity;
22use futures:: { Async , Poll } ;
33use http:: { header:: HeaderValue , StatusCode } ;
4+ use linkerd2_errno:: Errno ;
45use linkerd2_error:: Error ;
56use linkerd2_error_metrics as metrics;
67use linkerd2_error_respond as respond;
@@ -30,6 +31,7 @@ pub enum Reason {
3031 DispatchTimeout ,
3132 ResponseTimeout ,
3233 IdentityRequired ,
34+ Io ( Option < Errno > ) ,
3335 FailFast ,
3436 Unexpected ,
3537}
@@ -295,23 +297,31 @@ impl std::fmt::Display for IdentityRequired {
295297
296298impl std:: error:: Error for IdentityRequired { }
297299
298- impl metrics:: LabelError < Error > for LabelError {
299- type Labels = Label ;
300-
301- fn label_error ( & self , err : & Error ) -> Self :: Labels {
302- let reason = if err. is :: < ResponseTimeout > ( ) {
300+ impl LabelError {
301+ fn reason ( err : & ( dyn std:: error:: Error + ' static ) ) -> Reason {
302+ if err. is :: < ResponseTimeout > ( ) {
303303 Reason :: ResponseTimeout
304304 } else if err. is :: < FailFastError > ( ) {
305305 Reason :: FailFast
306306 } else if err. is :: < tower:: timeout:: error:: Elapsed > ( ) {
307307 Reason :: DispatchTimeout
308308 } else if err. is :: < IdentityRequired > ( ) {
309309 Reason :: IdentityRequired
310+ } else if let Some ( e) = err. downcast_ref :: < std:: io:: Error > ( ) {
311+ Reason :: Io ( e. raw_os_error ( ) . map ( Errno :: from) )
312+ } else if let Some ( e) = err. source ( ) {
313+ Self :: reason ( e)
310314 } else {
311315 Reason :: Unexpected
312- } ;
316+ }
317+ }
318+ }
313319
314- ( self . 0 , reason)
320+ impl metrics:: LabelError < Error > for LabelError {
321+ type Labels = Label ;
322+
323+ fn label_error ( & self , err : & Error ) -> Self :: Labels {
324+ ( self . 0 , Self :: reason ( err. as_ref ( ) ) )
315325 }
316326}
317327
@@ -325,9 +335,16 @@ impl metrics::FmtLabels for Reason {
325335 Reason :: DispatchTimeout => "dispatch timeout" ,
326336 Reason :: ResponseTimeout => "response timeout" ,
327337 Reason :: IdentityRequired => "identity required" ,
338+ Reason :: Io ( _) => "i/o" ,
328339 Reason :: Unexpected => "unexpected" ,
329340 }
330- )
341+ ) ?;
342+
343+ if let Reason :: Io ( Some ( errno) ) = self {
344+ write ! ( f, ",errno=\" {}\" " , errno) ?;
345+ }
346+
347+ Ok ( ( ) )
331348 }
332349}
333350
0 commit comments