Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/TELEMETRY.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ native histogram under the instrument's own name, with no `_bucket`, `_sum` or
| `devops_cli_rag_query_duration_ms` | Histogram | `ms` | RAG retrieval time, by stage: embedding, search, ranking, or total for the whole query. |
| `devops_cli_qdrant_retries_total` | Counter | `1` | Qdrant requests retried after a transient error, by operation and error type. |
| `devops_cli_rag_points` | Gauge | `1` | Points stored in RAG vector collections, by collection. |
| `devops_cli_github_requests_total` | Counter | `1` | GitHub requests the rate limiter paced, each attempt and retry once, by resource: the rate limit resource the request spends, such as core, graphql or search. A gh command and a request of the GitHub session both count. |
| `devops_cli_github_throttle_wait_seconds` | Histogram | `s` | Time devops-cli waited before it sent a refused GitHub request again, by resource: one observation for each throttle. GitHub refused the request with a rate limit, or the GitHub session got a 5xx for a read. |
| `devops_cli_github_graphql_points_total` | Counter | `1` | GraphQL points that GitHub reported each answer cost in its rateLimit field. |
| `devops_cli_project_releases` | Gauge | `1` | Total project releases tracked. |
| `devops_cli_project_commits` | Gauge | `1` | Project commits count by release. |
| `devops_cli_project_prs` | Gauge | `1` | Project pull requests merged by release. |
Expand Down
192 changes: 192 additions & 0 deletions k8s/monitoring/dashboards/devops-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,198 @@
"refId": "A"
}
]
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 68
},
"id": 21,
"title": "GitHub API",
"type": "row"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "GitHub requests per hour that devops-cli sent, by rate-limit resource, such as core, graphql or search. Each attempt counts, and each retry counts again. A gh command and a request of the GitHub session both count. The read of /rate_limit does not count, because GitHub does not charge it. Approximate, and low for sparse series: increase() needs two samples of a series inside its window, so a series' first sample, and any series seen only once in the window, add nothing. Delta points from one process can arrive out of order, and totals then come out low (#792).",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"drawStyle": "line"
},
"unit": "short"
}
},
"gridPos": {
"h": 8,
"w": 6,
"x": 0,
"y": 69
},
"id": 22,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
},
"title": "GitHub Requests by Resource",
"type": "timeseries",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum by (resource) (increase(devops_cli_github_requests_total[1h]))",
"legendFormat": "{{resource}}",
"refId": "A"
}
]
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "Refused GitHub requests per hour that devops-cli sent again after a wait, by rate-limit resource. GitHub refused them with a rate limit, or the GitHub session got a 5xx for a read. Approximate, and low for sparse series: increase() needs two samples of a series inside its window, so a series' first sample, and any series seen only once in the window, add nothing. Delta points from one process can arrive out of order, and totals then come out low (#792).",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"drawStyle": "bars"
},
"unit": "short"
}
},
"gridPos": {
"h": 8,
"w": 6,
"x": 6,
"y": 69
},
"id": 23,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
},
"title": "GitHub Throttles by Resource",
"type": "timeseries",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "histogram_count(sum by (resource) (increase(devops_cli_github_throttle_wait_seconds[1h])))",
"legendFormat": "{{resource}}",
"refId": "A"
}
]
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "Seconds per hour that devops-cli waited before it sent a refused GitHub request again, by rate-limit resource. Approximate, and low for sparse series: increase() needs two samples of a series inside its window, so a series' first sample, and any series seen only once in the window, add nothing. Delta points from one process can arrive out of order, and totals then come out low (#792).",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"drawStyle": "bars"
},
"unit": "s"
}
},
"gridPos": {
"h": 8,
"w": 6,
"x": 12,
"y": 69
},
"id": 24,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
},
"title": "GitHub Throttle Wait by Resource",
"type": "timeseries",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "histogram_sum(sum by (resource) (increase(devops_cli_github_throttle_wait_seconds[1h])))",
"legendFormat": "{{resource}}",
"refId": "A"
}
]
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "GraphQL points per hour that GitHub reported in the rateLimit field of each answer. One query can cost many points, so the count of graphql requests does not show this cost. Approximate, and low for sparse series: increase() needs two samples of a series inside its window, so a series' first sample, and any series seen only once in the window, add nothing. Delta points from one process can arrive out of order, and totals then come out low (#792).",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"drawStyle": "line"
},
"unit": "short"
}
},
"gridPos": {
"h": 8,
"w": 6,
"x": 18,
"y": 69
},
"id": 25,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
}
},
"title": "GitHub GraphQL Points",
"type": "timeseries",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(increase(devops_cli_github_graphql_points_total[1h])) or vector(0)",
"legendFormat": "points",
"refId": "A"
}
]
}
],
"refresh": "10s",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-28
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Design

