@@ -26,6 +26,7 @@ struct LogicalPerRequest {
2626 server : Remote < ServerAddr > ,
2727 tls : tls:: ConditionalServerTls ,
2828 permit : policy:: Permit ,
29+ labels : tap:: Labels ,
2930}
3031
3132/// Describes a logical request target.
@@ -37,6 +38,7 @@ struct Logical {
3738 http : http:: Version ,
3839 tls : tls:: ConditionalServerTls ,
3940 permit : policy:: Permit ,
41+ labels : tap:: Labels ,
4042}
4143
4244/// Describes a resolved profile for a logical service.
@@ -222,12 +224,7 @@ impl<C> Inbound<C> {
222224 // dispatches the request. NewRouter moves the NewService into the service type, so
223225 // minimize it's type footprint with a Box.
224226 . push ( svc:: BoxNewService :: layer ( ) )
225- . push ( svc:: NewRouter :: layer ( |( permit, t) : ( _ , T ) | LogicalPerRequest {
226- client : t. param ( ) ,
227- server : t. param ( ) ,
228- tls : t. param ( ) ,
229- permit,
230- } ) )
227+ . push ( svc:: NewRouter :: layer ( LogicalPerRequest :: from) )
231228 . push ( policy:: NewAuthorizeHttp :: layer ( rt. metrics . http_authz . clone ( ) ) )
232229 // Used by tap.
233230 . push_http_insert_target :: < tls:: ConditionalServerTls > ( )
@@ -239,6 +236,31 @@ impl<C> Inbound<C> {
239236
240237// === impl LogicalPerRequest ===
241238
239+ impl < T > From < ( policy:: Permit , T ) > for LogicalPerRequest
240+ where
241+ T : Param < Remote < ServerAddr > > ,
242+ T : Param < Remote < ClientAddr > > ,
243+ T : Param < tls:: ConditionalServerTls > ,
244+ {
245+ fn from ( ( permit, t) : ( policy:: Permit , T ) ) -> Self {
246+ let labels = vec ! [
247+ ( "srv_name" . to_string( ) , permit. labels. server. to_string( ) ) ,
248+ ( "saz_name" . to_string( ) , permit. labels. authz. to_string( ) ) ,
249+ ] ;
250+
251+ Self {
252+ client : t. param ( ) ,
253+ server : t. param ( ) ,
254+ tls : t. param ( ) ,
255+ permit,
256+ labels : labels
257+ . into_iter ( )
258+ . collect :: < std:: collections:: BTreeMap < _ , _ > > ( )
259+ . into ( ) ,
260+ }
261+ }
262+ }
263+
242264impl < A > svc:: stack:: RecognizeRoute < http:: Request < A > > for LogicalPerRequest {
243265 type Key = Logical ;
244266
@@ -274,6 +296,7 @@ impl<A> svc::stack::RecognizeRoute<http::Request<A>> for LogicalPerRequest {
274296 . version ( )
275297 . try_into ( )
276298 . expect ( "HTTP version must be valid" ) ,
299+ labels : self . labels . clone ( ) ,
277300 } )
278301 }
279302}
@@ -344,16 +367,15 @@ impl tap::Inspect for Logical {
344367 Some ( self . addr . into ( ) )
345368 }
346369
347- fn dst_labels < B > ( & self , _: & http:: Request < B > ) -> Option < & tap:: Labels > {
348- // TODO include policy labels here.
349- None
370+ fn dst_labels < B > ( & self , _: & http:: Request < B > ) -> Option < tap:: Labels > {
371+ Some ( self . labels . clone ( ) )
350372 }
351373
352374 fn dst_tls < B > ( & self , _: & http:: Request < B > ) -> tls:: ConditionalClientTls {
353375 tls:: ConditionalClientTls :: None ( tls:: NoClientTls :: Loopback )
354376 }
355377
356- fn route_labels < B > ( & self , req : & http:: Request < B > ) -> Option < std :: sync :: Arc < tap:: Labels > > {
378+ fn route_labels < B > ( & self , req : & http:: Request < B > ) -> Option < tap:: Labels > {
357379 req. extensions ( )
358380 . get :: < dst:: Route > ( )
359381 . map ( |r| r. route . labels ( ) . clone ( ) )
0 commit comments