Skip to content

Commit

Permalink
feat: customize metric for personio use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-personio committed Sep 13, 2023
1 parent 9fa90df commit ffc96dc
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/linkerd2-proxy.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions linkerd/app/admin/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ impl Param<metrics::EndpointLabels> 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()
Expand Down
25 changes: 2 additions & 23 deletions linkerd/app/core/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -66,8 +65,6 @@ pub enum EndpointLabels {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct InboundEndpointLabels {
pub tls: tls::ConditionalServerTls,
pub authority: Option<http::uri::Authority>,
pub target_addr: SocketAddr,
pub policy: RouteAuthzLabels,
}

Expand Down Expand Up @@ -99,9 +96,7 @@ pub struct RouteAuthzLabels {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct OutboundEndpointLabels {
pub server_id: tls::ConditionalClientTls,
pub authority: Option<http::uri::Authority>,
pub labels: Option<String>,
pub target_addr: SocketAddr,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -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(())
}
}
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 0 additions & 2 deletions linkerd/app/inbound/src/http/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ impl Param<metrics::EndpointLabels> 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()
Expand Down
1 change: 0 additions & 1 deletion linkerd/app/integration/src/tests/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,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;
Expand Down
16 changes: 12 additions & 4 deletions linkerd/app/outbound/src/http/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -342,11 +342,19 @@ where
T: svc::Param<Option<http::uri::Authority>>,
{
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(),
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions linkerd/app/outbound/src/http/endpoint/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,8 @@ impl svc::Param<transport::labels::Key> for Endpoint {
impl svc::Param<metrics::OutboundEndpointLabels> for Endpoint {
fn param(&self) -> metrics::OutboundEndpointLabels {
metrics::OutboundEndpointLabels {
authority: None,
labels: None,
server_id: self.param(),
target_addr: self.addr.into(),
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions linkerd/app/outbound/src/opaq/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,9 @@ where
T: svc::Param<Option<profiles::LogicalAddr>>,
{
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(),
}
}
}
Expand Down

0 comments on commit ffc96dc

Please sign in to comment.