Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): Route frame count metrics #3334

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion linkerd/app/outbound/src/http/logical/policy/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ where
// Set request extensions based on the route configuration
// AND/OR headers
.push(extensions::NewSetExtensions::layer())
.push(metrics::layer(&metrics.requests))
.push(metrics::layer(
&metrics.requests,
Self::label_extractor,
&metrics.body_data,
))
.check_new::<Self>()
.check_new_service::<Self, http::Request<http::BoxBody>>()
// Configure a classifier to use in the endpoint stack.
Expand Down
33 changes: 29 additions & 4 deletions linkerd/app/outbound/src/http/logical/policy/route/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use linkerd_app_core::{
metrics::prom::{self, EncodeLabelSetMut},
svc,
};
use linkerd_http_prom::record_response::{self, StreamLabel};
use linkerd_http_prom::{
body_data::request::{NewRecordBodyData, RequestBodyFamilies},
record_response::{self, StreamLabel},
};

pub use linkerd_http_prom::record_response::MkStreamLabel;

Expand All @@ -23,6 +26,7 @@ pub struct RouteMetrics<R: StreamLabel, B: StreamLabel> {
pub(super) retry: retry::RouteRetryMetrics,
pub(super) requests: RequestMetrics<R>,
pub(super) backend: backend::RouteBackendMetrics<B>,
pub(super) body_data: RequestBodyFamilies<labels::Route>,
}

pub type HttpRouteMetrics = RouteMetrics<LabelHttpRouteRsp, LabelHttpRouteBackendRsp>;
Expand Down Expand Up @@ -56,13 +60,30 @@ pub type NewRecordDuration<T, M, N> =
#[derive(Clone, Debug)]
pub struct ExtractRecordDurationParams<M>(pub M);

pub fn layer<T, N>(
pub fn layer<T, N, X>(
metrics: &RequestMetrics<T::StreamLabel>,
) -> impl svc::Layer<N, Service = NewRecordDuration<T, RequestMetrics<T::StreamLabel>, N>> + Clone
mk: X,
body_data: &RequestBodyFamilies<labels::Route>,
) -> impl svc::Layer<
N,
Service = NewRecordBodyData<
NewRecordDuration<T, RequestMetrics<T::StreamLabel>, N>,
X,
labels::RouteLabelExtract,
labels::Route,
>,
>
where
T: Clone + MkStreamLabel,
X: Clone,
{
NewRecordDuration::layer_via(ExtractRecordDurationParams(metrics.clone()))
let record = NewRecordDuration::layer_via(ExtractRecordDurationParams(metrics.clone()));
let body_data = NewRecordBodyData::new(mk, body_data.clone());

svc::layer::mk(move |inner| {
use svc::Layer;
body_data.layer(record.layer(inner))
})
}

// === impl RouteMetrics ===
Expand All @@ -89,6 +110,7 @@ impl<R: StreamLabel, B: StreamLabel> Default for RouteMetrics<R, B> {
requests: Default::default(),
backend: Default::default(),
retry: Default::default(),
body_data: Default::default(),
}
}
}
Expand All @@ -99,6 +121,7 @@ impl<R: StreamLabel, B: StreamLabel> Clone for RouteMetrics<R, B> {
requests: self.requests.clone(),
backend: self.backend.clone(),
retry: self.retry.clone(),
body_data: self.body_data.clone(),
}
}
}
Expand All @@ -113,11 +136,13 @@ impl<R: StreamLabel, B: StreamLabel> RouteMetrics<R, B> {
);

let retry = retry::RouteRetryMetrics::register(reg.sub_registry_with_prefix("retry"));
let body_data = RequestBodyFamilies::register(reg);

Self {
requests,
backend,
retry,
body_data,
}
}

Expand Down
Loading
Loading