Skip to content

Commit ec8eb29

Browse files
committed
refactor(app): Hoist label extractor out of retry middleware
this commit promotes the `RetryLabelExtract` type out of the route retry middleware, and into the metrics submodule. in preparation for generalizing this component, we rename it to `RouteLabelExtract`. Signed-off-by: katelyn martin <[email protected]>
1 parent 3b1db24 commit ec8eb29

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ where
132132
route_ref,
133133
..
134134
} = &rt.params;
135-
retry::RetryLabelExtract(parent_ref.clone(), route_ref.clone())
135+
metrics::labels::RouteLabelExtract(parent_ref.clone(), route_ref.clone())
136136
};
137137
let metrics = metrics.retry.clone();
138138
retry::NewHttpRetry::layer_via_mk(mk_extract, metrics)

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Prometheus label types.
22
use linkerd_app_core::{
3-
dns, errors, metrics::prom::EncodeLabelSetMut, proxy::http, Error as BoxError,
3+
dns, errors, metrics::prom::EncodeLabelSetMut, proxy::http, svc::ExtractParam,
4+
Error as BoxError,
45
};
56
use prometheus_client::encoding::*;
67

@@ -39,6 +40,9 @@ pub struct GrpcRsp {
3940
pub error: Option<Error>,
4041
}
4142

43+
#[derive(Clone, Debug)]
44+
pub struct RouteLabelExtract(pub ParentRef, pub RouteRef);
45+
4246
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
4347
pub enum Error {
4448
FailFast,
@@ -211,6 +215,17 @@ impl EncodeLabelSet for GrpcRsp {
211215
}
212216
}
213217

218+
// === impl RouteLabelExtract ===
219+
220+
impl<B> ExtractParam<Route, http::Request<B>> for RouteLabelExtract {
221+
fn extract_param(&self, t: &http::Request<B>) -> Route {
222+
let Self(parent, route) = self;
223+
let uri = t.uri();
224+
225+
Route::new(parent.clone(), route.clone(), uri)
226+
}
227+
}
228+
214229
// === impl Error ===
215230

216231
impl Error {

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
use super::{extensions, metrics::labels::Route as RouteLabels};
2-
use crate::{ParentRef, RouteRef};
1+
use super::{
2+
extensions,
3+
metrics::labels::{Route as RouteLabels, RouteLabelExtract},
4+
};
35
use futures::future::{Either, Ready};
46
use linkerd_app_core::{
57
cause_ref, classify,
68
exp_backoff::ExponentialBackoff,
79
is_caused_by,
810
proxy::http::{self, stream_timeouts::ResponseTimeoutError},
9-
svc::{self, http::h2, ExtractParam},
11+
svc::{self, http::h2},
1012
Error, Result,
1113
};
1214
use linkerd_http_retry::{self as retry, peek_trailers::PeekTrailersBody};
@@ -18,7 +20,7 @@ use tokio::time;
1820
pub struct IsRetry(());
1921

2022
pub type NewHttpRetry<F, N> =
21-
retry::NewHttpRetry<RetryPolicy, RouteLabels, F, RetryLabelExtract, N>;
23+
retry::NewHttpRetry<RetryPolicy, RouteLabels, F, RouteLabelExtract, N>;
2224

2325
#[derive(Clone, Debug)]
2426
pub struct RetryPolicy {
@@ -31,9 +33,6 @@ pub struct RetryPolicy {
3133
pub backoff: Option<ExponentialBackoff>,
3234
}
3335

34-
#[derive(Clone, Debug)]
35-
pub struct RetryLabelExtract(pub ParentRef, pub RouteRef);
36-
3736
pub type RouteRetryMetrics = retry::MetricFamilies<RouteLabels>;
3837

3938
// === impl RetryPolicy ===
@@ -163,14 +162,3 @@ impl RetryPolicy {
163162
false
164163
}
165164
}
166-
167-
// === impl RetryLabelExtract ===
168-
169-
impl<B> ExtractParam<RouteLabels, http::Request<B>> for RetryLabelExtract {
170-
fn extract_param(&self, t: &http::Request<B>) -> RouteLabels {
171-
let Self(parent, route) = self;
172-
let uri = t.uri();
173-
174-
RouteLabels::new(parent.clone(), route.clone(), uri)
175-
}
176-
}

0 commit comments

Comments
 (0)