Skip to content

Commit

Permalink
feat(app): Route frame count metrics
Browse files Browse the repository at this point in the history
 ### ⛅ overview

this introduces a new tower middleware for Prometheus metrics, used for
instrumenting HTTP and gRPC request bodies, and observing (a) the
number of frames yielded by a body, and (b) the number of bytes included
in body frames.

this builds upon the backend-level metrics added in #3308. this
additionally uses the route label extractor, hoisted out of the retry
middleware's Prometheus telemetry in #3337.

 ### 📝 changes

* a `linkerd_http_prom::body_data::request::NewRecordBodyData::NewRecordBodyData`
  middleware is added, which complements the equivalent
  `linkerd_http_prom::body_data::response` middleware.

* this is added

Signed-off-by: katelyn martin <[email protected]>
  • Loading branch information
cratelyn committed Nov 10, 2024
1 parent a75492c commit 3ae2592
Show file tree
Hide file tree
Showing 5 changed files with 430 additions and 29 deletions.
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>(
#[derive(Clone, Debug)]
pub struct ExtractRecordBodyDataParams(RequestBodyFamilies<labels::Route>);

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::layers().push(record).push(body_data)
}

// === 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

0 comments on commit 3ae2592

Please sign in to comment.