From df29960f472d7c69916e2f51ebb1d1018408f350 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Fri, 1 Nov 2024 00:00:00 +0000 Subject: [PATCH 1/2] refactor(app): Simplify backend metrics layer bounds this commit changes the backend-level metrics layer function, so that it invokes `linkerd_app_core::svc::layers()` rather than `linkerd_app_core::svc::layer::mk()`. this has a nice effect in that it simplifies the bounds of the `layer` function. Signed-off-by: katelyn martin --- .../logical/policy/route/backend/metrics.rs | 32 ++++++------------- linkerd/http/prom/src/body_data/response.rs | 2 +- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/linkerd/app/outbound/src/http/logical/policy/route/backend/metrics.rs b/linkerd/app/outbound/src/http/logical/policy/route/backend/metrics.rs index af15735757..8854a1cd66 100644 --- a/linkerd/app/outbound/src/http/logical/policy/route/backend/metrics.rs +++ b/linkerd/app/outbound/src/http/logical/policy/route/backend/metrics.rs @@ -38,20 +38,6 @@ pub fn layer( > + Clone where T: MkStreamLabel, - N: svc::NewService, - NewRecordBodyData< - ExtractRecordBodyDataParams, - NewCountRequests< - ExtractRequestCount, - NewResponseDuration>, N>, - >, - >: svc::NewService, - NewCountRequests< - ExtractRequestCount, - NewResponseDuration>, N>, - >: svc::NewService, - NewResponseDuration>, N>: - svc::NewService, { let RouteBackendMetrics { requests, @@ -59,15 +45,15 @@ where body_metrics, } = metrics.clone(); - svc::layer::mk(move |inner| { - use svc::Layer; - NewRecordBodyData::layer_via(ExtractRecordBodyDataParams(body_metrics.clone())).layer( - NewCountRequests::layer_via(ExtractRequestCount(requests.clone())).layer( - NewRecordDuration::layer_via(ExtractRecordDurationParams(responses.clone())) - .layer(inner), - ), - ) - }) + let requests = NewCountRequests::layer_via(ExtractRequestCount(requests.clone())); + let responses = NewRecordDuration::layer_via(ExtractRecordDurationParams(responses.clone())); + let body_metrics = + NewRecordBodyData::layer_via(ExtractRecordBodyDataParams(body_metrics.clone())); + + svc::layers() + .push(responses) + .push(requests) + .push(body_metrics) } #[derive(Clone, Debug)] diff --git a/linkerd/http/prom/src/body_data/response.rs b/linkerd/http/prom/src/body_data/response.rs index f7999a9f4d..a83095ed1c 100644 --- a/linkerd/http/prom/src/body_data/response.rs +++ b/linkerd/http/prom/src/body_data/response.rs @@ -34,7 +34,7 @@ impl NewRecordBodyData { /// /// This uses an `X`-typed [`ExtractParam`] implementation to extract service parameters /// from a `T`-typed target. - pub fn layer_via(extract: X) -> impl Layer { + pub fn layer_via(extract: X) -> impl Layer + Clone { svc::layer::mk(move |inner| Self { extract: extract.clone(), inner, From 4f1c33b7e31e8e46649e8f5976d3e1950a4f24a1 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Fri, 1 Nov 2024 00:00:00 +0000 Subject: [PATCH 2/2] refactor(app): Define layer type aliases this isn't a "simplification" so much as an outlining of the chunky types in this function signature. that said... it's subjectively nice to outline the definition of our layers into a `MetricsLayer` that we can use as shorthand in the function signature of `layer(..)`. Signed-off-by: katelyn martin --- .../logical/policy/route/backend/metrics.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/linkerd/app/outbound/src/http/logical/policy/route/backend/metrics.rs b/linkerd/app/outbound/src/http/logical/policy/route/backend/metrics.rs index 8854a1cd66..6851ad56f8 100644 --- a/linkerd/app/outbound/src/http/logical/policy/route/backend/metrics.rs +++ b/linkerd/app/outbound/src/http/logical/policy/route/backend/metrics.rs @@ -24,18 +24,18 @@ type ResponseMetrics = record_response::ResponseMetrics< ::StatusLabels, >; +type MetricsLayer = BodyDataLayer>>; +type BodyDataLayer = NewRecordBodyData; +type RequestLayer = NewCountRequests; +type ResponseLayer = NewResponseDuration< + T, + ExtractRecordDurationParams::StreamLabel>>, + N, +>; + pub fn layer( metrics: &RouteBackendMetrics, -) -> impl svc::Layer< - N, - Service = NewRecordBodyData< - ExtractRecordBodyDataParams, - NewCountRequests< - ExtractRequestCount, - NewResponseDuration>, N>, - >, - >, -> + Clone +) -> impl svc::Layer> + Clone where T: MkStreamLabel, {