@@ -521,9 +521,14 @@ func (d *Director) HandleResponseHeader(ctx context.Context, reqCtx *handlers.Re
521521// to the ext_proc response sent back to Envoy.
522522func (d * Director ) HandleResponseBody (ctx context.Context , reqCtx * handlers.RequestContext , endOfStream bool ) * handlers.RequestContext {
523523 logger := log .FromContext (ctx ).WithValues ("stage" , "bodyChunk" )
524- logger .V (logutil .TRACE ).Info ("Entering HandleResponseBodyChunk" )
524+ loggerTrace := logger .V (logutil .TRACE )
525+ if loggerTrace .Enabled () {
526+ loggerTrace .Info ("Entering HandleResponseBodyChunk" )
527+ }
525528 if len (d .requestControlPlugins .responseStreamingPlugins ) == 0 {
526- logger .V (logutil .TRACE ).Info ("Exiting HandleResponseBodyChunk" )
529+ if loggerTrace .Enabled () {
530+ loggerTrace .Info ("Exiting HandleResponseBodyChunk" )
531+ }
527532 return reqCtx
528533 }
529534
@@ -536,7 +541,6 @@ func (d *Director) HandleResponseBody(ctx context.Context, reqCtx *handlers.Requ
536541 EndOfStream : endOfStream ,
537542 Usage : reqCtx .Usage ,
538543 }
539- requestID := reqCtx .Request .Headers [reqcommon .RequestIDHeaderKey ]
540544
541545 if endOfStream {
542546 // Drain the async queue: close the channel and wait for the goroutine to finish
@@ -558,10 +562,13 @@ func (d *Director) HandleResponseBody(ctx context.Context, reqCtx *handlers.Requ
558562 }
559563 q := d .loadOrCreateResponseBodyQueue (reqCtx )
560564 if ! q .enqueue (work ) {
561- logger .V (logutil .DEBUG ).Info ("Skipping response body chunk because the async queue is closed" , "requestID" , requestID )
565+ logger .V (logutil .DEBUG ).Info ("Skipping response body chunk because the async queue is closed" ,
566+ "requestID" , reqCtx .Request .Headers [reqcommon .RequestIDHeaderKey ])
562567 }
563568 }
564- logger .V (logutil .TRACE ).Info ("Exiting HandleResponseBodyChunk" )
569+ if loggerTrace .Enabled () {
570+ loggerTrace .Info ("Exiting HandleResponseBodyChunk" )
571+ }
565572 return reqCtx
566573}
567574
@@ -592,11 +599,12 @@ func (d *Director) runPreRequestPlugins(ctx context.Context, request *fwksched.I
592599 schedulingResult * fwksched.SchedulingResult ) {
593600 loggerDebug := log .FromContext (ctx ).V (logutil .DEBUG )
594601 for _ , plugin := range d .requestControlPlugins .preRequestPlugins {
595- loggerDebug .Info ("Running PreRequest plugin" , "plugin" , plugin .TypedName ())
602+ tn := plugin .TypedName ()
603+ loggerDebug .Info ("Running PreRequest plugin" , "plugin" , tn )
596604 before := time .Now ()
597605 plugin .PreRequest (ctx , request , schedulingResult )
598- metrics .RecordPluginProcessingLatency (fwkrc .PreRequestExtensionPoint , plugin . TypedName (). Type , plugin . TypedName () .Name , time .Since (before ))
599- loggerDebug .Info ("Completed running PreRequest plugin successfully" , "plugin" , plugin . TypedName () )
606+ metrics .RecordPluginProcessingLatency (fwkrc .PreRequestExtensionPoint , tn . Type , tn .Name , time .Since (before ))
607+ loggerDebug .Info ("Completed running PreRequest plugin successfully" , "plugin" , tn )
600608 }
601609}
602610
@@ -606,13 +614,14 @@ func (d *Director) runRequestHeaderProcessors(ctx context.Context, request *fwks
606614 }
607615 loggerDebug := log .FromContext (ctx ).V (logutil .DEBUG )
608616 for _ , plugin := range d .requestControlPlugins .requestHeaderPlugins {
609- loggerDebug .Info ("Running RequestHeaderProcessor plugin" , "plugin" , plugin .TypedName ())
617+ tn := plugin .TypedName ()
618+ loggerDebug .Info ("Running RequestHeaderProcessor plugin" , "plugin" , tn )
610619 before := time .Now ()
611620 if err := plugin .RequestHeader (ctx , request ); err != nil {
612621 return err
613622 }
614- metrics .RecordPluginProcessingLatency (fwkrc .RequestHeaderExtensionPoint , plugin . TypedName (). Type , plugin . TypedName () .Name , time .Since (before ))
615- loggerDebug .Info ("Completed running RequestHeaderProcessor plugin successfully" , "plugin" , plugin . TypedName () )
623+ metrics .RecordPluginProcessingLatency (fwkrc .RequestHeaderExtensionPoint , tn . Type , tn .Name , time .Since (before ))
624+ loggerDebug .Info ("Completed running RequestHeaderProcessor plugin successfully" , "plugin" , tn )
616625 }
617626 return nil
618627}
@@ -637,38 +646,45 @@ func (d *Director) runAdmissionPlugins(ctx context.Context,
637646 request * fwksched.InferenceRequest , endpoints []fwksched.Endpoint ) error {
638647 loggerDebug := log .FromContext (ctx ).V (logutil .DEBUG )
639648 for _ , plugin := range d .requestControlPlugins .admissionPlugins {
640- loggerDebug .Info ("Running Admit plugin" , "plugin" , plugin .TypedName ())
649+ tn := plugin .TypedName ()
650+ loggerDebug .Info ("Running Admit plugin" , "plugin" , tn )
641651 before := time .Now ()
642652 denyReason := plugin .Admit (ctx , request , endpoints )
643- metrics .RecordPluginProcessingLatency (fwkrc .AdmissionExtensionPoint , plugin . TypedName (). Type , plugin . TypedName () .Name , time .Since (before ))
653+ metrics .RecordPluginProcessingLatency (fwkrc .AdmissionExtensionPoint , tn . Type , tn .Name , time .Since (before ))
644654 if denyReason != nil {
645- loggerDebug .Info ("Admit plugin denied the request" , "plugin" , plugin . TypedName () , "reason" , denyReason .Error ())
655+ loggerDebug .Info ("Admit plugin denied the request" , "plugin" , tn , "reason" , denyReason .Error ())
646656 return denyReason
647657 }
648- loggerDebug .Info ("Completed running Admit plugin successfully" , "plugin" , plugin . TypedName () )
658+ loggerDebug .Info ("Completed running Admit plugin successfully" , "plugin" , tn )
649659 }
650660 return nil
651661}
652662
653663func (d * Director ) runResponseHeaderPlugins (ctx context.Context , request * fwksched.InferenceRequest , response * fwkrc.Response , targetEndpoint * fwkdl.EndpointMetadata ) {
654664 loggerDebug := log .FromContext (ctx ).V (logutil .DEBUG )
655665 for _ , plugin := range d .requestControlPlugins .responseReceivedPlugins {
656- loggerDebug .Info ("Running ResponseReceived plugin" , "plugin" , plugin .TypedName ())
666+ tn := plugin .TypedName ()
667+ loggerDebug .Info ("Running ResponseReceived plugin" , "plugin" , tn )
657668 before := time .Now ()
658669 plugin .ResponseHeader (ctx , request , response , targetEndpoint )
659- metrics .RecordPluginProcessingLatency (fwkrc .ResponseReceivedExtensionPoint , plugin . TypedName (). Type , plugin . TypedName () .Name , time .Since (before ))
660- loggerDebug .Info ("Completed running ResponseReceived plugin successfully" , "plugin" , plugin . TypedName () )
670+ metrics .RecordPluginProcessingLatency (fwkrc .ResponseReceivedExtensionPoint , tn . Type , tn .Name , time .Since (before ))
671+ loggerDebug .Info ("Completed running ResponseReceived plugin successfully" , "plugin" , tn )
661672 }
662673}
663674
664675func (d * Director ) runResponseBodyPlugins (ctx context.Context , request * fwksched.InferenceRequest , response * fwkrc.Response , targetEndpoint * fwkdl.EndpointMetadata ) {
665676 loggerTrace := log .FromContext (ctx ).V (logutil .TRACE )
666677 for _ , plugin := range d .requestControlPlugins .responseStreamingPlugins {
667- loggerTrace .Info ("Running ResponseStreaming plugin" , "plugin" , plugin .TypedName ())
678+ tn := plugin .TypedName ()
679+ if loggerTrace .Enabled () {
680+ loggerTrace .Info ("Running ResponseStreaming plugin" , "plugin" , tn )
681+ }
668682 before := time .Now ()
669683 plugin .ResponseBody (ctx , request , response , targetEndpoint )
670- metrics .RecordPluginProcessingLatency (fwkrc .ResponseStreamingExtensionPoint , plugin .TypedName ().Type , plugin .TypedName ().Name , time .Since (before ))
671- loggerTrace .Info ("Completed running ResponseStreaming plugin successfully" , "plugin" , plugin .TypedName ())
684+ metrics .RecordPluginProcessingLatency (fwkrc .ResponseStreamingExtensionPoint , tn .Type , tn .Name , time .Since (before ))
685+ if loggerTrace .Enabled () {
686+ loggerTrace .Info ("Completed running ResponseStreaming plugin successfully" , "plugin" , tn )
687+ }
672688 }
673689}
674690
0 commit comments