Fix queue_duration metric to use queued_at instead of created_at#753
Open
Fix queue_duration metric to use queued_at instead of created_at#753
Conversation
Co-authored-by: yanksyoon <37652070+yanksyoon@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add access to queued_at timestamps for scheduled events
Fix queue_duration metric to use queued_at instead of created_at
Mar 16, 2026
The GitHub API may not always return queued_at for older jobs. Changed to use .get() method and made queued_at optional in type definitions. The metrics calculation now falls back to created_at when queued_at is not available, maintaining backward compatibility.
1a9b8f6 to
0d564f9
Compare
yhaliaw
approved these changes
Mar 24, 2026
Collaborator
yhaliaw
left a comment
There was a problem hiding this comment.
Good catch.
One question to clarify things.
| raise GithubMetricsError from exc | ||
|
|
||
| queue_duration = (job_info.started_at - job_info.created_at).total_seconds() | ||
| queued_or_created_at = job_info.queued_at or job_info.created_at |
Collaborator
There was a problem hiding this comment.
Is this a fail safe in case queued_at is missing?
Is it often that queued_at is missing?
Member
There was a problem hiding this comment.
Yup, it's a failsafe - the field queued_at exists for job_info for all the jobs but is null from all the API responses that I've tested. I'm not entirely sure when it gets set to null and when it has a set value (the documentation does not exist), but this should set us back to the original behavior.
florentianayuwono
approved these changes
Mar 24, 2026
Member
|
Quick GitHub API verification with list jobs & runs returns payload with queued_at field set to null. Enquired GitHub support again. |
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.
GitHub support confirmed
created_atis not the correct timestamp for measuring runner wait time —queued_atis when the job was actually placed in the runner queue. The previous formula (started_at - created_at) overstates queue duration.Overview
Replace
created_atwithqueued_atin thequeue_durationcalculation:Rationale
Per GitHub support,
queued_atis the timestamp when a job enters the runner queue.created_atprecedes this and inflates the metric. The GitHub REST API (/repos/{owner}/{repo}/actions/runs/{run_id}/jobs) returnsqueued_atper job and is the documented way to measure runner wait time.Juju Events Changes
None.
Module Changes
types_/github.py: Addedqueued_at: datetimeto theJobInfopydantic model.platform/platform_provider.py: Addedqueued_at: datetimeto theJobInfodataclass.github_client.py:_to_job_info()now extractsqueued_atfrom the API response.platform/github_provider.py:get_job_info()passesqueued_atthrough toplatform_provider.JobInfo.metrics/github.py:queue_durationnow computed asstarted_at - queued_at.Library Changes
None.
Checklist
urgent,trivial,complex).github-runner-manager/pyproject.toml.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.