Skip to content

Commit 9910adb

Browse files
authored
refactor(http/prom): rename generic duration infrastructure (#4419)
* refactor(http/prom): rename RecordResponse to RecordDuration this type is not itself a service in all cases. it *is* a service, and is accordingly aliased to both RecordRequestDuration and RecordResponseDuration, depending on which metrics structure it is provided. to help clarify this code, this renames this generic tower service infrastructure to RecordDuration. Signed-off-by: katelyn martin <kate@buoyant.io> * refactor(http/prom): rename NewRecordResponse to NewRecordDuration as in the previous commit, which applied this change to the tower service middleware, this commit applies a change to the duration "new service" middleware. this type is generic over a metrics structure and emits services that either record request or response duration, depending on the metics provided. Signed-off-by: katelyn martin <kate@buoyant.io> * nit(http/prom): fix impl banner comments Signed-off-by: katelyn martin <kate@buoyant.io> * nit(app/inbound): rename layer variable bindings 'body' was a sensible name when there was only one layer instrumenting body streams. now that there are request and response telemetry layers, we should use more specific terminology. Signed-off-by: katelyn martin <kate@buoyant.io> --------- Signed-off-by: katelyn martin <kate@buoyant.io>
1 parent 121a527 commit 9910adb

5 files changed

Lines changed: 27 additions & 21 deletions

File tree

linkerd/app/inbound/src/http/router/metrics.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ pub(super) fn layer<N>(
2525
count_reqs::NewCountRequests::layer_via(extract)
2626
};
2727

28-
let body = {
28+
let response_body = {
2929
let extract = ExtractResponseBodyDataMetrics::new(response_body_data.clone());
3030
NewRecordResponseBodyData::layer_via(extract)
3131
};
3232

33-
let request = {
33+
let request_body = {
3434
let extract = ExtractRequestBodyDataParams::new(request_body_data.clone());
3535
NewRecordRequestBodyData::layer_via(extract)
3636
};
@@ -40,7 +40,9 @@ pub(super) fn layer<N>(
4040
NewRecordStatusCode::layer_via(extract)
4141
};
4242

43-
svc::layer::mk(move |inner| count.layer(body.layer(request.layer(status.layer(inner)))))
43+
svc::layer::mk(move |inner| {
44+
count.layer(response_body.layer(request_body.layer(status.layer(inner))))
45+
})
4446
}
4547

4648
/// An `N`-typed service instrumented with metrics middleware.

linkerd/app/outbound/src/http/logical/policy/route/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub type LabelHttpRouteBackendRsp = LabelHttpRsp<labels::RouteBackend>;
7070
pub type LabelGrpcRouteBackendRsp = LabelGrpcRsp<labels::RouteBackend>;
7171

7272
pub type NewRecordDuration<T, M, N> =
73-
record_response::NewRecordResponse<T, ExtractRecordDurationParams<M>, M, N>;
73+
record_response::NewRecordDuration<T, ExtractRecordDurationParams<M>, M, N>;
7474

7575
#[derive(Clone, Debug)]
7676
pub struct ExtractRecordDurationParams<M>(pub M);

linkerd/http/prom/src/record_response.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use self::{
2323
response::{NewResponseDuration, RecordResponseDuration, ResponseMetrics},
2424
};
2525

26-
/// A set of parameters that can be used to construct a `RecordResponse` layer.
26+
/// A set of parameters that can be used to construct a [`RecordDuration`] layer.
2727
pub struct Params<L: MkStreamLabel, M> {
2828
pub labeler: L,
2929
pub metric: M,
@@ -35,22 +35,22 @@ pub struct RequestCancelled;
3535

3636
/// Instruments an `N`-typed [`svc::NewService<T>`] with metrics.
3737
///
38-
/// Builds [`RecordResponse<L, M, S>`] instances by extracting `L`- and `M`-typed [`Params<L, M>`]
38+
/// Builds [`RecordDuration<L, M, S>`] instances by extracting `L`- and `M`-typed [`Params<L, M>`]
3939
/// parameters from `T`-typed stack targets using an `X`-typed [`svc::ExtractParam<P, T>`]
4040
/// implementation.
4141
///
4242
/// The `L`-typed [`MkStreamLabel`] inspects requests and emits a [`StreamLabel`], which is
4343
/// intended to be used to generate labels for the `M`-typed metrics.
4444
#[derive(Clone, Debug)]
45-
pub struct NewRecordResponse<L, X, M, N> {
45+
pub struct NewRecordDuration<L, X, M, N> {
4646
inner: N,
4747
extract: X,
4848
_marker: std::marker::PhantomData<fn() -> (L, M)>,
4949
}
5050

5151
/// A Service that can record a request/response durations.
5252
#[derive(Clone, Debug)]
53-
pub struct RecordResponse<L, M, S> {
53+
pub struct RecordDuration<L, M, S> {
5454
inner: S,
5555
labeler: L,
5656
metric: M,
@@ -97,9 +97,9 @@ impl MetricConstructor<Histogram> for MkDurationHistogram {
9797
}
9898
}
9999

100-
// === impl NewRecordResponse ===
100+
// === impl NewRecordDuration ===
101101

102-
impl<L, X, M, N> NewRecordResponse<L, X, M, N>
102+
impl<L, X, M, N> NewRecordDuration<L, X, M, N>
103103
where
104104
L: MkStreamLabel,
105105
{
@@ -119,7 +119,7 @@ where
119119
}
120120
}
121121

122-
impl<L, M, N> NewRecordResponse<L, (), M, N>
122+
impl<L, M, N> NewRecordDuration<L, (), M, N>
123123
where
124124
L: MkStreamLabel,
125125
{
@@ -128,24 +128,24 @@ where
128128
}
129129
}
130130

131-
impl<T, L, X, M, N> svc::NewService<T> for NewRecordResponse<L, X, M, N>
131+
impl<T, L, X, M, N> svc::NewService<T> for NewRecordDuration<L, X, M, N>
132132
where
133133
L: MkStreamLabel,
134134
X: svc::ExtractParam<Params<L, M>, T>,
135135
N: svc::NewService<T>,
136136
{
137-
type Service = RecordResponse<L, M, N::Service>;
137+
type Service = RecordDuration<L, M, N::Service>;
138138

139139
fn new_service(&self, target: T) -> Self::Service {
140140
let Params { labeler, metric } = self.extract.extract_param(&target);
141141
let inner = self.inner.new_service(target);
142-
RecordResponse::new(labeler, metric, inner)
142+
RecordDuration::new(labeler, metric, inner)
143143
}
144144
}
145145

146-
// === impl RecordResponse ===
146+
// === impl RecordDuration ===
147147

148-
impl<L, M, S> RecordResponse<L, M, S>
148+
impl<L, M, S> RecordDuration<L, M, S>
149149
where
150150
L: MkStreamLabel,
151151
{

linkerd/http/prom/src/record_response/request.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ pub struct RequestMetrics<L> {
1717
}
1818

1919
pub type NewRequestDuration<L, X, N> =
20-
super::NewRecordResponse<L, X, RequestMetrics<<L as MkStreamLabel>::DurationLabels>, N>;
20+
super::NewRecordDuration<L, X, RequestMetrics<<L as MkStreamLabel>::DurationLabels>, N>;
2121

2222
pub type RecordRequestDuration<L, S> =
23-
super::RecordResponse<L, RequestMetrics<<L as MkStreamLabel>::DurationLabels>, S>;
23+
super::RecordDuration<L, RequestMetrics<<L as MkStreamLabel>::DurationLabels>, S>;
2424

2525
// === impl RequestMetrics ===
2626

@@ -61,6 +61,8 @@ impl<L> Clone for RequestMetrics<L> {
6161
}
6262
}
6363

64+
// === impl RecordRequestDuration ===
65+
6466
impl<ReqB, L, S> svc::Service<http::Request<ReqB>> for RecordRequestDuration<L, S>
6567
where
6668
L: MkStreamLabel,

linkerd/http/prom/src/record_response/response.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub struct ResponseMetrics<L> {
1818
}
1919

2020
pub type NewResponseDuration<L, X, N> =
21-
super::NewRecordResponse<L, X, ResponseMetrics<<L as MkStreamLabel>::DurationLabels>, N>;
21+
super::NewRecordDuration<L, X, ResponseMetrics<<L as MkStreamLabel>::DurationLabels>, N>;
2222

2323
pub type RecordResponseDuration<L, S> =
24-
super::RecordResponse<L, ResponseMetrics<<L as MkStreamLabel>::DurationLabels>, S>;
24+
super::RecordDuration<L, ResponseMetrics<<L as MkStreamLabel>::DurationLabels>, S>;
2525

2626
/// Notifies the response body when the request body is flushed.
2727
#[pin_project::pin_project(PinnedDrop)]
@@ -64,6 +64,8 @@ impl<L> Clone for ResponseMetrics<L> {
6464
}
6565
}
6666

67+
// === impl RecordResponseDuration ===
68+
6769
impl<M, S> svc::Service<http::Request<BoxBody>> for RecordResponseDuration<M, S>
6870
where
6971
M: MkStreamLabel,
@@ -105,7 +107,7 @@ where
105107
}
106108
}
107109

108-
// === impl ResponseBody ===
110+
// === impl RequestBody ===
109111

110112
impl<B> http_body::Body for RequestBody<B>
111113
where

0 commit comments

Comments
 (0)