Skip to content

Commit a75492c

Browse files
committed
refactor(app): Outline route label extraction
this addresses the `TODO` comment, moving the `RouteLabelExtract` type out of the policy route layer function. this defines a method on `MatchedRoute` which may be called to retrieve a `RouteLabelExtract`. that type holds references to the contruction-time information about the route, and can be used to later inspect an outbound request at call-time, returning a `labels::Route` set of labels. this is a helpful piece of reusable glue that is broadly useful in instrumenting our route-level middleware. Signed-off-by: katelyn martin <[email protected]>
1 parent ec8eb29 commit a75492c

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,9 @@ where
124124
.push_on_service(svc::LoadShed::layer())
125125
.push(filters::NewApplyFilters::<Self, _, _>::layer())
126126
.push({
127-
// TODO(kate): extracting route labels like this should ideally live somewhere
128-
// else, like e.g. the `SetExtensions` middleware.
129-
let mk_extract = |rt: &Self| {
130-
let Route {
131-
parent_ref,
132-
route_ref,
133-
..
134-
} = &rt.params;
135-
metrics::labels::RouteLabelExtract(parent_ref.clone(), route_ref.clone())
136-
};
127+
let mk = Self::label_extractor;
137128
let metrics = metrics.retry.clone();
138-
retry::NewHttpRetry::layer_via_mk(mk_extract, metrics)
129+
retry::NewHttpRetry::layer_via_mk(mk, metrics)
139130
})
140131
.check_new::<Self>()
141132
.check_new_service::<Self, http::Request<http::BoxBody>>()

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,26 @@ impl EncodeLabelSet for GrpcRsp {
215215
}
216216
}
217217

218+
// === impl MatchedRoute ===
219+
220+
impl<T, M, F, P> super::super::MatchedRoute<T, M, F, P> {
221+
/// Returns a [`RouteLabelExtract`].
222+
///
223+
/// The extractor returned by this function provides a [`ExtractParam<P, T>`] implementation
224+
/// that can be used to acquire the route-level labels corresponding to a given outbound
225+
/// request.
226+
pub(crate) fn label_extractor(&self) -> RouteLabelExtract {
227+
use super::super::Route;
228+
let Route {
229+
parent_ref,
230+
route_ref,
231+
..
232+
} = &self.params;
233+
234+
RouteLabelExtract(parent_ref.clone(), route_ref.clone())
235+
}
236+
}
237+
218238
// === impl RouteLabelExtract ===
219239

220240
impl<B> ExtractParam<Route, http::Request<B>> for RouteLabelExtract {

0 commit comments

Comments
 (0)