Skip to content

Commit 2e7c205

Browse files
committed
refactor(app/inbound): metrics layer accepts InboundMetrics
this commit makes a small refactor to the inbound proxy's `metrics::layer()` middleware in the interest of future-proofing it before additional metrics layers are introduced. this will mean that the call site in `http/router.rs` will not need to be updated repeatedly as we introduce request/response body frame size metrics, duration histograms, and so forth. Signed-off-by: katelyn martin <[email protected]>
1 parent 6f58bbf commit 2e7c205

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<C> Inbound<C> {
245245
.push(svc::NewOneshotRoute::layer_via(|t: &policy::Permitted<T>| {
246246
LogicalPerRequest::from(t)
247247
}))
248-
.push(self::metrics::layer(rt.metrics.request_count.clone()))
248+
.push(self::metrics::layer(&rt.metrics))
249249
.check_new_service::<policy::Permitted<T>, http::Request<http::BoxBody>>()
250250
.push(svc::ArcNewService::layer())
251251
.push(policy::NewHttpPolicy::layer(rt.metrics.http_authz.clone()))

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::policy::Permitted;
1+
use crate::{policy::Permitted, InboundMetrics};
22
use linkerd_app_core::{
33
metrics::{
44
prom::{
@@ -13,14 +13,16 @@ use linkerd_app_core::{
1313
use linkerd_http_prom::count_reqs::{NewCountRequests, RequestCount};
1414

1515
pub(super) fn layer<N>(
16-
request_count: RequestCountFamilies,
17-
// TODO(kate): other metrics families will added here.
16+
InboundMetrics { request_count, .. }: &InboundMetrics,
1817
) -> impl svc::Layer<N, Service = NewCountRequests<ExtractRequestCount, N>> {
19-
svc::layer::mk(move |inner| {
20-
use svc::Layer as _;
18+
use svc::Layer as _;
19+
20+
let count = {
2121
let extract = ExtractRequestCount(request_count.clone());
22-
NewCountRequests::layer_via(extract).layer(inner)
23-
})
22+
NewCountRequests::layer_via(extract)
23+
};
24+
25+
svc::layer::mk(move |inner| count.layer(inner))
2426
}
2527

2628
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)