1- use crate :: http as profiles ;
1+ use crate :: { http, Profile , Receiver , Target } ;
22use api:: destination_client:: DestinationClient ;
33use futures:: { future, prelude:: * , ready, select_biased} ;
4- use http;
54use http_body:: Body as HttpBody ;
6- use linkerd2_addr:: { Addr , NameAddr } ;
5+ use linkerd2_addr:: Addr ;
76use linkerd2_error:: { Error , Recover } ;
87use linkerd2_proxy_api:: destination as api;
98use 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 ) ]
3936pub struct InvalidProfileAddr ( Addr ) ;
4037
@@ -92,7 +89,7 @@ impl<S, R> Client<S, R>
9289where
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
337334fn 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
0 commit comments