Skip to content

feat(github): record the rate limit of each response as gauges #4752

Done

Description

@dan-petty

Update 2026-11-26 (infra move): the Files list now names the product dashboard.


Problem or Motivation

No series holds the count that GitHub keeps of the devops-cli API use. devops_cli_github_requests_total counts attempts on the client side: a gh command counts as one request with status 'none', a paginated read counts as 1 (#4737), and counter streams lose counts between the collector and Prometheus (#4684). Each GitHub answer carries the headers x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-used, x-ratelimit-reset and x-ratelimit-resource. devops-cli already reads them, from gh output (src/devops_cli/github/rate_limiter.py:598-616) and from the session (src/devops_cli/github/session_transport.py:225), into update_quota (rate_limiter.py:1179), but sends no metric of them. All pods of one App installation share one budget (ADR 0021).

Owner decision of 2026-11-11: GitHub's own count comes from gauges of these headers, with no new pod and no second copy of the Service App key.

Proposed Solution & Architectural Design

In update_quota, where both header paths land, set four gauges with the label resource (core, graphql, search, code_search and the other values that GitHub sends):

  • devops_cli_github_rate_limit_limit
  • devops_cli_github_rate_limit_remaining
  • devops_cli_github_rate_limit_used
  • devops_cli_github_rate_limit_reset_seconds (the Unix time of the window reset)

A gauge keeps the last value, so it has no false reset. The value is the count of GitHub for the identity at the time of the answer. An answer with no rate-limit header changes no gauge.

Add one panel to the GitHub row of devops-cli.json: used and limit by resource, as GitHub reports them, beside the counted requests of #4707. List the gauges in docs/TELEMETRY.md.

Scope: queries, panel types, units, legends and defaults only. Keep the default Grafana colors. The project design study owns colors and type.

Target Subsystem

SDLC, Git & PR Governance (GitHub client and its telemetry).

Existing Tool Considered

githubexporter/github-exporter v2.4.1 in rate-limit-only mode reads GET /rate_limit. The owner refused it on 2026-11-11: it needs a new pod with a second copy of the write-capable Service App key, and it cannot see the user token of a workstation. GET /rate_limit also counts against the secondary limit, while the headers come with each answer at no cost. Cost to build: about 60,000 tokens and 1 h; about 2,000 tokens a month to keep; about 10,000 tokens to fix.

Acceptance Criteria

  • A test: a session answer with x-ratelimit-limit 5000, x-ratelimit-remaining 4958, x-ratelimit-used 42, x-ratelimit-reset 1767225600 and x-ratelimit-resource core sets the four gauges of resource core to these values.
  • A test: gh output with the same headers sets the same gauges.
  • A test: an answer with no rate-limit header changes no gauge.
  • docs/TELEMETRY.md lists the four gauges.
  • A harness case for the new panel passes, and the dashboard tests pass.
  • Live, for job roadmap-service over 1 h: used plus remaining equals limit for resource core at each sample.

Files

  • src/devops_cli/github/rate_limiter.py
  • src/devops_cli/telemetry/instruments.py
  • k8s/devops/dashboards/devops-cli.json
  • docs/TELEMETRY.md
  • tests/github/test_github_rate_limiter.py
  • tests/telemetry/test_telemetry_instruments.py
  • tests/fixtures/dashboard_queries/devops-cli.yaml

Dependencies

#4707 (the same row of devops-cli.json).

Related

#4563 (shares the GitHub budget in Valkey).

Source: #4675

Alternatives check of 2026-11-23: partly.
Tool: theodore86/github-rate-limits-exporter (https://github.com/theodore86/github-rate-limits-exporter), MIT, last activity 2026-11-22, maintained.
Reason: The searches found only GitHub rate-limit exporters, which do expose limit, remaining, used and reset per resource as Prometheus metrics, but only by polling GET /rate_limit from their own pod and token, not from the response headers in update_quota, so they cover the metric content and not the in-process path the issue requires.

Covers:

  • Limit, remaining, used and reset per API resource
  • A resource label with core, graphql, search, code_search
  • Prometheus scrape endpoint ready to deploy

Lacks:

  • No gauges emitted inside update_quota
  • Polls GET /rate_limit with its own token from a new pod
  • Needs a second copy of the write-capable App key
  • Cannot see a workstation's user token
  • No project dashboard panel or telemetry docs

Proposed design

Problem statement

No series holds the rate-limit count that GitHub keeps for the devops-cli identity. devops_cli_github_requests_total counts client attempts, and a counter stream can lose counts. The rate limiter already reads the x-ratelimit-* headers into update_quota, but it sends no metric of them. This change sends four gauges by resource, adds one dashboard panel, and lists the gauges in the telemetry document.

Acceptance criteria

Requirement: Session rate-limit gauges

The GitHub session SHALL set the four rate-limit gauges from the x-ratelimit-* headers of an answer, with the label resource.

Scenario: A session answer holds every rate-limit header

  • WHEN an answer carries x-ratelimit-limit 5000, x-ratelimit-remaining 4958, x-ratelimit-used 42, x-ratelimit-reset 1767225600 and x-ratelimit-resource core
  • THEN the four gauges of resource core hold 5000, 4958, 42 and 1767225600

Requirement: gh command rate-limit gauges

run_gh SHALL set the four gauges from the x-ratelimit-* headers that gh prints.

Scenario: gh output holds every rate-limit header

  • WHEN gh output holds the same five header lines
  • THEN the four gauges of resource core hold 5000, 4958, 42 and 1767225600

Requirement: Partial header answer

An answer SHALL set only the gauges of the rate-limit values that it holds.

Scenario: An answer holds no used and no reset header

  • WHEN an answer holds x-ratelimit-remaining 4900 and x-ratelimit-limit 5000, and no used and no reset header
  • THEN the remaining and limit gauges hold 4900 and 5000, and the used and reset gauges of that resource keep their last value

Requirement: Headerless answer

An answer with no rate-limit header SHALL change no rate-limit gauge.

Scenario: An answer holds no rate-limit header

  • WHEN an answer carries no x-ratelimit-* header
  • THEN the four gauges of the resource keep their last values

Requirement: Rate-limit refresh

The refresh read of GET /rate_limit SHALL set the four gauges of each resource in its body.

Scenario: A refresh body holds a graphql window

  • WHEN a GET /rate_limit body holds graphql with limit 5000, used 66, remaining 4934 and a reset time
  • THEN the four gauges of resource graphql hold 5000, 66, 4934 and the reset time

Requirement: Declared gauge instruments

Each of the four gauges MUST be a declared instrument of the kind gauge, with the unit 1 or s and the label resource only.

Scenario: The instruments module is read

  • WHEN uv run pytest tests/telemetry/test_telemetry_instruments.py runs
  • THEN the test passes for the four declared gauges, their units, the resource label only, and no _total name

Requirement: GitHub API row panel

The GitHub API row of devops-cli.json SHALL hold one timeseries panel that shows the used and the limit of each resource with last_over_time on the two gauges.

Scenario: The dashboard tests read the row

  • WHEN uv run pytest tests/prometheus/test_dashboard_queries.py tests/telemetry/test_telemetry_instruments.py runs
  • THEN the dashboard row test and the harness case for the new panel pass

Requirement: Telemetry gauge rows

docs/TELEMETRY.md SHALL list the four gauges in its metric table.

Scenario: The instrument test reads the document

  • WHEN uv run pytest tests/telemetry/test_telemetry_instruments.py runs
  • THEN the test passes for each of the four gauge rows

Requirement: Pending a person after the merge

After the merge, a person SHALL verify over 1 h that used plus remaining equals limit for resource core for job roadmap-service.

Scenario: Live sample of the core resource

  • WHEN a person reads the gauges for job roadmap-service over 1 h
  • THEN used plus remaining equals limit for resource core at each sample

Existing Tool Considered

The alternatives check in the issue body records verdict partly for theodore86/github-rate-limits-exporter (MIT, maintained). That block lists what the tool covers and lacks. The proposal closes the gap it names: it emits the four gauges in update_quota from the x-ratelimit-* headers of each answer and from the GET /rate_limit refresh. It therefore needs no new pod, no second App key, and it sees the user token of a workstation. It also adds the dashboard panel and the telemetry rows. Cost to build the gauges in update_quota instead: about 60,000 tokens and 1 h to build, about 2,000 tokens a month to keep, and about 10,000 tokens to fix.

Key questions

  • Does GitHub's own count come from gauges of the response headers, or from a separate exporter?: It comes from gauges of the x-ratelimit-* headers in update_quota, with no new pod and no second App key. The owner decided this on 2026-11-11. (best practice) [sources: docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, src/devops_cli/github/rate_limiter.py]
    • Chosen: gauges of the response headers. Each answer carries the headers at no cost, and the rate limiter already reads them into update_quota.
    • Rejected: separate exporter pod. It needs a new pod and a second copy of the write-capable App key, it cannot see a workstation token, and its polls can count against the secondary limit.
  • Where does the code set the four gauges?: In update_quota, which the session header path, the gh header path and the GET /rate_limit refresh already call. The refresh passes each resource through it, so one emit there covers all three paths. (best practice) [sources: src/devops_cli/github/rate_limiter.py, src/devops_cli/github/session_transport.py]
    • Chosen: one emit inside update_quota. All three paths land there, so one place sets the gauges and the refresh read sets them too.
    • Rejected: emit at each caller. Three copies drift apart, and a caller that forgets one sends no gauge.
  • What names, kinds, units and labels do the four gauges have?: devops_cli_github_rate_limit_limit, devops_cli_github_rate_limit_remaining and devops_cli_github_rate_limit_used are gauges of unit 1. devops_cli_github_rate_limit_reset_seconds is a gauge of unit s that holds the Unix time of the window reset. Each carries the label resource only. (best practice) [sources: src/devops_cli/telemetry/instruments.py, docs/TELEMETRY.md, tests/telemetry/test_telemetry_instruments.py]
    • Chosen: four gauges with the label resource only. The budget is one per identity, so a repository or row label adds series and states nothing new.
    • Rejected: counters of each answer. GitHub's count goes down as well as up, so a counter shows a false reset at each window.
    • Rejected: gauges with resource, repo and row. The headers describe the budget of the identity, not of one repository or row, and each extra label multiplies the series.
  • Which file holds the devops-cli dashboard?: k8s/devops/dashboards/devops-cli.json. [sources: k8s/devops/dashboards/devops-cli.json, tests/telemetry/test_telemetry_instruments.py, tests/prometheus/test_dashboard_queries.py]
  • Which panel does the dashboard gain, and does it change an existing test?: One timeseries panel, GitHub rate limit: used and limit by resource, joins the GitHub API row. It reads the gauges with last_over_time over $__range. The row test asserts the exact set of panels, so the change updates that test with the new panel. (best practice) [sources: tests/telemetry/test_telemetry_instruments.py, k8s/devops/dashboards/devops-cli.json, docs/TELEMETRY.md]
    • Chosen: one panel in the GitHub API row, with the row test updated. The row holds the GitHub budget panels, so GitHub's used and limit sit beside the counted requests of fix(monitoring): make the GitHub and command panels readable #4707.
    • Rejected: a new row of its own. A row costs vertical space and separates the gauge from the counted requests that it explains.
  • Does this item still wait on fix(monitoring): make the GitHub and command panels readable #4707?: No. The GitHub API row of devops-cli.json already holds the five panels of fix(monitoring): make the GitHub and command panels readable #4707 at the refined commit, so the row and its test are in place. [sources: tests/telemetry/test_telemetry_instruments.py, tests/fixtures/dashboard_queries/devops-cli.yaml, openspec/specs/github-api-metrics/spec.md]
  • Which values must the session and gh header paths pass to update_quota?: The session path must pass used from x-ratelimit-used and the resource from x-ratelimit-resource, in addition to remaining, limit and reset. The gh parser _process_header_metrics must add x-ratelimit-resource to its table, or the gh path cannot label the gauges by resource. (best practice) [sources: src/devops_cli/github/session_transport.py, src/devops_cli/github/rate_limiter.py]
    • Chosen: pass used and resource in both paths. The acceptance tests use resource core and graphql, and the gauges need both values to carry the correct label and count.
    • Rejected: default every answer to resource core. GitHub sends graphql, search and code_search answers, so a core default labels those values with the wrong resource.
    • Rejected: emit the gauges without the resource label. The issue requires the label resource, and a dashboard cannot separate the budgets without it.
  • Does docs/TELEMETRY.md get the four rows from the generator or from a hand edit?: docs/TELEMETRY.md is generated. src/devops_cli/docs/generator.py reads INSTRUMENTS, so the change declares the four instruments and regenerates the document. No hand edit of the table is needed. [sources: src/devops_cli/docs/generator.py, docs/TELEMETRY.md, src/devops_cli/telemetry/instruments.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/feature
    scope/github
    status/new
    value/medium
    effort/low
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/github. The (github) scope of the title gives the scope.
    • Priority: P2-Medium. Observability improvement that aids operators but does not block a release or fix a defect.
    • Value: Medium. Gives operators visibility into GitHub's own rate-limit budget per resource, reducing blind spots in capacity planning.
    • Effort: Low. Four gauges, one panel, docs update, and tests in well-scoped files; the body estimates about one hour.
    • Related: feat(github): github api request and throttle counters for the devops-cli dashboard #814, which asks for a different change. Both add GitHub API metrics to the same dashboard and instruments.py, but #814 adds client-side request counters while this adds server-side rate-limit gauges from response headers.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Addition (owner direction of 2026-11-12, ADR 0026 of #5223). The title stays.

    ADR 0026 moves the issue and pull request commands of devops gh and devops pr to gh's GraphQL commands. gh prints no rate-limit header for these commands, so the header path of this item does not see them. devops_cli_github_graphql_points_total counts points only for answers that hold a rateLimit field (rate_limiter.py:546-559). The rate limiter already reads GET /rate_limit when its stored quota is old (_refresh_from_github). The body of that answer holds limit, used, remaining and reset for each resource.

    Added scope

    • The refresh read of GET /rate_limit sets the four gauges of each resource in its body, through update_quota.
    • docs/TELEMETRY.md gives the query of the trigger of ADR 0026: one hour above 2,500 on devops_cli_github_rate_limit_used{resource="graphql"} for one job.

    Acceptance Criteria (additions)

    • A test: a GET /rate_limit body with graphql used 66 and remaining 4,934 sets the gauges of resource graphql to these values.
    • Live: in 1 h of normal agent work, the gauge of resource graphql of job devops-cli has at least one sample.

    Dependencies

    No change. #5223 does not wait for this item. Until it merges, the trigger of ADR 0026 uses the hourly sum of GraphQL requests and reported points.

  6. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Alternatives check: partly

    Reason: The searches found standalone Prometheus exporters for GitHub's rate-limit budget: theodore86/github-rate-limits-exporter (and the issue's own refused candidate, githubexporter/github-exporter) expose limit, remaining, used and reset per API resource as Prometheus metrics, which is the metric set the issue wants. Neither reads the x-ratelimit-* headers of each answer inside devops-cli: both poll GET /rate_limit with their own token from a separate exporter, so they need a new pod and a second token copy and cannot see a workstation's user token — hence they cover only part of the need.

    Tool: theodore86/github-rate-limits-exporter (https://github.com/theodore86/github-rate-limits-exporter)

    • License: MIT
    • Last activity: 2026-11-13
    • Maintained: yes

    Covers:

    • Exposes GitHub rate-limit limit, remaining, used and reset (window reset in UTC seconds) per API resource as Prometheus metrics
    • Runs against a PAT or GitHub App credentials and ships Docker, Helm and docker-compose deployment paths

    Lacks:

    • Reads the quota by polling GET /rate_limit instead of the x-ratelimit-* headers of each response, so it needs a separate exporter pod and a second token copy
    • Cannot see the user token of a workstation
    • Does not set the four gauges inside devops-cli's update_quota path (rate_limiter.py), where the issue wants them
    • Its GET /rate_limit polls count against GitHub's secondary limit, while per-response headers are free

    Tools considered:

    Searches run:

    • githubexporter github-exporter rate limit metrics, results: 5
    • GitHub API rate limit Prometheus exporter gauges, results: 5
    • github-exporter prometheus GitHub rate limit remaining metrics, results: 5

    Sources:

    Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    status/ready
    and removed
    status/new
    on Nov 15, 2026
  8. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at e5dfddb (see proposed design in issue body).

  9. added
    owner/service
    on Nov 25, 2026
  10. 8 remaining items

  11. added
    owner/service
    and removed
    owner/service
    on Nov 25, 2026
  12. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  13. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  14. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  15. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 18:38 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/githubsource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions