Skip to content

Fix job execution duration when runner assign time is not set#4472

Open
nikola-jokic wants to merge 2 commits intomasterfrom
nikola-jokic/no-runner-assigned-time-job-completed
Open

Fix job execution duration when runner assign time is not set#4472
nikola-jokic wants to merge 2 commits intomasterfrom
nikola-jokic/no-runner-assigned-time-job-completed

Conversation

@nikola-jokic
Copy link
Copy Markdown
Collaborator

@nikola-jokic nikola-jokic commented Apr 24, 2026

Fixes #4444
Fixes #3731

Copilot AI review requested due to automatic review settings April 24, 2026 08:23
@nikola-jokic nikola-jokic added the gha-runner-scale-set Related to the gha-runner-scale-set mode label Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hello! Thank you for your contribution.

Please review our contribution guidelines to understand the project's testing and code conventions.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an edge case in gha_job_execution_duration_seconds where jobs completed before runner assignment could yield an epoch-sized duration.

Changes:

  • Add a RunnerAssignTime.IsZero() check when computing job execution duration.
  • Record an execution duration of 0 when the runner was never assigned.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/ghalistener/metrics/metrics.go Outdated
Comment thread cmd/ghalistener/metrics/metrics.go Outdated
Comment on lines 501 to 506
var executionDuration int64
if !msg.RunnerAssignTime.IsZero() {
executionDuration = msg.FinishTime.Unix() - msg.RunnerAssignTime.Unix()
}

e.observeHistogram(MetricJobExecutionDurationSeconds, l, float64(executionDuration))
Copy link

Copilot AI Apr 24, 2026

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).

Copilot uses AI. Check for mistakes.
Comment thread cmd/ghalistener/metrics/metrics.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/ghalistener/metrics/metrics.go Outdated
Comment on lines 496 to 501
if !msg.RunnerAssignTime.IsZero() {
return
}

l := e.completedJobLabels(msg)
e.incCounter(MetricCompletedJobsTotal, l)
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RunnerAssignTime.IsZero() guard is inverted and causes RecordJobCompleted to return for the normal (non-zero) case while still observing the huge epoch-based duration for the zero-value case. Also, because the return happens before completedJobLabels/gha_completed_jobs_total increment, this change would stop counting completed jobs entirely when RunnerAssignTime is set.

Flip the condition to return only when RunnerAssignTime is zero, and move the early return to after incrementing MetricCompletedJobsTotal so canceled-before-assignment jobs are still counted but duration observation is skipped.

Suggested change
if !msg.RunnerAssignTime.IsZero() {
return
}
l := e.completedJobLabels(msg)
e.incCounter(MetricCompletedJobsTotal, l)
l := e.completedJobLabels(msg)
e.incCounter(MetricCompletedJobsTotal, l)
if msg.RunnerAssignTime.IsZero() {
return
}

Copilot uses AI. Check for mistakes.
Comment thread cmd/ghalistener/metrics/metrics.go Outdated
Comment on lines 496 to 501
if !msg.RunnerAssignTime.IsZero() {
return
}

l := e.completedJobLabels(msg)
e.incCounter(MetricCompletedJobsTotal, l)
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces new branching behavior in RecordJobCompleted (skip observation when RunnerAssignTime is unset) but there are no unit tests asserting the expected metric effects. Please add a test that covers both cases:

  • non-zero RunnerAssignTime: increments gha_completed_jobs_total and observes a reasonable gha_job_execution_duration_seconds value
  • zero RunnerAssignTime: still increments gha_completed_jobs_total but does not observe gha_job_execution_duration_seconds

This will prevent regressions like an accidentally inverted IsZero() check.

Suggested change
if !msg.RunnerAssignTime.IsZero() {
return
}
l := e.completedJobLabels(msg)
e.incCounter(MetricCompletedJobsTotal, l)
l := e.completedJobLabels(msg)
e.incCounter(MetricCompletedJobsTotal, l)
if msg.RunnerAssignTime.IsZero() {
return
}

Copilot uses AI. Check for mistakes.
@nikola-jokic nikola-jokic force-pushed the nikola-jokic/no-runner-assigned-time-job-completed branch from 83f6619 to 74bce34 Compare April 29, 2026 21:59
@nikola-jokic nikola-jokic requested a review from Copilot April 29, 2026 21:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gha-runner-scale-set Related to the gha-runner-scale-set mode

Projects

None yet

2 participants