From 41152e8a2d10f532a24564913e0fbd3d77381996 Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Tue, 15 Dec 2020 17:47:01 +0000 Subject: [PATCH] Add a protocol label to stack metrics 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. --- linkerd/app/core/src/metrics.rs | 13 ++++++++----- linkerd/app/inbound/src/lib.rs | 8 ++++---- linkerd/app/outbound/src/http/logical.rs | 8 ++++++-- linkerd/app/outbound/src/ingress.rs | 2 +- linkerd/app/outbound/src/lib.rs | 4 ++-- linkerd/app/outbound/src/server.rs | 4 +++- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/linkerd/app/core/src/metrics.rs b/linkerd/app/core/src/metrics.rs index 39d57a8d44..b8f3605745 100644 --- a/linkerd/app/core/src/metrics.rs +++ b/linkerd/app/core/src/metrics.rs @@ -56,6 +56,7 @@ pub struct EndpointLabels { #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct StackLabels { pub direction: Direction, + pub protocol: &'static str, pub name: &'static str, } @@ -297,17 +298,19 @@ impl FmtLabels for TlsId { // === impl StackLabels === impl StackLabels { - pub fn inbound(name: &'static str) -> Self { + pub fn inbound(protocol: &'static str, name: &'static str) -> Self { Self { - direction: Direction::In, name, + protocol, + direction: Direction::In, } } - pub fn outbound(name: &'static str) -> Self { + pub fn outbound(protocol: &'static str, name: &'static str) -> Self { Self { - direction: Direction::Out, name, + protocol, + direction: Direction::Out, } } } @@ -315,6 +318,6 @@ impl StackLabels { impl FmtLabels for StackLabels { fn fmt_labels(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.direction.fmt_labels(f)?; - write!(f, ",name=\"{}\"", self.name) + write!(f, ",protocol=\"{}\",name=\"{}\"", self.protocol, self.name) } } diff --git a/linkerd/app/inbound/src/lib.rs b/linkerd/app/inbound/src/lib.rs index 7a397bdfdc..09d3ff05db 100644 --- a/linkerd/app/inbound/src/lib.rs +++ b/linkerd/app/inbound/src/lib.rs @@ -280,7 +280,7 @@ impl Config { svc::layers() .push_failfast(dispatch_timeout) .push_spawn_buffer(buffer_capacity) - .push(metrics.stack.layer(stack_labels("logical"))), + .push(metrics.stack.layer(stack_labels("http", "logical"))), ) .push_cache(cache_max_idle_age) .push_on_response( @@ -371,7 +371,7 @@ impl Config { .push(TraceContext::layer(span_sink.map(|span_sink| { SpanConverter::server(span_sink, trace_labels()) }))) - .push(metrics.stack.layer(stack_labels("source"))) + .push(metrics.stack.layer(stack_labels("http", "server"))) .box_http_request() .box_http_response(), ) @@ -458,8 +458,8 @@ pub fn trace_labels() -> HashMap { l } -fn stack_labels(name: &'static str) -> metrics::StackLabels { - metrics::StackLabels::inbound(name) +fn stack_labels(proto: &'static str, name: &'static str) -> metrics::StackLabels { + metrics::StackLabels::inbound(proto, name) } // === impl SkipByPort === diff --git a/linkerd/app/outbound/src/http/logical.rs b/linkerd/app/outbound/src/http/logical.rs index 23cf19d65d..f8053ec20a 100644 --- a/linkerd/app/outbound/src/http/logical.rs +++ b/linkerd/app/outbound/src/http/logical.rs @@ -55,7 +55,11 @@ where .push_on_response( svc::layers() .push(svc::layer::mk(svc::SpawnReady::new)) - .push(metrics.stack.layer(stack_labels("balance.endpoint"))) + .push( + metrics + .stack + .layer(stack_labels("http", "balance.endpoint")), + ) .box_http_request(), ) .check_new_service::>() @@ -71,7 +75,7 @@ where // If the balancer has been empty/unavailable for 10s, eagerly fail // requests. .push_failfast(dispatch_timeout) - .push(metrics.stack.layer(stack_labels("concrete"))), + .push(metrics.stack.layer(stack_labels("http", "concrete"))), ) .into_new_service() .check_new_service::>() diff --git a/linkerd/app/outbound/src/ingress.rs b/linkerd/app/outbound/src/ingress.rs index bfd89d047b..c809fcafb7 100644 --- a/linkerd/app/outbound/src/ingress.rs +++ b/linkerd/app/outbound/src/ingress.rs @@ -110,7 +110,7 @@ where .push(TraceContext::layer(span_sink.clone().map(|span_sink| { SpanConverter::server(span_sink, trace_labels()) }))) - .push(metrics.stack.layer(stack_labels("source"))) + .push(metrics.stack.layer(stack_labels("http", "server"))) .push_failfast(dispatch_timeout) .push_spawn_buffer(buffer_capacity) .box_http_response(), diff --git a/linkerd/app/outbound/src/lib.rs b/linkerd/app/outbound/src/lib.rs index c4135975ef..acdbcb64c8 100644 --- a/linkerd/app/outbound/src/lib.rs +++ b/linkerd/app/outbound/src/lib.rs @@ -26,8 +26,8 @@ pub struct Config { pub allow_discovery: AddrMatch, } -fn stack_labels(name: &'static str) -> metrics::StackLabels { - metrics::StackLabels::outbound(name) +fn stack_labels(proto: &'static str, name: &'static str) -> metrics::StackLabels { + metrics::StackLabels::outbound(proto, name) } pub fn trace_labels() -> HashMap { diff --git a/linkerd/app/outbound/src/server.rs b/linkerd/app/outbound/src/server.rs index 661e1703d4..792815a020 100644 --- a/linkerd/app/outbound/src/server.rs +++ b/linkerd/app/outbound/src/server.rs @@ -176,7 +176,7 @@ where .push(TraceContext::layer(span_sink.clone().map(|span_sink| { SpanConverter::server(span_sink, trace_labels()) }))) - .push(metrics.stack.layer(stack_labels("source"))) + .push(metrics.stack.layer(stack_labels("http", "server"))) .push_failfast(dispatch_timeout) .push_spawn_buffer(buffer_capacity) .box_http_response(), @@ -193,6 +193,7 @@ where .check_make_service::() .push_on_response(svc::layer::mk(tcp::Forward::new)) .into_new_service() + .push_on_response(metrics.stack.layer(stack_labels("tcp", "forward"))) .check_new_service::>>() .push_map_target(tcp::Endpoint::from_logical( tls::ReasonForNoPeerName::NotProvidedByServiceDiscovery, @@ -235,6 +236,7 @@ where .push_map_target(tcp::Endpoint::from_logical( tls::ReasonForNoPeerName::PortSkipped, )) + .push_on_response(metrics.stack.layer(stack_labels("tcp", "opaque"))) .check_new_service::>() .into_inner();