## Decisions

- **The rate limiter sends the metrics.** `acquire`, `record_throttle` and `charge_points` are the one place where `run_gh` and the GitHub session meet. Each method sends its metric after its own update and outside its lock, so a slow export does not hold the pacing of another thread.
- **A request is counted when the rate limiter lets it go.** `acquire` sends the count after it calculates the wait and before it sleeps. An attempt whose quota the rate limiter cannot read raises before the count, because it is not sent.
- **The label is the rate-limit resource.** `core`, `graphql`, `search`, `code_search` and `code_scanning_autofix` are the resources that the rate limiter knows, so the label has few values. The command and the repository are not labels: the rate limiter does not know them, and the GitHub quota is per identity, not per repository.
- **One histogram for the throttles.** A native histogram holds the count and the sum of its observations. `histogram_count` gives the throttles, and `histogram_sum` gives the seconds of wait.
- **The session's 5xx retries are in the histogram.** `retry_wait` already records the wait before it sends a read again after a 5xx as a throttle in the ledger. The metric keeps the meaning of the ledger, and the description of the instrument says so.
- **The GraphQL points are one counter with no label.** All GraphQL points go to the `graphql` resource, so a resource label has one value.

## Rejected alternatives

- **A counter `devops_cli_github_throttles_total` next to the histogram.** It always agrees with `histogram_count` of the histogram, so the second series adds no data.
- **A gauge of the quota that is left, from each process.** Many short-lived processes of two identities (the gh login of a person and the identity of the Service) would write one series. Without a label for the identity, the series mixes two quotas. The key of the identity is a digest of its token or installation, which a dashboard cannot name. `devops gh rate-limit` shows the quota of the current identity.
- **The Service gauges on the Prometheus endpoint of the Service.** `tests/test_telemetry_instruments.py` lets a dashboard query only the series in `INSTRUMENTS`, and `test_no_gauge_reaches_prometheus_through_two_paths` refuses one gauge on two paths. The Service does not run now (`replicas: 0`), and #1647 and #2399 change its identity and its GraphQL use. The proposal names the parts that the change does not build.
- **`opentelemetry-instrumentation-httpx`.** It sees only the GitHub session. The gh commands that `run_gh` starts are child processes, and the instrumentation does not know the rate-limit resource or the wait.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Proposal

## Why

Issue #814: no dashboard shows how many requests devops-cli sends to GitHub, how often GitHub refuses them, or how many GraphQL points they cost.

