feat: add per-phase histogram metrics to engine worker pipeline - #21547
Merged
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Final EOF read's compute time is silently discarded
- The drain loop now records and accumulates compute duration for successful reads and the EOF read before breaking, so task compute timing includes the final pass.
Or push these changes by commenting:
@cursor push d7a30c883a
Preview (d7a30c883a)
diff --git a/pkg/engine/internal/worker/thread.go b/pkg/engine/internal/worker/thread.go
--- a/pkg/engine/internal/worker/thread.go
+++ b/pkg/engine/internal/worker/thread.go
@@ -347,13 +347,15 @@
startCompute := time.Now()
rec, err := pipeline.Read(ctx)
computeDuration := time.Since(startCompute)
+ if err == nil || errors.Is(err, executor.EOF) {
+ t.Metrics.passComputeSeconds.Observe(computeDuration.Seconds())
+ totalComputeTime += computeDuration
+ }
if err != nil && errors.Is(err, executor.EOF) {
break
} else if err != nil {
return totalRows, err
}
- t.Metrics.passComputeSeconds.Observe(computeDuration.Seconds())
- totalComputeTime += computeDuration
region.Record(xcap.TaskDrainRecordsReceived.Observe(1))
totalRows += int(rec.NumRows())You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 64bb7ba. Configure here.
rfratto
approved these changes
Apr 15, 2026
rfratto
left a comment
Member
There was a problem hiding this comment.
LGTM, though Cursor is right here that we're not observing the time it takes to compute the final record where EOF is expected.
Segflow
force-pushed
the
meher/histogram-per-phase-timing
branch
from
April 17, 2026 10:45
fc0fc17 to
b990a04
Compare
This was referenced Apr 20, 2026
This was referenced May 20, 2026
This was referenced Jun 8, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


What this PR does / why we need it:
Adds native histogram metrics to instrument the three phases (read, compute, write) of the engine worker's
drainPipelineloop, giving visibility into where time is spent during task execution.Two granularity levels are introduced:
Per-pass metrics — one observation per loop iteration in
drainPipeline:loki_engine_worker_pass_compute_seconds— duration of a singlepipeline.Read(compute) callloki_engine_worker_pass_write_seconds— duration of sending a single record batch to sinksPer-task metrics — one observation per
drainPipelineinvocation:loki_engine_worker_task_read_seconds— time spent inpipeline.Open(read/init phase)loki_engine_worker_task_compute_seconds— cumulative compute time across all passesloki_engine_worker_task_write_seconds— cumulative write time across all passesAll histograms use native histogram buckets (factor 1.1, max 100 buckets, 1h min reset).
Which issue(s) this PR fixes:
N/A
Special notes for your reviewer:
N/A
Checklist
CONTRIBUTING.mdguide (required)docs/sources/setup/upgrade/_index.mddeprecated-config.yamlanddeleted-config.yamlfiles respectively in thetools/deprecated-config-checkerdirectory. Example PRNote
Low Risk
Low risk: adds Prometheus native-histogram observations around existing
drainPipelinephases without changing task execution behavior.Overview
Adds new Prometheus native histograms on the worker to track per-pass
pipeline.Read(compute) and sink send (write) durations, plus per-task totals forpipeline.Open(read/init) and accumulated compute/write time across the drain loop.Updates
thread.drainPipelineto time and record these phase metrics (and reuse the measured write duration for existingxcap.TaskSendDuration), and adjustsTestThread_drainPipelineto initializethread.Metrics.Reviewed by Cursor Bugbot for commit b990a04. Bugbot is set up for automated code reviews on this repo. Configure here.