-
Notifications
You must be signed in to change notification settings - Fork 292
Add EPP request/response processing latency metrics #1658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd88771
add EPP request/response processing latency metrics
satyamg1620 6359ce1
address review feedback on processing latency metrics
satyamg1620 e5cbb5c
fix subsystem prefix in processing latency metric tests
satyamg1620 59a5cbf
Measure EPP processing latency at the handler boundary
satyamg1620 93a9bc1
Assert EPP processing latency metrics in e2e preset
satyamg1620 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,14 @@ type RequestContext struct { | |
| RequestDroppedReason errcommon.RequestDroppedReason | ||
| modelServerStreaming bool | ||
|
|
||
| // responseProcessingDuration is the EPP cost of handling the response. For a | ||
| // streamed response it is the sum of the per-chunk handler slices, since the | ||
| // gaps between chunks are model server generation time. For a non-streaming | ||
| // response it is the single interval from responseHeadersReceivedAt onward, | ||
| // during which the response is entirely in EPP's hands. | ||
| responseProcessingDuration time.Duration | ||
| responseHeadersReceivedAt time.Time | ||
|
|
||
| Response *Response | ||
|
|
||
| reqHeaderResp *extProcPb.ProcessingResponse | ||
|
|
@@ -265,6 +273,25 @@ func (s *StreamingServer) Process(srv extProcPb.ExternalProcessor_ProcessServer) | |
| }, | ||
| } | ||
|
|
||
| // Request-phase failures (parser resolution, body parsing, admission | ||
| // rejection) leave the switch before the success path, so both call this. | ||
| // Flow-control rejections carry the queue wait and are the slowest samples; | ||
| // dropping them would bias the histogram low. | ||
| recordRequestProcessing := sync.OnceFunc(func() { | ||
| metrics.RecordRequestProcessingLatency(time.Since(reqCtx.RequestReceivedTimestamp)) | ||
| }) | ||
|
|
||
| // Record EPP response processing latency once when the stream ends. Using a | ||
| // defer (rather than emitting on end-of-stream) ensures aborted streams | ||
| // (client cancel or upstream error before EOS) are also recorded, so the | ||
| // metric is not biased toward fully streamed responses. The guard skips | ||
| // requests that never reached the response phase. | ||
| defer func() { | ||
| if reqCtx.responseProcessingDuration > 0 { | ||
| metrics.RecordResponseProcessingLatency(reqCtx.responseProcessingDuration) | ||
| } | ||
| }() | ||
|
|
||
| buf := s.bufferPool.Get().(*bytes.Buffer) | ||
| buf.Reset() | ||
| defer func() { | ||
|
|
@@ -461,10 +488,13 @@ func (s *StreamingServer) Process(srv extProcPb.ExternalProcessor_ProcessServer) | |
| if parseResult.SkipResponseProcessing { | ||
| reqCtx.RequestState = RequestResponseProcessingSkipped | ||
| } | ||
|
|
||
| recordRequestProcessing() | ||
| } | ||
| case *extProcPb.ProcessingRequest_RequestTrailers: | ||
| // This is currently unused. | ||
| case *extProcPb.ProcessingRequest_ResponseHeaders: | ||
| respHeadersReceivedAt := time.Now() | ||
| for _, header := range v.ResponseHeaders.Headers.GetHeaders() { | ||
| value := string(header.RawValue) | ||
| loggerTrace.Info("header", "key", header.Key, "value", value) | ||
|
|
@@ -478,12 +508,15 @@ func (s *StreamingServer) Process(srv extProcPb.ExternalProcessor_ProcessServer) | |
| reqCtx.RequestState = ResponseReceived | ||
| reqCtx = s.HandleResponseHeaders(ctx, reqCtx, v) | ||
| reqCtx.respHeaderResp = s.generateResponseHeaderResponse(reqCtx) | ||
| reqCtx.responseHeadersReceivedAt = respHeadersReceivedAt | ||
| reqCtx.responseProcessingDuration += time.Since(respHeadersReceivedAt) | ||
|
|
||
| case *extProcPb.ProcessingRequest_ResponseBody: | ||
| endOfStream := v.ResponseBody.EndOfStream | ||
| chunk := v.ResponseBody.Body | ||
|
|
||
| if reqCtx.modelServerStreaming { | ||
| respBodyStart := time.Now() | ||
| if endOfStream { | ||
| reqCtx.ResponseComplete = true | ||
| reqCtx.ResponseCompleteTimestamp = time.Now() | ||
|
|
@@ -493,6 +526,7 @@ func (s *StreamingServer) Process(srv extProcPb.ExternalProcessor_ProcessServer) | |
| chunk = rewriteModelName(chunk, reqCtx.TargetModelName, reqCtx.IncomingModelName) | ||
| // For streaming response, we send response chunk back to envoy every time we received it. | ||
| reqCtx.respBodyResp = generateResponseBodyResponses(chunk, endOfStream, reqCtx.Response.DynamicMetadata) | ||
| reqCtx.responseProcessingDuration += time.Since(respBodyStart) | ||
| } else { | ||
| respBody = append(respBody, chunk...) | ||
| if endOfStream { | ||
|
|
@@ -513,6 +547,7 @@ func (s *StreamingServer) Process(srv extProcPb.ExternalProcessor_ProcessServer) | |
|
|
||
| // Handle the err and fire an immediate response. | ||
| if err != nil { | ||
| recordRequestProcessing() | ||
| if logger.V(logutil.DEBUG).Enabled() { | ||
| logger.V(logutil.DEBUG).Error(err, "Failed to process request", "request", req) | ||
| } else { | ||
|
|
@@ -553,6 +588,7 @@ func (s *StreamingServer) finishResponse(ctx context.Context, reqCtx *RequestCon | |
| return | ||
| } | ||
|
|
||
| start := time.Now() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the start time should be when response headers are received |
||
| reqCtx.ResponseComplete = true | ||
| reqCtx.ResponseCompleteTimestamp = time.Now() | ||
| reqCtx = s.HandleResponseBody(ctx, reqCtx, body, true) | ||
|
|
@@ -562,6 +598,13 @@ func (s *StreamingServer) finishResponse(ctx context.Context, reqCtx *RequestCon | |
| // For non-streaming response, we send response back to envoy after receiving all the response body. | ||
| reqCtx.respBodyResp = generateResponseBodyResponses(body, setEos, reqCtx.Response.DynamicMetadata) | ||
| } | ||
| if modelStreaming || reqCtx.responseHeadersReceivedAt.IsZero() { | ||
| reqCtx.responseProcessingDuration += time.Since(start) | ||
| } else { | ||
| // Supersedes the header slice already accumulated: the interval since the | ||
| // response headers arrived covers it and the body wait in between. | ||
| reqCtx.responseProcessingDuration = time.Since(reqCtx.responseHeadersReceivedAt) | ||
| } | ||
| } | ||
|
|
||
| // rewriteModelName replaces occurrences of the target (internal) model name with the | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
pkg/epp/metrics/testdata/llm_d_request_processing_duration_seconds_metric
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # HELP llm_d_epp_request_processing_duration_seconds [ALPHA] EPP request processing latency distribution in seconds, from request receipt until the request body has been handled, including admission control. | ||
| # TYPE llm_d_epp_request_processing_duration_seconds histogram | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.0005"} 1 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.001"} 2 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.002"} 3 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.005"} 4 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.01"} 5 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.015"} 6 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.025"} 6 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.04"} 7 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.06"} 7 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.1"} 8 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.25"} 9 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="0.5"} 9 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="1"} 9 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="2.5"} 9 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="5"} 9 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="10"} 9 | ||
| llm_d_epp_request_processing_duration_seconds_bucket{le="+Inf"} 9 | ||
| llm_d_epp_request_processing_duration_seconds_sum 0.2835 | ||
| llm_d_epp_request_processing_duration_seconds_count 9 |
20 changes: 20 additions & 0 deletions
20
pkg/epp/metrics/testdata/llm_d_response_processing_duration_seconds_metric
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # HELP llm_d_epp_response_processing_duration_seconds [ALPHA] EPP response processing latency distribution in seconds: the sum of per-chunk handler time for a streamed response, or the interval from response headers to completion for a non-streaming response. | ||
| # TYPE llm_d_epp_response_processing_duration_seconds histogram | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.0001"} 0 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.00025"} 1 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.0005"} 1 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.001"} 2 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.0025"} 3 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.005"} 4 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.01"} 5 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.025"} 6 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.05"} 7 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.1"} 8 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.25"} 9 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="0.5"} 9 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="1"} 9 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="2.5"} 9 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="5"} 9 | ||
| llm_d_epp_response_processing_duration_seconds_bucket{le="+Inf"} 9 | ||
| llm_d_epp_response_processing_duration_seconds_sum 0.2835 | ||
| llm_d_epp_response_processing_duration_seconds_count 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The start should strictly be measured when headers are received because body should come after.