Skip to content

Commit 0682683

Browse files
committed
address review feedback on processing latency metrics
Signed-off-by: satyamg1620 <Satyam.Gupta.3@ibm.com>
1 parent 38ebbff commit 0682683

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

pkg/epp/handlers/server.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ func (s *StreamingServer) Process(srv extProcPb.ExternalProcessor_ProcessServer)
269269
},
270270
}
271271

272+
// Record EPP response processing latency once when the stream ends. Using a
273+
// defer (rather than emitting on end-of-stream) ensures aborted streams
274+
// (client cancel or upstream error before EOS) are also recorded, so the
275+
// metric is not biased toward fully streamed responses. The guard skips
276+
// requests that never reached the response phase.
277+
defer func() {
278+
if reqCtx.responseProcessingDuration > 0 {
279+
metrics.RecordResponseProcessingLatency(reqCtx.responseProcessingDuration)
280+
}
281+
}()
282+
272283
buf := s.bufferPool.Get().(*bytes.Buffer)
273284
buf.Reset()
274285
defer func() {
@@ -501,9 +512,6 @@ func (s *StreamingServer) Process(srv extProcPb.ExternalProcessor_ProcessServer)
501512
// For streaming response, we send response chunk back to envoy every time we received it.
502513
reqCtx.respBodyResp = generateResponseBodyResponses(chunk, endOfStream, reqCtx.Response.DynamicMetadata)
503514
reqCtx.responseProcessingDuration += time.Since(respBodyStart)
504-
if endOfStream {
505-
metrics.RecordResponseProcessingLatency(reqCtx.responseProcessingDuration)
506-
}
507515
} else {
508516
respBody = append(respBody, chunk...)
509517
if endOfStream {
@@ -575,7 +583,6 @@ func (s *StreamingServer) finishResponse(ctx context.Context, reqCtx *RequestCon
575583
reqCtx.respBodyResp = generateResponseBodyResponses(body, setEos, reqCtx.Response.DynamicMetadata)
576584
}
577585
reqCtx.responseProcessingDuration += time.Since(start)
578-
metrics.RecordResponseProcessingLatency(reqCtx.responseProcessingDuration)
579586
}
580587

581588
// rewriteModelName replaces occurrences of the target (internal) model name with the

pkg/epp/metrics/llm_d_router_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ var (
257257
prometheus.HistogramOpts{
258258
Subsystem: LLMDRouterEndpointPickerSubsystem,
259259
Name: "request_processing_duration_seconds",
260-
Help: metricsutil.HelpMsgWithStability("EPP request processing latency distribution in seconds, from request receipt until an endpoint is selected, excluding flow-control admission wait.", compbasemetrics.ALPHA),
260+
Help: metricsutil.HelpMsgWithStability("EPP request orchestration latency distribution in seconds, from request receipt through endpoint selection and request preparation, excluding admission-control time.", compbasemetrics.ALPHA),
261261
Buckets: []float64{
262262
0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1,
263263
},

pkg/epp/metrics/testdata/llm_d_request_processing_duration_seconds_metric

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# HELP llm_d_router_epp_request_processing_duration_seconds [ALPHA] EPP request processing latency distribution in seconds, from request receipt until an endpoint is selected, excluding flow-control admission wait.
1+
# HELP llm_d_router_epp_request_processing_duration_seconds [ALPHA] EPP request orchestration latency distribution in seconds, from request receipt through endpoint selection and request preparation, excluding admission-control time.
22
# TYPE llm_d_router_epp_request_processing_duration_seconds histogram
33
llm_d_router_epp_request_processing_duration_seconds_bucket{le="0.0001"} 0
44
llm_d_router_epp_request_processing_duration_seconds_bucket{le="0.0002"} 1

pkg/epp/requestcontrol/director.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,11 @@ func (d *Director) getInferenceObjective(ctx context.Context, reqCtx *handlers.R
234234
func (d *Director) HandleRequest(ctx context.Context, reqCtx *handlers.RequestContext, inferenceRequestBody *fwkrh.InferenceRequestBody) (_ *handlers.RequestContext, err error) {
235235
start := time.Now()
236236
var admissionWait time.Duration
237-
// request_processing_duration captures EPP's own processing cost, so the
238-
// flow-control admission wait (tracked separately by
239-
// flow_control_request_queue_duration_seconds) is subtracted out.
237+
// request_processing_duration measures EPP's own orchestration cost for a
238+
// request (receipt through endpoint selection and request preparation). Time
239+
// spent in admission control is subtracted: under flow control it is
240+
// dominated by the queue wait, which is load- rather than EPP-driven and is
241+
// tracked separately by flow_control_request_queue_duration_seconds.
240242
defer func() { metrics.RecordRequestProcessingLatency(time.Since(start) - admissionWait) }()
241243

242244
tracer := tracing.Tracer("llm-d-router/pkg/epp/requestcontrol")

0 commit comments

Comments
 (0)