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

refactor(app): Simplify backend metrics tower layer #3318

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,36 @@ type ResponseMetrics<L> = record_response::ResponseMetrics<
<L as StreamLabel>::StatusLabels,
>;

type MetricsLayer<T, N> = BodyDataLayer<RequestLayer<ResponseLayer<T, N>>>;
type BodyDataLayer<N> = NewRecordBodyData<ExtractRecordBodyDataParams, N>;
type RequestLayer<N> = NewCountRequests<ExtractRequestCount, N>;
type ResponseLayer<T, N> = NewResponseDuration<
T,
ExtractRecordDurationParams<ResponseMetrics<<T as MkStreamLabel>::StreamLabel>>,
N,
>;

pub fn layer<T, N>(
metrics: &RouteBackendMetrics<T::StreamLabel>,
) -> impl svc::Layer<
N,
Service = NewRecordBodyData<
ExtractRecordBodyDataParams,
NewCountRequests<
ExtractRequestCount,
NewResponseDuration<T, ExtractRecordDurationParams<ResponseMetrics<T::StreamLabel>>, N>,
>,
>,
> + Clone
) -> impl svc::Layer<N, Service = MetricsLayer<T, N>> + Clone
where
T: MkStreamLabel,
N: svc::NewService<T>,
NewRecordBodyData<
ExtractRecordBodyDataParams,
NewCountRequests<
ExtractRequestCount,
NewResponseDuration<T, ExtractRecordDurationParams<ResponseMetrics<T::StreamLabel>>, N>,
>,
>: svc::NewService<T>,
NewCountRequests<
ExtractRequestCount,
NewResponseDuration<T, ExtractRecordDurationParams<ResponseMetrics<T::StreamLabel>>, N>,
>: svc::NewService<T>,
NewResponseDuration<T, ExtractRecordDurationParams<ResponseMetrics<T::StreamLabel>>, N>:
svc::NewService<T>,
{
let RouteBackendMetrics {
requests,
responses,
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)]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/http/prom/src/body_data/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<X: Clone, N> NewRecordBodyData<X, N> {
///
/// This uses an `X`-typed [`ExtractParam<P, T>`] implementation to extract service parameters
/// from a `T`-typed target.
pub fn layer_via(extract: X) -> impl Layer<N, Service = Self> {
pub fn layer_via(extract: X) -> impl Layer<N, Service = Self> + Clone {
svc::layer::mk(move |inner| Self {
extract: extract.clone(),
inner,
Expand Down
Loading