Skip to content

Commit 147908f

Browse files
authored
Add a protocol label to stack metrics (#773)
Now that TCP stacks are getting more complex, it's worth differentiating them with a protocol label. This change also renames 'source' stacks to 'server' stacks.
1 parent 8794cc6 commit 147908f

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

linkerd/app/core/src/metrics.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct EndpointLabels {
5656
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
5757
pub struct StackLabels {
5858
pub direction: Direction,
59+
pub protocol: &'static str,
5960
pub name: &'static str,
6061
}
6162

@@ -297,24 +298,26 @@ impl FmtLabels for TlsId {
297298
// === impl StackLabels ===
298299

299300
impl StackLabels {
300-
pub fn inbound(name: &'static str) -> Self {
301+
pub fn inbound(protocol: &'static str, name: &'static str) -> Self {
301302
Self {
302-
direction: Direction::In,
303303
name,
304+
protocol,
305+
direction: Direction::In,
304306
}
305307
}
306308

307-
pub fn outbound(name: &'static str) -> Self {
309+
pub fn outbound(protocol: &'static str, name: &'static str) -> Self {
308310
Self {
309-
direction: Direction::Out,
310311
name,
312+
protocol,
313+
direction: Direction::Out,
311314
}
312315
}
313316
}
314317

315318
impl FmtLabels for StackLabels {
316319
fn fmt_labels(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
317320
self.direction.fmt_labels(f)?;
318-
write!(f, ",name=\"{}\"", self.name)
321+
write!(f, ",protocol=\"{}\",name=\"{}\"", self.protocol, self.name)
319322
}
320323
}

linkerd/app/inbound/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl Config {
280280
svc::layers()
281281
.push_failfast(dispatch_timeout)
282282
.push_spawn_buffer(buffer_capacity)
283-
.push(metrics.stack.layer(stack_labels("logical"))),
283+
.push(metrics.stack.layer(stack_labels("http", "logical"))),
284284
)
285285
.push_cache(cache_max_idle_age)
286286
.push_on_response(
@@ -371,7 +371,7 @@ impl Config {
371371
.push(TraceContext::layer(span_sink.map(|span_sink| {
372372
SpanConverter::server(span_sink, trace_labels())
373373
})))
374-
.push(metrics.stack.layer(stack_labels("source")))
374+
.push(metrics.stack.layer(stack_labels("http", "server")))
375375
.box_http_request()
376376
.box_http_response(),
377377
)
@@ -458,8 +458,8 @@ pub fn trace_labels() -> HashMap<String, String> {
458458
l
459459
}
460460

461-
fn stack_labels(name: &'static str) -> metrics::StackLabels {
462-
metrics::StackLabels::inbound(name)
461+
fn stack_labels(proto: &'static str, name: &'static str) -> metrics::StackLabels {
462+
metrics::StackLabels::inbound(proto, name)
463463
}
464464

465465
// === impl SkipByPort ===

linkerd/app/outbound/src/http/logical.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ where
5555
.push_on_response(
5656
svc::layers()
5757
.push(svc::layer::mk(svc::SpawnReady::new))
58-
.push(metrics.stack.layer(stack_labels("balance.endpoint")))
58+
.push(
59+
metrics
60+
.stack
61+
.layer(stack_labels("http", "balance.endpoint")),
62+
)
5963
.box_http_request(),
6064
)
6165
.check_new_service::<Endpoint, http::Request<_>>()
@@ -71,7 +75,7 @@ where
7175
// If the balancer has been empty/unavailable for 10s, eagerly fail
7276
// requests.
7377
.push_failfast(dispatch_timeout)
74-
.push(metrics.stack.layer(stack_labels("concrete"))),
78+
.push(metrics.stack.layer(stack_labels("http", "concrete"))),
7579
)
7680
.into_new_service()
7781
.check_new_service::<Concrete, http::Request<_>>()

linkerd/app/outbound/src/ingress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ where
110110
.push(TraceContext::layer(span_sink.clone().map(|span_sink| {
111111
SpanConverter::server(span_sink, trace_labels())
112112
})))
113-
.push(metrics.stack.layer(stack_labels("source")))
113+
.push(metrics.stack.layer(stack_labels("http", "server")))
114114
.push_failfast(dispatch_timeout)
115115
.push_spawn_buffer(buffer_capacity)
116116
.box_http_response(),

linkerd/app/outbound/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub struct Config {
2626
pub allow_discovery: AddrMatch,
2727
}
2828

29-
fn stack_labels(name: &'static str) -> metrics::StackLabels {
30-
metrics::StackLabels::outbound(name)
29+
fn stack_labels(proto: &'static str, name: &'static str) -> metrics::StackLabels {
30+
metrics::StackLabels::outbound(proto, name)
3131
}
3232

3333
pub fn trace_labels() -> HashMap<String, String> {

linkerd/app/outbound/src/server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ where
176176
.push(TraceContext::layer(span_sink.clone().map(|span_sink| {
177177
SpanConverter::server(span_sink, trace_labels())
178178
})))
179-
.push(metrics.stack.layer(stack_labels("source")))
179+
.push(metrics.stack.layer(stack_labels("http", "server")))
180180
.push_failfast(dispatch_timeout)
181181
.push_spawn_buffer(buffer_capacity)
182182
.box_http_response(),
@@ -193,6 +193,7 @@ where
193193
.check_make_service::<tcp::Endpoint, ()>()
194194
.push_on_response(svc::layer::mk(tcp::Forward::new))
195195
.into_new_service()
196+
.push_on_response(metrics.stack.layer(stack_labels("tcp", "forward")))
196197
.check_new_service::<tcp::Endpoint, transport::io::PrefixedIo<transport::metrics::SensorIo<I>>>()
197198
.push_map_target(tcp::Endpoint::from_logical(
198199
tls::ReasonForNoPeerName::NotProvidedByServiceDiscovery,
@@ -235,6 +236,7 @@ where
235236
.push_map_target(tcp::Endpoint::from_logical(
236237
tls::ReasonForNoPeerName::PortSkipped,
237238
))
239+
.push_on_response(metrics.stack.layer(stack_labels("tcp", "opaque")))
238240
.check_new_service::<tcp::Logical, transport::metrics::SensorIo<I>>()
239241
.into_inner();
240242

0 commit comments

Comments
 (0)