Skip to content

Support repository-wide workflow metrics and job step durations - #868

Open
uzairchhapra wants to merge 2 commits into
grafana:mainfrom
uzairchhapra:feat/repository-workflow-metrics
Open

uzairchhapra wants to merge 2 commits into
grafana:mainfrom
uzairchhapra:feat/repository-workflow-metrics

Conversation

@uzairchhapra

Copy link
Copy Markdown

Type of Change

  • 🚀 Feature

Feature

What is this feature?

Leave Workflow blank in Workflow Runs to return repository-wide runs using GitHub's repository Actions endpoint. Existing workflow ID and file name filters still work. The new Workflow Job Steps query uses the same optional filters and exposes per-step duration for bottleneck dashboards.

Why is this needed?

Dashboards should be able to count run outcomes across a repository without enumerating workflows. The step query also provides the step-level durations requested in #326.

How to test

  1. In Grafana Explore, use the GitHub data source and set Owner grafana, Repository github-datasource, and the UTC range November 17, 2026, 00:00:00–23:59:59.
  2. Run Workflow Runs with Workflow blank. Group by conclusion and count id for repository-level outcomes. Populate a workflow ID to narrow the results to one definition.
  3. Switch to Workflow Job Steps with Workflow blank, and group by workflow_name, job_name, and step_name to compare step durations.

Verification

  • Built frontend and backend, loaded the plugin into local Grafana 13.1.9, and exercised the real /api/ds/query path against GitHub. The range above returned 16 runs across 8 workflows (12 successful, 4 skipped). The workflow ID filter returned a single workflow. The steps query returned 622 steps across 7 workflows; all 500 measured durations matched the difference between completion and start timestamps.
  • Added Go tests for repository and workflow-specific endpoints, pagination, and completed, in-progress, and skipped steps. Added query documentation and a changeset.

Special notes for your reviewer

The time filter is based on run creation. To limit GitHub requests, step details are scoped to the latest attempt of the 50 most recent matching runs and show a warning on truncation. Workflow Runs is the intended source for repository-level counts. Self-hosted runner assignment latency is not inferred from workflow or step timestamps.

Refs #326, #508, and #173.

@uzairchhapra
uzairchhapra requested a review from a team as a code owner November 18, 2026 04:11
@itsmylife itsmylife self-assigned this Dec 3, 2026

@itsmylife itsmylife left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for the contribution, @uzairchhapra! Repository-wide runs and step durations fill a real gap. I tested this locally against grafana/github-datasource: blank Workflow, workflow ID, file name and branch filters all work, and step durations match the timestamps.

A few things before we can merge:

  1. Reduce API calls for Workflow Job Steps. One query can make ~60 sequential REST calls with no caching, so a dashboard refreshing every minute would use most of a PAT's 5,000 requests/hour. Suggestions:

    • Fetch only the runs you use: request one page with per_page=50 instead of paging through up to 1,000 runs and then truncating to 50.
    • Cache jobs for completed runs: once a run has status=completed, its jobs and steps for that attempt don't change. Cache them in memory by run_id + run_attempt and only call ListWorkflowJobs for new or in-progress runs. After the first load, a refresh costs 1–2 calls.
    • Conditional requests: 304 Not Modified responses don't count against GitHub's rate limit. Use an ETag-aware HTTP cache in the REST client (e.g. gregjones/httpcache).
    • Bounded concurrency when fetching jobs (e.g. errgroup with a limit of ~5). It doesn't lower the call count, but it keeps wide ranges under the query timeout.

    The first two matter most; the other two are nice to have.

  2. Handler pattern: the new handler calls s.Datasource.client directly. Please follow the existing pattern (Datasource.HandleWorkflowJobStepsQuery → GetWorkflowJobSteps(ctx, models.Client, …)) and add ListWorkflowJobs to models.Client.

  3. Tests: please add tests for getWorkflowJobSteps covering truncation and the warning notice, job pagination, and error wrapping.

  4. Changeset: please mention that saved queries with a blank Workflow used to fail and now return every run in the repository.

  5. Docs: the token permission tables in configure.md don't list Actions: Read, which both query types need.

  6. Rebase: the branch is one commit behind main (2.11.0 release prep).

Optional nits:

  • Validate the Workflow value. GitHub accepts 137535905w as ID 137535905, so typos silently match a workflow. Allowing only blank, digits, or *.yml/*.yaml would catch that.
  • The Workflow field commits only on blur, so pressing Enter runs the previous value. Committing on Enter too would help.

Allow workflow runs across all workflows and expose job step durations.

Refs grafana#326
@uzairchhapra
uzairchhapra force-pushed the feat/repository-workflow-metrics branch from b35e9be to 72675de Compare December 4, 2026 11:44
@uzairchhapra

Copy link
Copy Markdown
Author

Thanks for testing this and for the feedback! I rebased onto main, limited Workflow Job Steps to one page of 50 runs, and added caching for completed run attempts. I also updated the handler, tests, permissions docs, and changeset. go test -race ./... passed on the rebased branch.

Two production edge cases remain:

  • The 50-run cap bounds the number of runs, but a cold Workflow Job Steps query still fetches every job page for each run. A fixed per-query job-request budget with a visible incomplete-results warning would bound that cost without adding a page-size setting.
  • GitHub caps time-filtered Workflow Runs at 1,000 results. The docs mention it, but a panel at that ceiling can look complete. A notice that results may be incomplete would make repository-wide counts less misleading.

Could you take another look at the current changes and let me know whether you would prefer those two safeguards here or as a follow-up?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants