Skip to content

Commit cd11ef1

Browse files
authored
refactor(app/inbound): type aliases specify extractors (#4189)
our metrics layer is generic across an `N`-typed service factory. this commit introduces types aliases that apply `X`-typed extractor parameters to the `linkerd-http-prom` middleware, which are unaware of a concrete metrics extractor. we use this to reduce the complexity of the `layer()` function's type signature. see #4180. NB: based upon #4188, and #4186. Signed-off-by: katelyn martin <[email protected]>
1 parent 4b8bbbe commit cd11ef1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use linkerd_app_core::{
1212
};
1313
use linkerd_http_prom::{
1414
body_data::{self, BodyDataMetrics},
15-
count_reqs::{self, NewCountRequests, RequestCount},
15+
count_reqs::{self, RequestCount},
1616
};
1717

1818
pub(super) fn layer<N>(
@@ -21,13 +21,7 @@ pub(super) fn layer<N>(
2121
response_body_data,
2222
..
2323
}: &InboundMetrics,
24-
) -> impl svc::Layer<
25-
N,
26-
Service = NewCountRequests<
27-
ExtractRequestCount,
28-
body_data::response::NewRecordBodyData<ExtractResponseBodyDataMetrics, N>,
29-
>,
30-
> {
24+
) -> impl svc::Layer<N, Service = Instrumented<N>> {
3125
use svc::Layer as _;
3226

3327
let count = {
@@ -37,12 +31,18 @@ pub(super) fn layer<N>(
3731

3832
let body = {
3933
let extract = ExtractResponseBodyDataMetrics(response_body_data.clone());
40-
body_data::response::NewRecordBodyData::layer_via(extract)
34+
NewRecordResponseBodyData::layer_via(extract)
4135
};
4236

4337
svc::layer::mk(move |inner| count.layer(body.layer(inner)))
4438
}
4539

40+
/// An `N`-typed service instrumented with metrics middleware.
41+
type Instrumented<N> = NewCountRequests<NewRecordResponseBodyData<N>>;
42+
43+
/// An `N`-typed `NewService<T>` instrumented with request counting metrics.
44+
type NewCountRequests<N> = count_reqs::NewCountRequests<ExtractRequestCount, N>;
45+
4646
#[derive(Clone, Debug)]
4747
pub struct RequestCountFamilies {
4848
grpc: count_reqs::RequestCountFamilies<RequestCountLabels>,
@@ -57,6 +57,10 @@ pub struct RequestCountLabels {
5757
#[derive(Clone, Debug)]
5858
pub struct ExtractRequestCount(pub RequestCountFamilies);
5959

60+
/// An `N`-typed `NewService<T>` instrumented with response body metrics.
61+
type NewRecordResponseBodyData<N> =
62+
body_data::response::NewRecordBodyData<ExtractResponseBodyDataMetrics, N>;
63+
6064
#[derive(Clone, Debug)]
6165
pub struct ResponseBodyFamilies {
6266
grpc: body_data::response::ResponseBodyFamilies<ResponseBodyDataLabels>,

0 commit comments

Comments
 (0)