Skip to content

Commit 6393c83

Browse files
authored
Add tracing spans to controller clients (#1288)
It can be difficult to identify when log messages are emitted from controller clients. This change adds tracing spans to identify the client and its endpoints.
1 parent 04992e9 commit 6393c83

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

linkerd/app/core/src/control.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,23 @@ impl fmt::Display for ControlAddr {
3636
type BalanceBody =
3737
http::balance::PendingUntilFirstDataBody<tower::load::peak_ewma::Handle, hyper::Body>;
3838

39-
type RspBody = linkerd_http_metrics::requests::ResponseBody<BalanceBody, classify::Eos>;
40-
41-
pub type Client = svc::Buffer<http::Request<tonic::body::BoxBody>, http::Response<RspBody>, Error>;
39+
pub type RspBody = linkerd_http_metrics::requests::ResponseBody<BalanceBody, classify::Eos>;
4240

4341
impl Config {
4442
pub fn build<L>(
4543
self,
4644
dns: dns::Resolver,
4745
metrics: metrics::ControlHttp,
4846
identity: Option<L>,
49-
) -> svc::ArcNewService<(), Client>
47+
) -> svc::ArcNewService<
48+
(),
49+
impl svc::Service<
50+
http::Request<tonic::body::BoxBody>,
51+
Response = http::Response<RspBody>,
52+
Error = Error,
53+
Future = impl Send,
54+
> + Clone,
55+
>
5056
where
5157
L: Clone + svc::Param<tls::client::Config> + Send + Sync + 'static,
5258
{
@@ -87,12 +93,14 @@ impl Config {
8793
// Ensure individual endpoints are driven to readiness so that the balancer need not
8894
// drive them all directly.
8995
.push_on_service(svc::layer::mk(svc::SpawnReady::new))
96+
.instrument(|t: &self::client::Target| tracing::info_span!("endpoint", addr = %t.addr))
9097
.push(self::resolve::layer(dns, resolve_backoff))
9198
.push_on_service(self::control::balance::layer())
9299
.into_new_service()
93100
.push(metrics.to_layer::<classify::Response, _, _>())
94101
.push(self::add_origin::layer())
95102
.push_on_service(svc::layers().push_spawn_buffer(self.buffer_capacity))
103+
.instrument(|c: &ControlAddr| tracing::info_span!("controller", addr = %c.addr))
96104
.push_map_target(move |()| addr.clone())
97105
.push(svc::ArcNewService::layer())
98106
.into_inner()
@@ -238,7 +246,7 @@ mod client {
238246

239247
#[derive(Clone, Hash, Debug, Eq, PartialEq)]
240248
pub struct Target {
241-
addr: SocketAddr,
249+
pub(super) addr: SocketAddr,
242250
server_id: tls::ConditionalClientTls,
243251
}
244252

linkerd/app/src/dst.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use linkerd_app_core::{
33
exp_backoff::{ExponentialBackoff, ExponentialBackoffStream},
44
metrics,
55
profiles::{self, DiscoveryRejected},
6-
proxy::{api_resolve as api, identity::LocalCrtKey, resolve::recover},
7-
svc::NewService,
6+
proxy::{api_resolve as api, http, identity::LocalCrtKey, resolve::recover},
7+
svc::{self, NewService},
88
Error, Recover,
99
};
1010

@@ -15,15 +15,15 @@ pub struct Config {
1515
}
1616

1717
/// Handles to destination service clients.
18-
pub struct Dst {
18+
pub struct Dst<S> {
1919
/// The address of the destination service, used for logging.
2020
pub addr: control::ControlAddr,
2121

2222
/// Resolves profiles.
23-
pub profiles: profiles::Client<BackoffUnlessInvalidArgument, control::Client>,
23+
pub profiles: profiles::Client<BackoffUnlessInvalidArgument, S>,
2424

2525
/// Resolves endpoints.
26-
pub resolve: recover::Resolve<BackoffUnlessInvalidArgument, api::Resolve<control::Client>>,
26+
pub resolve: recover::Resolve<BackoffUnlessInvalidArgument, api::Resolve<S>>,
2727
}
2828

2929
#[derive(Copy, Clone, Debug, Default)]
@@ -37,7 +37,17 @@ impl Config {
3737
dns: dns::Resolver,
3838
metrics: metrics::ControlHttp,
3939
identity: Option<LocalCrtKey>,
40-
) -> Result<Dst, Error> {
40+
) -> Result<
41+
Dst<
42+
impl svc::Service<
43+
http::Request<tonic::body::BoxBody>,
44+
Response = http::Response<control::RspBody>,
45+
Error = Error,
46+
Future = impl Send,
47+
> + Clone,
48+
>,
49+
Error,
50+
> {
4151
let addr = self.control.addr.clone();
4252
let backoff = BackoffUnlessInvalidArgument(self.control.connect.backoff);
4353
let svc = self.control.build(dns, metrics, identity).new_service(());

0 commit comments

Comments
 (0)