-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix job execution duration when runner assign time is not set #4472
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -496,7 +496,13 @@ func (e *exporter) RecordJobCompleted(msg *scaleset.JobCompleted) { | |||||||||||||||||||||||||||
| l := e.completedJobLabels(msg) | ||||||||||||||||||||||||||||
| e.incCounter(MetricCompletedJobsTotal, l) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| executionDuration := msg.FinishTime.Unix() - msg.RunnerAssignTime.Unix() | ||||||||||||||||||||||||||||
| // If the runner assign time is not set, it means that the job is never picked up by the runner. | ||||||||||||||||||||||||||||
| // Set execution duration to 0, to observe that the job is completed without being executed. | ||||||||||||||||||||||||||||
| var executionDuration int64 | ||||||||||||||||||||||||||||
| if !msg.RunnerAssignTime.IsZero() { | ||||||||||||||||||||||||||||
| executionDuration = msg.FinishTime.Unix() - msg.RunnerAssignTime.Unix() | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
Comment on lines
+499
to
+505
|
||||||||||||||||||||||||||||
| // If the runner assign time is not set, it means that the job is never picked up by the runner. | |
| // Set execution duration to 0, to observe that the job is completed without being executed. | |
| var executionDuration int64 | |
| if !msg.RunnerAssignTime.IsZero() { | |
| executionDuration = msg.FinishTime.Unix() - msg.RunnerAssignTime.Unix() | |
| } | |
| // If the runner assign time is not set, it means that the job was never picked up by a runner. | |
| // Skip recording execution duration so jobs that never executed do not pollute the histogram. | |
| if msg.RunnerAssignTime.IsZero() { | |
| return | |
| } | |
| executionDuration := msg.FinishTime.Unix() - msg.RunnerAssignTime.Unix() |
Copilot
AI
Apr 24, 2026
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.
This change fixes a production-facing metric edge case, but there are currently no unit tests covering RecordJobCompleted. Please add a test for the zero RunnerAssignTime scenario to ensure we don’t regress back to recording an epoch-sized duration (and to lock in the intended behavior: either skipping the observation or recording a specific value).
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 added comment is a bit misleading/grammatically off: this case means the job was never picked up by a runner, and the wording “Set execution duration to 0, to observe…” reads awkwardly. Consider rephrasing to past tense and clarifying that there was no execution phase (especially if you keep recording 0s).