Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion linkerd/app/outbound/src/http/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct DispatcherFailed(Arc<str>);

/// Wraps errors encountered in this module.
#[derive(Debug, thiserror::Error)]
#[error("{} {}.{}: {source}", backend.0.kind(), backend.0.name(), backend.0.namespace())]
#[error("{}: {source}", backend.0)]
pub struct BalanceError {
backend: BackendRef,
#[source]
Expand Down
18 changes: 18 additions & 0 deletions linkerd/app/outbound/src/http/logical/policy/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ pub(crate) type Grpc<T> = MatchedRoute<
pub(crate) type BackendDistribution<T, F> = distribute::Distribution<Backend<T, F>>;
pub(crate) type NewDistribute<T, F, N> = distribute::NewDistribute<Backend<T, F>, (), N>;

/// Wraps errors with route metadata.
#[derive(Debug, thiserror::Error)]
#[error("route {}: {source}", route.0)]
struct RouteError {
route: RouteRef,
#[source]
source: Error,
}

// === impl MatchedRoute ===

impl<T, M, F, E> MatchedRoute<T, M, F, E>
Expand Down Expand Up @@ -115,6 +124,15 @@ where
// Sets an optional request timeout.
.push(http::NewTimeout::layer())
.push(classify::NewClassify::layer())
.push(svc::NewMapErr::layer_with(|rt: &Self| {
let route = rt.params.route_ref.clone();
move |source| {
Error::from(RouteError {
route: route.clone(),
source,
})
}
}))
.push(svc::ArcNewService::layer())
.into_inner()
})
Expand Down
20 changes: 19 additions & 1 deletion linkerd/app/outbound/src/http/logical/policy/route/backend.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{super::Concrete, filters};
use crate::RouteRef;
use crate::{BackendRef, RouteRef};
use linkerd_app_core::{proxy::http, svc, Error, Result};
use linkerd_http_route as http_route;
use linkerd_proxy_client_policy as policy;
Expand Down Expand Up @@ -29,6 +29,15 @@ pub struct ExtractMetrics {
metrics: RouteBackendMetrics,
}

/// Wraps errors with backend metadata.
#[derive(Debug, thiserror::Error)]
#[error("backend {}: {source}", backend.0)]
struct BackendError {
backend: BackendRef,
#[source]
source: Error,
}

// === impl Backend ===

impl<T: Clone, F> Clone for Backend<T, F> {
Expand Down Expand Up @@ -110,6 +119,15 @@ where
.push(count_reqs::NewCountRequests::layer_via(ExtractMetrics {
metrics: metrics.clone(),
}))
.push(svc::NewMapErr::layer_with(|t: &Self| {
let backend = t.params.concrete.backend_ref.clone();
move |source| {
Error::from(BackendError {
backend: backend.clone(),
source,
})
}
}))
.push(svc::ArcNewService::layer())
.into_inner()
})
Expand Down
23 changes: 22 additions & 1 deletion linkerd/proxy/client-policy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![forbid(unsafe_code)]

use once_cell::sync::Lazy;
use std::{borrow::Cow, hash::Hash, net::SocketAddr, num::NonZeroU16, sync::Arc, time};
use std::{borrow::Cow, fmt, hash::Hash, net::SocketAddr, num::NonZeroU16, sync::Arc, time};

pub mod grpc;
pub mod http;
Expand Down Expand Up @@ -264,6 +264,27 @@ impl std::hash::Hash for Meta {
}
}

impl fmt::Display for Meta {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Default { name } => write!(f, "default.{name}"),
Self::Resource {
kind,
name,
namespace,
port,
..
} => {
write!(f, "{kind}.{namespace}.{name}")?;
if let Some(port) = port {
write!(f, ":{port}")?
}
Ok(())
}
}
}
}

// === impl FailureAccrual ===

impl Default for FailureAccrual {
Expand Down