11use crate :: http:: uri:: Authority ;
22use indexmap:: IndexMap ;
33use linkerd2_app_core:: {
4- dst,
5- metric_labels,
4+ dst, metric_labels,
65 metric_labels:: { prefix_labels, EndpointLabels , TlsStatus } ,
76 profiles,
87 proxy:: {
@@ -15,8 +14,7 @@ use linkerd2_app_core::{
1514 } ,
1615 router,
1716 transport:: { listen, tls} ,
18- Addr ,
19- Conditional , //L5D_REQUIRE_ID,
17+ Addr , Conditional ,
2018} ;
2119use std:: { net:: SocketAddr , sync:: Arc } ;
2220
@@ -38,7 +36,7 @@ pub struct HttpLogical {
3836
3937#[ derive( Clone , Debug , Eq , PartialEq ) ]
4038pub struct HttpConcrete {
41- pub dst : Addr ,
39+ pub resolve : Option < Addr > ,
4240 pub logical : HttpLogical ,
4341}
4442
@@ -47,7 +45,7 @@ pub struct LogicalPerRequest(HttpAccept);
4745
4846#[ derive( Clone , Debug ) ]
4947pub struct Profile {
50- pub rx : profiles:: Receiver ,
48+ pub rx : Option < profiles:: Receiver > ,
5149 pub logical : HttpLogical ,
5250}
5351
@@ -81,21 +79,17 @@ impl From<listen::Addrs> for TcpLogical {
8179 }
8280}
8381
82+ /// Used as a default destination when resolution is rejected.
8483impl Into < SocketAddr > for & ' _ TcpLogical {
8584 fn into ( self ) -> SocketAddr {
8685 self . addr
8786 }
8887}
8988
90- impl Into < Addr > for & ' _ TcpLogical {
91- fn into ( self ) -> Addr {
92- self . addr . into ( )
93- }
94- }
95-
96- impl std:: fmt:: Display for TcpLogical {
97- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
98- self . addr . fmt ( f)
89+ /// Used to resolve endpoints.
90+ impl Into < Option < Addr > > for & ' _ TcpLogical {
91+ fn into ( self ) -> Option < Addr > {
92+ Some ( self . addr . into ( ) )
9993 }
10094}
10195
@@ -118,102 +112,63 @@ impl Into<SocketAddr> for &'_ HttpAccept {
118112
119113// === impl HttpConrete ===
120114
121- impl From < ( Addr , Profile ) > for HttpConcrete {
122- fn from ( ( dst, Profile { logical, .. } ) : ( Addr , Profile ) ) -> Self {
123- Self { dst, logical }
124- }
125- }
126-
127- impl AsRef < Addr > for HttpConcrete {
128- fn as_ref ( & self ) -> & Addr {
129- & self . dst
115+ impl From < ( Option < Addr > , Profile ) > for HttpConcrete {
116+ fn from ( ( resolve, Profile { logical, .. } ) : ( Option < Addr > , Profile ) ) -> Self {
117+ Self { resolve, logical }
130118 }
131119}
132120
133- impl Into < Addr > for & ' _ HttpConcrete {
134- fn into ( self ) -> Addr {
135- self . dst . clone ( )
121+ /// Produces an address to resolve to individual endpoints. This address is only
122+ /// present if the initial profile resolution was not rejected.
123+ impl Into < Option < Addr > > for & ' _ HttpConcrete {
124+ fn into ( self ) -> Option < Addr > {
125+ self . resolve . clone ( )
136126 }
137127}
138128
129+ /// Produces an address to be used if resolution is rejected.
139130impl Into < SocketAddr > for & ' _ HttpConcrete {
140131 fn into ( self ) -> SocketAddr {
141- self . dst
142- . socket_addr ( )
132+ self . resolve
133+ . as_ref ( )
134+ . and_then ( |a| a. socket_addr ( ) )
143135 . unwrap_or_else ( || self . logical . orig_dst )
144136 }
145137}
146138
147- impl std:: fmt:: Display for HttpConcrete {
148- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
149- self . dst . fmt ( f)
150- }
151- }
152-
153- impl From < HttpLogical > for HttpConcrete {
154- fn from ( logical : HttpLogical ) -> Self {
155- Self {
156- dst : logical. dst . clone ( ) ,
157- logical,
158- }
159- }
160- }
161-
162139// === impl HttpLogical ===
163140
164- impl std:: fmt:: Display for HttpLogical {
165- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
166- self . dst . fmt ( f)
167- }
168- }
169-
170- impl < ' t > From < & ' t HttpLogical > for http:: header:: HeaderValue {
171- fn from ( target : & ' t HttpLogical ) -> Self {
172- http:: header:: HeaderValue :: from_str ( & target. dst . to_string ( ) )
173- . expect ( "addr must be a valid header" )
174- }
175- }
176-
177- impl Into < SocketAddr > for HttpLogical {
178- fn into ( self ) -> SocketAddr {
179- self . orig_dst
180- }
181- }
182-
141+ /// Produces an address for profile discovery.
183142impl Into < Addr > for & ' _ HttpLogical {
184143 fn into ( self ) -> Addr {
185144 self . dst . clone ( )
186145 }
187146}
188147
148+ /// Needed for canonicalization.
189149impl AsRef < Addr > for HttpLogical {
190150 fn as_ref ( & self ) -> & Addr {
191151 & self . dst
192152 }
193153}
194154
155+ /// Needed for canonicalization.
195156impl AsMut < Addr > for HttpLogical {
196157 fn as_mut ( & mut self ) -> & mut Addr {
197158 & mut self . dst
198159 }
199160}
200161
201- // === impl HttpEndpoint ===
202-
203- impl From < HttpLogical > for HttpEndpoint {
204- fn from ( logical : HttpLogical ) -> Self {
205- Self {
206- addr : logical. orig_dst ,
207- settings : logical. version . into ( ) ,
208- identity : Conditional :: None (
209- tls:: ReasonForNoPeerName :: NotProvidedByServiceDiscovery . into ( ) ,
210- ) ,
211- concrete : logical. into ( ) ,
212- metadata : Metadata :: default ( ) ,
213- }
162+ // Used to set the l5d-canonical-dst header.
163+ impl < ' t > From < & ' t HttpLogical > for http:: header:: HeaderValue {
164+ fn from ( target : & ' t HttpLogical ) -> Self {
165+ http:: header:: HeaderValue :: from_str ( & target. dst . to_string ( ) )
166+ . expect ( "addr must be a valid header" )
214167 }
215168}
216169
170+ // === impl HttpEndpoint ===
171+
217172impl std:: hash:: Hash for HttpEndpoint {
218173 fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
219174 self . addr . hash ( state) ;
@@ -461,8 +416,8 @@ pub fn route((route, profile): (profiles::http::Route, Profile)) -> dst::Route {
461416
462417// === impl Profile ===
463418
464- impl From < ( profiles:: Receiver , HttpLogical ) > for Profile {
465- fn from ( ( rx, logical) : ( profiles:: Receiver , HttpLogical ) ) -> Self {
419+ impl From < ( Option < profiles:: Receiver > , HttpLogical ) > for Profile {
420+ fn from ( ( rx, logical) : ( Option < profiles:: Receiver > , HttpLogical ) ) -> Self {
466421 Self { rx, logical }
467422 }
468423}
@@ -473,14 +428,14 @@ impl AsRef<Addr> for Profile {
473428 }
474429}
475430
476- impl AsRef < profiles :: Receiver > for Profile {
477- fn as_ref ( & self ) -> & profiles :: Receiver {
478- & self . rx
431+ impl Into < Addr > for & ' _ Profile {
432+ fn into ( self ) -> Addr {
433+ self . logical . dst . clone ( )
479434 }
480435}
481436
482- impl From < Profile > for HttpLogical {
483- fn from ( Profile { logical , .. } : Profile ) -> Self {
484- logical
437+ impl Into < Option < profiles :: Receiver > > for & ' _ Profile {
438+ fn into ( self ) -> Option < profiles :: Receiver > {
439+ self . rx . clone ( )
485440 }
486441}
0 commit comments