- The rate limiter paces each request. It counts the requests, the throttles and the throttle wait in the quota ledger of the identity (`src/devops_cli/github/rate_limiter.py`). Only `devops gh rate-limit` reads these totals, and no metric sends them.
- A count of requests does not show the GraphQL cost. On 2026-10-07, about 300 gh calls spent about 4,850 points in one window. A quiet hour sent 158 calls for about 158 points (comment on #814, 2026-10-08).

## What Changes

- The new counter `devops_cli_github_requests_total`, by `resource`. The rate limiter adds 1 for each attempt that it paces: a gh command or a request of the GitHub session, and each retry. The resource is the rate-limit resource that the request spends, such as `core`, `graphql` or `search`.
- The new histogram `devops_cli_github_throttle_wait_seconds`, by `resource`. Each throttle adds one observation: the seconds that devops-cli waits before it sends the refused request again. The count of the histogram is the count of throttles.
- The new counter `devops_cli_github_graphql_points_total`. It adds the cost that each GraphQL answer reports in `rateLimit.cost`.
- `GitHubRateLimiter.record_throttle` takes the resource of the request that GitHub refused.
- The new row "GitHub API" in `k8s/monitoring/dashboards/devops-cli.json` shows the requests by resource, the throttles and their wait by resource, and the GraphQL points.
- `docs/TELEMETRY.md` lists the three metrics. `devops docs generate` writes the list from `INSTRUMENTS`.
- A consumer sees the metrics and the dashboard, so the change has a spec delta: the new capability `github-api-metrics`.
- This change fits one pull request.

The change does not build these parts of the 2026-10-08 update of #814:

- The gauge of the GraphQL points left and the spend by repository of each Service round. Both come from the GraphQL budget read of the board store (`GitHubRoadmapStore.graphql_spend`, `src/devops_cli/roadmap/board_read.py`). #2399 moves the roadmap state to labels and milestones, and no roadmap job reads or writes the board after it. The board reads were the GraphQL cost of the Service. `devops_cli_github_graphql_points_total` counts the GraphQL cost of every process, the Service included.
- The gauge `devops_cli_service_paused_until_seconds`. The Service pauses only after a GraphQL budget refusal (`service_pause_until` in `src/devops_cli/roadmap/run.py`). The Service does not run now (`replicas: 0`, #1562), and #1647 and #2399 change its identity and its GraphQL use.

## Capabilities

### New Capabilities

- `github-api-metrics`: the metrics that devops-cli sends about its requests to GitHub, and the dashboard row that shows them.

### Modified Capabilities

None.

## Impact

- `src/devops_cli/telemetry/instruments.py`, `src/devops_cli/github/rate_limiter.py`, `src/devops_cli/github/session_transport.py`.
- `k8s/monitoring/dashboards/devops-cli.json`.
- `tests/test_github_api_metrics.py`, `tests/test_telemetry_instruments.py`, `tests/test_github_rate_limiter.py`.
- `docs/TELEMETRY.md`, which `devops docs generate --sync-readme` rewrites.

## Feasibility

Checked on origin/main bb46660c on 2026-10-28.

- One place sees each request. `run_gh` paces each attempt with `GitHubRateLimiter.acquire` (`_execute_gh_single_attempt`). The GitHub session paces each attempt with the same method (`pace_request` in `src/devops_cli/github/session_transport.py`). The `/rate_limit` read is not paced, and GitHub does not charge it.
- One place sees each throttle. `_handle_attempt_backoff` (`run_gh`) and `retry_wait` (the GitHub session) call `record_throttle` with the wait, and both know the resource of the request.
- One place sees each GraphQL cost. `_extract_graphql_ratelimit_json` calls `charge_points("graphql", cost)` for each answer that holds `rateLimit.cost`.
- `INSTRUMENTS` has counters and histograms, and `emit()` sends them as OTLP deltas (`src/devops_cli/telemetry/instruments.py`). Prometheus 3 stores a histogram as a native histogram, and `histogram_count` and `histogram_sum` read it.
- `tests/test_telemetry_instruments.py` lets a dashboard query only the series in `INSTRUMENTS`. A Service gauge on the Prometheus endpoint of the Service (`GLOBAL_METRICS`) cannot be on the dashboard.
- #1647 changes the identity plumbing of the rate limiter and the session transport (`token` becomes `identity`). It does not change `acquire`, `record_throttle` or `charge_points`.

## Existing Tool Considered

The change uses the OpenTelemetry SDK through `emit()`, which devops-cli already uses for every metric. GitHub gives no metric of the requests of one client: `GET /rate_limit` gives only the quota that is left for each resource. `opentelemetry-instrumentation-httpx` would count the requests of the GitHub session, but not the gh commands that `run_gh` starts, and it does not know the rate-limit resource or the throttle wait. The change builds no new code path: it adds three `emit()` calls where the rate limiter already counts. It deletes no code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Purpose

The metrics that devops-cli sends about its requests to GitHub: the requests by rate-limit resource, the throttles and their wait, and the GraphQL points, and the row of the devops-cli dashboard that shows them.

## ADDED Requirements

### Requirement: Each paced GitHub request counts one request by its resource
The rate limiter SHALL add 1 to `devops_cli_github_requests_total`, with the label `resource`, for each attempt that it paces. A gh command of `run_gh` and a request of the GitHub session are both counted, and each retry is counted again. The label is the rate-limit resource that the request spends.

#### Scenario: A gh command that GitHub refuses one time
- **WHEN** `run_gh` sends `gh api repos/<owner>/<repo>`, GitHub refuses the first attempt with a rate limit and the second attempt succeeds
- **THEN** `devops_cli_github_requests_total` has one point with the `resource` `core` and the value 2

#### Scenario: A GraphQL command
- **WHEN** `run_gh` sends `gh api graphql` and the attempt succeeds
- **THEN** `devops_cli_github_requests_total` has one point with the `resource` `graphql` and the value 1

#### Scenario: A request of the GitHub session
- **WHEN** the GitHub session sends `GET /user` and GitHub answers it
- **THEN** `devops_cli_github_requests_total` has one point with the `resource` `core` and the value 1

### Requirement: Each throttle is one observation of its wait
Each time devops-cli waits before it sends a refused GitHub request again, it SHALL add one observation of the wait in seconds to `devops_cli_github_throttle_wait_seconds`, with the label `resource`.

#### Scenario: A gh command with a Retry-After
- **WHEN** GitHub refuses the first attempt of `gh api repos/<owner>/<repo>` with a rate limit and `Retry-After: 7`
- **THEN** `devops_cli_github_throttle_wait_seconds` has one observation of 7 with the `resource` `core`

#### Scenario: A request of the GitHub session with a Retry-After
- **WHEN** GitHub answers the first attempt of `GET /user` with 429 and `retry-after: 1`, and answers the second attempt
- **THEN** `devops_cli_github_throttle_wait_seconds` has one observation of 1 with the `resource` `core`

### Requirement: The GraphQL points that GitHub reports are counted
devops-cli SHALL add the cost that a GraphQL answer reports in `rateLimit.cost` to `devops_cli_github_graphql_points_total`.

#### Scenario: A GraphQL answer that costs 3 points
- **WHEN** `run_gh` sends `gh api graphql` and the answer holds `rateLimit` with `cost` 3
- **THEN** `devops_cli_github_graphql_points_total` has one point with the value 3

### Requirement: The devops-cli dashboard shows the GitHub requests
The dashboard `devops-cli.json` SHALL have the row "GitHub API" with a panel for each of these queries: the requests by resource, the throttles by resource, the throttle wait by resource, and the GraphQL points.

#### Scenario: The GitHub API row
- **WHEN** `k8s/monitoring/dashboards/devops-cli.json` is read
- **THEN** the row "GitHub API" holds the panels "GitHub Requests by Resource", "GitHub Throttles by Resource", "GitHub Throttle Wait by Resource" and "GitHub GraphQL Points"
- **AND** they query `sum by (resource) (increase(devops_cli_github_requests_total[1h]))`, `histogram_count(sum by (resource) (increase(devops_cli_github_throttle_wait_seconds[1h])))`, `histogram_sum(sum by (resource) (increase(devops_cli_github_throttle_wait_seconds[1h])))` and `sum(increase(devops_cli_github_graphql_points_total[1h])) or vector(0)`
Loading
Loading