Skip to content

Commit e478b3e

Browse files
authored
service-profiles: Cleanup crate organization (#646)
* Renames `Routes` to `Profile`; * Renames `GetRoutes` to `GetProfile`; * Renames `WeightedAddr` to `Target`; and * Scope `Route` & co within `http` module.
1 parent 8c61f2a commit e478b3e

File tree

12 files changed

+138
-140
lines changed

12 files changed

+138
-140
lines changed

linkerd/app/core/src/classify.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ use tracing::trace;
1212
#[derive(Clone, Debug)]
1313
pub enum Request {
1414
Default,
15-
Profile(profiles::ResponseClasses),
15+
Profile(profiles::http::ResponseClasses),
1616
}
1717

1818
#[derive(Clone, Debug)]
1919
pub enum Response {
2020
Default,
2121
Grpc,
22-
Profile(profiles::ResponseClasses),
22+
Profile(profiles::http::ResponseClasses),
2323
}
2424

2525
#[derive(Clone, Debug)]
@@ -51,8 +51,8 @@ pub enum SuccessOrFailure {
5151

5252
// === impl Request ===
5353

54-
impl From<profiles::ResponseClasses> for Request {
55-
fn from(classes: profiles::ResponseClasses) -> Self {
54+
impl From<profiles::http::ResponseClasses> for Request {
55+
fn from(classes: profiles::http::ResponseClasses) -> Self {
5656
if classes.is_empty() {
5757
Request::Default
5858
} else {
@@ -106,7 +106,7 @@ impl Default for Response {
106106
impl Response {
107107
fn match_class<B>(
108108
rsp: &http::Response<B>,
109-
classes: &[profiles::ResponseClass],
109+
classes: &[profiles::http::ResponseClass],
110110
) -> Option<Class> {
111111
for class in classes {
112112
if class.is_match(rsp) {

linkerd/app/core/src/dst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::time::Duration;
99
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1010
pub struct Route {
1111
pub target: Addr,
12-
pub route: profiles::Route,
12+
pub route: profiles::http::Route,
1313
pub direction: super::metric_labels::Direction,
1414
}
1515

linkerd/app/core/src/retry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct NewRetry<C = ()> {
3030
pub struct Retry<C = ()> {
3131
metrics: Handle,
3232
budget: Arc<Budget>,
33-
response_classes: profiles::ResponseClasses,
33+
response_classes: profiles::http::ResponseClasses,
3434
_clone_request: PhantomData<C>,
3535
}
3636

linkerd/app/inbound/src/endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl AsRef<Addr> for Profile {
118118
impl profiles::WithRoute for Profile {
119119
type Route = dst::Route;
120120

121-
fn with_route(self, route: profiles::Route) -> Self::Route {
121+
fn with_route(self, route: profiles::http::Route) -> Self::Route {
122122
dst::Route {
123123
route,
124124
target: self.0.clone(),

linkerd/app/inbound/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Config {
6666
+ 'static,
6767
S::Error: Into<Error>,
6868
S::Future: Unpin + Send,
69-
P: profiles::GetRoutes<Profile> + Unpin + Clone + Send + 'static,
69+
P: profiles::GetProfile<Profile> + Unpin + Clone + Send + 'static,
7070
P::Future: Unpin + Send,
7171
{
7272
let tcp_connect = self.build_tcp_connect(&metrics);
@@ -148,7 +148,7 @@ impl Config {
148148
C::Error: Into<Error>,
149149
C::Response: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + 'static,
150150
C::Future: Unpin + Send,
151-
P: profiles::GetRoutes<Profile> + Unpin + Clone + Send + 'static,
151+
P: profiles::GetProfile<Profile> + Unpin + Clone + Send + 'static,
152152
P::Future: Unpin + Send,
153153
// The loopback router processes requests sent to the inbound port.
154154
L: tower::Service<Target, Response = S> + Unpin + Send + Clone + 'static,

linkerd/app/outbound/src/endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl AsRef<Addr> for Profile {
439439
impl profiles::WithRoute for Profile {
440440
type Route = dst::Route;
441441

442-
fn with_route(self, route: profiles::Route) -> Self::Route {
442+
fn with_route(self, route: profiles::http::Route) -> Self::Route {
443443
dst::Route {
444444
route,
445445
target: self.0.clone(),

linkerd/app/outbound/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl Config {
239239
+ 'static,
240240
R::Future: Unpin + Send,
241241
R::Resolution: Unpin + Send,
242-
P: profiles::GetRoutes<Profile> + Unpin + Clone + Send + 'static,
242+
P: profiles::GetProfile<Profile> + Unpin + Clone + Send + 'static,
243243
P::Future: Unpin + Send,
244244
{
245245
let ProxyConfig {

linkerd/service-profiles/src/client.rs

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use crate::http as profiles;
1+
use crate::{http, Profile, Receiver, Target};
22
use api::destination_client::DestinationClient;
33
use futures::{future, prelude::*, ready, select_biased};
4-
use http;
54
use http_body::Body as HttpBody;
6-
use linkerd2_addr::{Addr, NameAddr};
5+
use linkerd2_addr::Addr;
76
use linkerd2_error::{Error, Recover};
87
use linkerd2_proxy_api::destination as api;
98
use pin_project::pin_project;
@@ -33,8 +32,6 @@ pub struct Client<S, R> {
3332
context_token: String,
3433
}
3534

36-
pub type Receiver = watch::Receiver<profiles::Routes>;
37-
3835
#[derive(Clone, Debug)]
3936
pub struct InvalidProfileAddr(Addr);
4037

@@ -92,7 +89,7 @@ impl<S, R> Client<S, R>
9289
where
9390
// These bounds aren't *required* here, they just help detect the problem
9491
// earlier (as Client::new), instead of when trying to passing a `Client`
95-
// to something that wants `impl profiles::GetRoutes`.
92+
// to something that wants `impl GetProfile`.
9693
S: GrpcService<BoxBody> + Clone + Send + 'static,
9794
S::ResponseBody: Send,
9895
<S::ResponseBody as Body>::Data: Send,
@@ -196,7 +193,7 @@ where
196193
}
197194

198195
info!("Using default service profile after timeout");
199-
profiles::Routes::default()
196+
Profile::default()
200197
}
201198
Poll::Ready(Ok(profile)) => profile,
202199
};
@@ -253,25 +250,25 @@ where
253250
fn poll_rx(
254251
rx: Pin<&mut grpc::Streaming<api::DestinationProfile>>,
255252
cx: &mut Context<'_>,
256-
) -> Poll<Option<Result<profiles::Routes, grpc::Status>>> {
253+
) -> Poll<Option<Result<Profile, grpc::Status>>> {
257254
trace!("poll");
258255
let profile = ready!(rx.poll_next(cx)).map(|res| {
259256
res.map(|proto| {
260257
debug!("profile received: {:?}", proto);
261258
let retry_budget = proto.retry_budget.and_then(convert_retry_budget);
262-
let routes = proto
259+
let http_routes = proto
263260
.routes
264261
.into_iter()
265262
.filter_map(move |orig| convert_route(orig, retry_budget.as_ref()))
266263
.collect();
267-
let dst_overrides = proto
264+
let targets = proto
268265
.dst_overrides
269266
.into_iter()
270267
.filter_map(convert_dst_override)
271268
.collect();
272-
profiles::Routes {
273-
routes,
274-
dst_overrides,
269+
Profile {
270+
http_routes,
271+
targets,
275272
}
276273
})
277274
});
@@ -281,7 +278,7 @@ where
281278
fn poll_profile(
282279
mut self: Pin<&mut Self>,
283280
cx: &mut Context<'_>,
284-
) -> Poll<Result<profiles::Routes, Error>> {
281+
) -> Poll<Result<Profile, Error>> {
285282
let span = info_span!("poll_profile");
286283
let _enter = span.enter();
287284

@@ -337,14 +334,14 @@ where
337334
fn convert_route(
338335
orig: api::Route,
339336
retry_budget: Option<&Arc<Budget>>,
340-
) -> Option<(profiles::RequestMatch, profiles::Route)> {
337+
) -> Option<(http::RequestMatch, http::Route)> {
341338
let req_match = orig.condition.and_then(convert_req_match)?;
342339
let rsp_classes = orig
343340
.response_classes
344341
.into_iter()
345342
.filter_map(convert_rsp_class)
346343
.collect();
347-
let mut route = profiles::Route::new(orig.metrics_labels.into_iter(), rsp_classes);
344+
let mut route = http::Route::new(orig.metrics_labels.into_iter(), rsp_classes);
348345
if orig.is_retryable {
349346
set_route_retry(&mut route, retry_budget);
350347
}
@@ -354,19 +351,18 @@ fn convert_route(
354351
Some((req_match, route))
355352
}
356353

357-
fn convert_dst_override(orig: api::WeightedDst) -> Option<profiles::WeightedAddr> {
354+
fn convert_dst_override(orig: api::WeightedDst) -> Option<Target> {
358355
if orig.weight == 0 {
359356
return None;
360357
}
361-
NameAddr::from_str(orig.authority.as_str())
362-
.ok()
363-
.map(|addr| profiles::WeightedAddr {
364-
addr,
365-
weight: orig.weight,
366-
})
358+
let addr = Addr::from_str(orig.authority.as_str()).ok()?;
359+
Some(Target {
360+
addr,
361+
weight: orig.weight,
362+
})
367363
}
368364

369-
fn set_route_retry(route: &mut profiles::Route, retry_budget: Option<&Arc<Budget>>) {
365+
fn set_route_retry(route: &mut http::Route, retry_budget: Option<&Arc<Budget>>) {
370366
let budget = match retry_budget {
371367
Some(budget) => budget.clone(),
372368
None => {
@@ -378,7 +374,7 @@ fn set_route_retry(route: &mut profiles::Route, retry_budget: Option<&Arc<Budget
378374
route.set_retries(budget);
379375
}
380376

381-
fn set_route_timeout(route: &mut profiles::Route, timeout: Result<Duration, Duration>) {
377+
fn set_route_timeout(route: &mut http::Route, timeout: Result<Duration, Duration>) {
382378
match timeout {
383379
Ok(dur) => {
384380
route.set_timeout(dur);
@@ -389,19 +385,19 @@ fn set_route_timeout(route: &mut profiles::Route, timeout: Result<Duration, Dura
389385
}
390386
}
391387

392-
fn convert_req_match(orig: api::RequestMatch) -> Option<profiles::RequestMatch> {
388+
fn convert_req_match(orig: api::RequestMatch) -> Option<http::RequestMatch> {
393389
let m = match orig.r#match? {
394390
api::request_match::Match::All(ms) => {
395391
let ms = ms.matches.into_iter().filter_map(convert_req_match);
396-
profiles::RequestMatch::All(ms.collect())
392+
http::RequestMatch::All(ms.collect())
397393
}
398394
api::request_match::Match::Any(ms) => {
399395
let ms = ms.matches.into_iter().filter_map(convert_req_match);
400-
profiles::RequestMatch::Any(ms.collect())
396+
http::RequestMatch::Any(ms.collect())
401397
}
402398
api::request_match::Match::Not(m) => {
403399
let m = convert_req_match(*m)?;
404-
profiles::RequestMatch::Not(Box::new(m))
400+
http::RequestMatch::Not(Box::new(m))
405401
}
406402
api::request_match::Match::Path(api::PathMatch { regex }) => {
407403
let regex = regex.trim();
@@ -414,23 +410,23 @@ fn convert_req_match(orig: api::RequestMatch) -> Option<profiles::RequestMatch>
414410
Regex::new(&re).ok()?
415411
}
416412
};
417-
profiles::RequestMatch::Path(re)
413+
http::RequestMatch::Path(re)
418414
}
419415
api::request_match::Match::Method(mm) => {
420416
let m = mm.r#type.and_then(|m| (&m).try_into().ok())?;
421-
profiles::RequestMatch::Method(m)
417+
http::RequestMatch::Method(m)
422418
}
423419
};
424420

425421
Some(m)
426422
}
427423

428-
fn convert_rsp_class(orig: api::ResponseClass) -> Option<profiles::ResponseClass> {
424+
fn convert_rsp_class(orig: api::ResponseClass) -> Option<http::ResponseClass> {
429425
let c = orig.condition.and_then(convert_rsp_match)?;
430-
Some(profiles::ResponseClass::new(orig.is_failure, c))
426+
Some(http::ResponseClass::new(orig.is_failure, c))
431427
}
432428

433-
fn convert_rsp_match(orig: api::ResponseMatch) -> Option<profiles::ResponseMatch> {
429+
fn convert_rsp_match(orig: api::ResponseMatch) -> Option<http::ResponseMatch> {
434430
let m = match orig.r#match? {
435431
api::response_match::Match::All(ms) => {
436432
let ms = ms
@@ -441,7 +437,7 @@ fn convert_rsp_match(orig: api::ResponseMatch) -> Option<profiles::ResponseMatch
441437
if ms.is_empty() {
442438
return None;
443439
}
444-
profiles::ResponseMatch::All(ms)
440+
http::ResponseMatch::All(ms)
445441
}
446442
api::response_match::Match::Any(ms) => {
447443
let ms = ms
@@ -452,16 +448,16 @@ fn convert_rsp_match(orig: api::ResponseMatch) -> Option<profiles::ResponseMatch
452448
if ms.is_empty() {
453449
return None;
454450
}
455-
profiles::ResponseMatch::Any(ms)
451+
http::ResponseMatch::Any(ms)
456452
}
457453
api::response_match::Match::Not(m) => {
458454
let m = convert_rsp_match(*m)?;
459-
profiles::ResponseMatch::Not(Box::new(m))
455+
http::ResponseMatch::Not(Box::new(m))
460456
}
461457
api::response_match::Match::Status(range) => {
462-
let min = http::StatusCode::from_u16(range.min as u16).ok()?;
463-
let max = http::StatusCode::from_u16(range.max as u16).ok()?;
464-
profiles::ResponseMatch::Status { min, max }
458+
let min = ::http::StatusCode::from_u16(range.min as u16).ok()?;
459+
let max = ::http::StatusCode::from_u16(range.max as u16).ok()?;
460+
http::ResponseMatch::Status { min, max }
465461
}
466462
};
467463

linkerd/service-profiles/src/http/concrete.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use super::{OverrideDestination, WeightedAddr};
1+
use super::OverrideDestination;
2+
use crate::Target;
23
use futures::{future, TryFutureExt};
3-
use linkerd2_addr::NameAddr;
4+
use linkerd2_addr::Addr;
45
use linkerd2_error::Error;
56
use rand::distributions::{Distribution, WeightedIndex};
67
use rand::rngs::SmallRng;
@@ -38,10 +39,10 @@ pub struct Update {
3839

3940
#[derive(Clone)]
4041
enum Routes {
41-
Forward(Option<NameAddr>),
42+
Forward(Option<Addr>),
4243
Override {
4344
distribution: WeightedIndex<u32>,
44-
overrides: Vec<NameAddr>,
45+
overrides: Vec<Addr>,
4546
},
4647
}
4748

@@ -125,7 +126,7 @@ impl Update {
125126
.map_err(|_| error::LostService(()))
126127
}
127128

128-
pub fn set_split(&mut self, mut addrs: Vec<WeightedAddr>) -> Result<(), error::LostService> {
129+
pub fn set_split(&mut self, mut addrs: Vec<Target>) -> Result<(), error::LostService> {
129130
let routes = match self.routes {
130131
Routes::Forward(ref addr) => {
131132
if addrs.len() == 1 {

0 commit comments

Comments
 (0)