From 96328698aefcbc9cded1f122f7f2cb44075327c7 Mon Sep 17 00:00:00 2001 From: Bruce Chen Date: Tue, 12 Sep 2023 14:23:46 +0200 Subject: [PATCH] feat: customize metric for personio use cases --- .github/workflows/release.yml | 2 +- .idea/.gitignore | 8 ++++++ .idea/linkerd2-proxy.iml | 9 +++++++ .idea/modules.xml | 8 ++++++ .idea/php.xml | 12 +++++++++ .idea/vcs.xml | 6 +++++ linkerd/app/admin/src/stack.rs | 2 -- linkerd/app/core/src/metrics.rs | 25 ++----------------- linkerd/app/inbound/src/http/router.rs | 2 -- .../app/integration/src/tests/discovery.rs | 2 -- linkerd/app/outbound/src/http/concrete.rs | 16 +++++++++--- .../app/outbound/src/http/endpoint/tests.rs | 2 -- linkerd/app/outbound/src/opaq/concrete.rs | 7 ------ 13 files changed, 58 insertions(+), 43 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/linkerd2-proxy.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 468fd46c80..5d6434bfee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ env: CARGO_NET_RETRY: 10 CHECKSEC_VERSION: 2.5.0 RUSTFLAGS: "-D warnings -A deprecated" - RUSTUP_MAX_RETRIES: 10 + RUSTUP_MAX_RETRIES: 11 jobs: meta: diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..13566b81b0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/linkerd2-proxy.iml b/.idea/linkerd2-proxy.iml new file mode 100644 index 0000000000..d6ebd48059 --- /dev/null +++ b/.idea/linkerd2-proxy.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..a38bd29c15 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000000..f5f27444bd --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..35eb1ddfbb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/linkerd/app/admin/src/stack.rs b/linkerd/app/admin/src/stack.rs index 571f8915e0..1e28ae0295 100644 --- a/linkerd/app/admin/src/stack.rs +++ b/linkerd/app/admin/src/stack.rs @@ -225,8 +225,6 @@ impl Param for Permitted { fn param(&self) -> metrics::EndpointLabels { metrics::InboundEndpointLabels { tls: self.http.tcp.tls.clone(), - authority: None, - target_addr: self.http.tcp.addr.into(), policy: self.permit.labels.clone(), } .into() diff --git a/linkerd/app/core/src/metrics.rs b/linkerd/app/core/src/metrics.rs index baee0aa785..5f937ea836 100644 --- a/linkerd/app/core/src/metrics.rs +++ b/linkerd/app/core/src/metrics.rs @@ -19,7 +19,6 @@ pub use linkerd_metrics::*; use linkerd_proxy_server_policy as policy; use std::{ fmt::{self, Write}, - net::SocketAddr, sync::Arc, time::Duration, }; @@ -66,8 +65,6 @@ pub enum EndpointLabels { #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct InboundEndpointLabels { pub tls: tls::ConditionalServerTls, - pub authority: Option, - pub target_addr: SocketAddr, pub policy: RouteAuthzLabels, } @@ -99,9 +96,7 @@ pub struct RouteAuthzLabels { #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct OutboundEndpointLabels { pub server_id: tls::ConditionalClientTls, - pub authority: Option, pub labels: Option, - pub target_addr: SocketAddr, } #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -300,17 +295,7 @@ impl FmtLabels for EndpointLabels { impl FmtLabels for InboundEndpointLabels { fn fmt_labels(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if let Some(a) = self.authority.as_ref() { - Authority(a).fmt_labels(f)?; - write!(f, ",")?; - } - - ( - (TargetAddr(self.target_addr), TlsAccept::from(&self.tls)), - &self.policy, - ) - .fmt_labels(f)?; - + ((TlsAccept::from(&self.tls)), &self.policy).fmt_labels(f)?; Ok(()) } } @@ -368,14 +353,8 @@ impl FmtLabels for RouteAuthzLabels { impl FmtLabels for OutboundEndpointLabels { fn fmt_labels(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if let Some(a) = self.authority.as_ref() { - Authority(a).fmt_labels(f)?; - write!(f, ",")?; - } - - let ta = TargetAddr(self.target_addr); let tls = TlsConnect::from(&self.server_id); - (ta, tls).fmt_labels(f)?; + (tls).fmt_labels(f)?; if let Some(labels) = self.labels.as_ref() { write!(f, ",{}", labels)?; diff --git a/linkerd/app/inbound/src/http/router.rs b/linkerd/app/inbound/src/http/router.rs index 9e895e04f9..0a2e22f774 100644 --- a/linkerd/app/inbound/src/http/router.rs +++ b/linkerd/app/inbound/src/http/router.rs @@ -406,8 +406,6 @@ impl Param for Logical { fn param(&self) -> metrics::EndpointLabels { metrics::InboundEndpointLabels { tls: self.tls.clone(), - authority: self.logical.as_ref().map(|d| d.as_http_authority()), - target_addr: self.addr.into(), policy: self.permit.labels.clone(), } .into() diff --git a/linkerd/app/integration/src/tests/discovery.rs b/linkerd/app/integration/src/tests/discovery.rs index 6ea36b57c2..ec25afad22 100644 --- a/linkerd/app/integration/src/tests/discovery.rs +++ b/linkerd/app/integration/src/tests/discovery.rs @@ -438,7 +438,6 @@ mod http2 { .route("/bye", "bye") .run() .await; - let srv1_addr = srv1.addr; // Start with the first server. let dstctl = controller::new(); @@ -465,7 +464,6 @@ mod http2 { metrics::metric("tcp_close_total") .label("peer", "dst") .label("direction", "outbound") - .label("target_addr", srv1_addr.to_string()) .value(1u64) .assert_in(&metrics) .await; diff --git a/linkerd/app/outbound/src/http/concrete.rs b/linkerd/app/outbound/src/http/concrete.rs index e690530f6e..c85a48bc65 100644 --- a/linkerd/app/outbound/src/http/concrete.rs +++ b/linkerd/app/outbound/src/http/concrete.rs @@ -18,7 +18,7 @@ use linkerd_app_core::{ Error, Infallible, NameAddr, }; use linkerd_proxy_client_policy::FailureAccrual; -use std::{fmt::Debug, net::SocketAddr, sync::Arc}; +use std::{collections::BTreeMap, fmt::Debug, net::SocketAddr, sync::Arc}; use tracing::info_span; mod metrics; @@ -342,11 +342,19 @@ where T: svc::Param>, { fn param(&self) -> OutboundEndpointLabels { + // self.metadata.labels() could return Err in some cases + // if that case the dst_labels won't carry any value + let mut dst_labels = match Arc::try_unwrap(self.metadata.labels()) { + Ok(result) => result, + Err(_e) => BTreeMap::new(), + }; + + dst_labels.remove("pod"); + dst_labels.remove("pod_template_hash"); + OutboundEndpointLabels { - authority: self.parent.param(), - labels: prefix_labels("dst", self.metadata.labels().iter()), + labels: prefix_labels("dst", dst_labels.iter()), server_id: self.param(), - target_addr: self.addr.into(), } } } diff --git a/linkerd/app/outbound/src/http/endpoint/tests.rs b/linkerd/app/outbound/src/http/endpoint/tests.rs index 461ea2e913..e9d77191e1 100644 --- a/linkerd/app/outbound/src/http/endpoint/tests.rs +++ b/linkerd/app/outbound/src/http/endpoint/tests.rs @@ -289,10 +289,8 @@ impl svc::Param for Endpoint { impl svc::Param for Endpoint { fn param(&self) -> metrics::OutboundEndpointLabels { metrics::OutboundEndpointLabels { - authority: None, labels: None, server_id: self.param(), - target_addr: self.addr.into(), } } } diff --git a/linkerd/app/outbound/src/opaq/concrete.rs b/linkerd/app/outbound/src/opaq/concrete.rs index c71bc67b85..ba98fa1e63 100644 --- a/linkerd/app/outbound/src/opaq/concrete.rs +++ b/linkerd/app/outbound/src/opaq/concrete.rs @@ -246,16 +246,9 @@ where T: svc::Param>, { fn param(&self) -> metrics::OutboundEndpointLabels { - let authority = self - .parent - .param() - .as_ref() - .map(|profiles::LogicalAddr(a)| a.as_http_authority()); metrics::OutboundEndpointLabels { - authority, labels: metrics::prefix_labels("dst", self.metadata.labels().iter()), server_id: self.param(), - target_addr: self.addr.into(), } } }