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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ and excessive permissions fail it, and every other finding is shown. |
| **gh** | `devops gh api [OPTIONS] <endpoint>` | Execute a GitHub API request with quota-derived spacing, rate-limit backoff, and optional caching. |
| | `devops gh rate-limit [OPTIONS]` | Display GitHub REST and GraphQL API rate limits, quotas, and reset countdowns. |
| | `devops gh status [OPTIONS]` | Display GitHub published operational status, key components, and active incidents. |
| | `devops gh metrics [OPTIONS]` | Display comprehensive project metrics including release frequency, PRs, commits, CI pass rates, and milestones. |
| | `devops gh metrics [OPTIONS]` | Display comprehensive project metrics including release frequency, PRs, commits, CI pass rates, milestones, and project board items. |
| | `devops gh labels COMMAND [ARGS]...` | GitHub Views, Projects, Issues, Pages, Milestones, and Labels automation. |
| | `devops gh milestones COMMAND [ARGS]...` | GitHub Views, Projects, Issues, Pages, Milestones, and Labels automation. |
| | `devops gh project COMMAND [ARGS]...` | GitHub Views, Projects, Issues, Pages, Milestones, and Labels automation. |
Expand Down
2 changes: 1 addition & 1 deletion docs/CLI_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6718,7 +6718,7 @@ devops gh status [OPTIONS]

### `devops gh metrics`

**Display comprehensive project metrics including release frequency, PRs, commits, CI pass rates, and milestones.**
**Display comprehensive project metrics including release frequency, PRs, commits, CI pass rates, milestones, and project board items.**

```bash
devops gh metrics [OPTIONS]
Expand Down
2 changes: 1 addition & 1 deletion docs/TELEMETRY.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ native histogram under the instrument's own name, with no `_bucket`, `_sum` or
| `devops_cli_project_commits` | Gauge | `1` | Project commits count by release. |
| `devops_cli_project_prs` | Gauge | `1` | Project pull requests merged by release. |
| `devops_cli_project_ci_runs` | Gauge | `1` | CI workflow runs by name, status and conclusion. |
| `devops_cli_project_items` | Gauge | `1` | Project items by milestone, type, priority and state. |
| `devops_cli_project_items` | Gauge | `1` | Project board items by milestone, state, type and priority. A label is empty when the item has no value for it. |
| `devops_cli_project_release_interval_days` | Histogram | `d` | Days elapsed between consecutive project releases. |
| `devops_cli_project_traffic_views` | Gauge | `1` | GitHub repository total page views count. |
| `devops_cli_project_traffic_views_uniques` | Gauge | `1` | GitHub repository unique visitors count. |
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/gh.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ devops gh status [OPTIONS]

## `devops gh metrics`

**Display comprehensive project metrics including release frequency, PRs, commits, CI pass rates, and milestones.**
**Display comprehensive project metrics including release frequency, PRs, commits, CI pass rates, milestones, and project board items.**

```bash
devops gh metrics [OPTIONS]
Expand Down
6 changes: 3 additions & 3 deletions k8s/monitoring/dashboards/project-metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"description": "Open and closed items tracked per milestone. It shows the latest value of each series in the time range, and no data when none was sent in it.",
"description": "Items of the project board by milestone and state. An item in no milestone shows as none. It shows the latest value of each series in the time range, and no data when none was sent in it.",
"fieldConfig": {
"defaults": {
"color": { "mode": "palette-classic" },
Expand All @@ -303,15 +303,15 @@
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "sum by (milestone, state) (last_over_time(devops_cli_project_items[$__range]))",
"expr": "label_replace(sum by (milestone, state) (last_over_time(devops_cli_project_items[$__range])), \"milestone\", \"none\", \"milestone\", \"^$\")",
"legendFormat": "{{milestone}} ({{state}})",
"refId": "A"
}
]
},
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"description": "Aggregate open vs closed items across all milestones. It shows the latest value of each series in the time range, and no data when none was sent in it.",
"description": "Open and closed items of the project board, in all milestones and in none. It shows the latest value of each series in the time range, and no data when none was sent in it.",
"fieldConfig": {
"defaults": {
"color": { "mode": "palette-classic" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-26
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Design

## Source of the counts

`store.items()` reads the board (GraphQL pages of 100 cards) and the issues of the repository (REST), and joins them by issue number. An issue that is not on the board has no card, so it is not an item. The roadmap Service opens its store with an empty board filter, so the read holds open and closed items.

One read costs one budget query plus one GraphQL page for each 100 cards: 12 pages, so 12 points by `read_cost`, for 1,170 cards, every 15 minutes. The read refuses before it spends when the budget is below the floor, as for each other board read.

## Labels

| Label | Value |
| :--- | :--- |
| `milestone` | The milestone title, or empty. |
| `state` | `open` or `closed`, the state of the issue. |
| `type` | The `type/*` label of the issue without its prefix, or empty. |
| `priority` | The board Priority, or empty. |

An empty label value is the same as no label for Prometheus. A query that groups by `milestone` returns the items with no milestone as a series without that label.

## Vanished label sets

The tracer flushes gauges with DELTA temporality, so a series that is not set in a round is not sent. Prometheus keeps its last sample for `last_over_time(...[$__range])`. An item that moves from `In Progress` to closed leaves its label set, and the panels would count it in both.

`emit_project_metrics_telemetry` keeps the label sets that it sent in the last snapshot (`_sent_item_series`, reset by `reset_sent_item_series`). It sends 0 once for each set that is not in the new snapshot. A new process starts with no sent sets, so the sets of an earlier process keep their last value until they leave the time range of the panel.

The in-memory registry that Prometheus scrapes is cleared and written again at each snapshot, so it needs no 0.

## Rejected alternatives

- **Send all combinations of the known values.** 51 milestones, 2 states, 8 types and 5 priorities are about 4,000 series at each flush, nearly all 0, for a board of 1,170 items. Rejected: most series would carry no information.
- **Make the panels read the newest sample only.** This needs the time of each sample in the query. On the cluster's Prometheus, `time() - timestamp(last_over_time(devops_cli_project_items{state="closed"}[30d]))` is 0 for every series, although the samples are a day old, so `last_over_time` reports the evaluation time and not the sample time. Also, `project-metrics-dashboard` requires `last_over_time(<metric>[$__range])` for each gauge panel.
- **Use the board Status as `state`.** The panel description and the existing values say open and closed, and the acceptance criterion compares the open count. The Status stays on the board. A label for it would multiply the series, and no panel reads it.
- **Keep the milestone-only counts and add the missing item in no milestone.** The description of the instrument names type and priority, and the issue asks for them. Rejected: it leaves the gauge and its description in disagreement.
- **Log a warning and send no items when the board read fails.** A failed read then looks like an empty board, and the 0 rule would send 0 for every label set. The read raises. The Service wraps the whole collection in its existing handler, which logs the failure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Proposal

## Why

Issue #2263: the panels "Items by Milestone" and "Active Items by State" of the Project & Engineering Velocity dashboard show 0 open items while 239 issues are open.

`devops_cli_project_items` takes its counts from the REST milestones: `open_issues` and `closed_issues` of each milestone.
Intake puts a new item in the backlog with no milestone, and a person plans milestones.
When no milestone is open, the gauge has no open item to count.
The description of the instrument names the labels milestone, type, priority and state, but the emitter sends only `milestone` and `state`.

## What Changes

- The gauge counts the items of the project board. The roadmap store reads them: each item has the state and the labels of its issue, its milestone, and its board Priority.
- The gauge has the labels `milestone`, `state`, `type` and `priority`. An item with no milestone, no `type/*` label or no Priority has an empty value for that label.
- A label set that had items in the last snapshot and has none in this one is sent once with the value 0. A series that stops arriving keeps its last value in `last_over_time(...[$__range])`, so without the 0 the panels count items that left that label set.
- `collect_project_metrics_report` reads the items through the roadmap store of the job (the Service) or through the board that `.github/roadmap.toml` names (the command). `devops gh metrics` fails when the store cannot read the board, so a failed read never shows as an empty board.
- The milestone loops that fed the gauge from the REST milestone counts are deleted. `MilestoneMetric` stays for the milestone table of `devops gh metrics`.
- The two panels and `docs/TELEMETRY.md` describe what the gauge counts. The panel "Items by Milestone" shows an item with no milestone as `none`.
- The change carries a spec delta: the labels of a gauge and the dashboard panels are observable. It fits in one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `project-metrics-dashboard`: adds the requirements for what the items gauge counts and for the panels that read it.

## Impact

- Code: `src/devops_cli/github/metrics.py`, `src/devops_cli/roadmap/run.py`, `src/devops_cli/telemetry/instruments.py`.
- Dashboard: `k8s/monitoring/dashboards/project-metrics.json`.
- Documentation: `docs/TELEMETRY.md`.
- Tests: `tests/test_github_metrics.py`, `tests/test_telemetry_instruments.py`, `tests/conftest.py` (the reset of the sent series).

## Feasibility

- The premise holds. The query `sum by (state) (last_over_time(devops_cli_project_items[7d]))` on the cluster's Prometheus returns `closed` 928 and `open` 0. The series come from the snapshot that was sent by hand: 51 milestones with two series each.
- `GitHubRoadmapStore.items()` returns every issue on the board with `state`, `labels`, `milestone`, `status` and `priority`. A test reads them through `GitHubFake`, the `gh` process edge.
- The tracer flushes gauges with DELTA temporality. A probe with the OpenTelemetry SDK shows that a gauge series that is not set again is not in the next flush. Prometheus keeps the last sample of that series, and `last_over_time(...[$__range])` returns it. The probe is the reason for the 0 value of a label set that has no items.
- Not confirmed: the numbers on the live dashboard after the change. The roadmap Service has 0 replicas, so no snapshot arrives. The same gauge also reaches Prometheus through the scrape of the Service pod and through OTLP. On 2026-10-08, `sum by (job, state)` of the old `devops_cli_project_items_total` returned 8 open items for `kubernetes-pods` and 4 for `roadmap-service`, so a `sum by (state)` adds two sources. This is a different cause, in how the dashboards read a gauge with two sources. It is #2288, and this change does not hide it.

## Existing Tool Considered

The roadmap store (`RoadmapStore.items()`) and `open_roadmap` already read the board and join it with the issues. This change reuses them and adds no library and no new GitHub call path.
The change deletes the two loops that send `PROJECT_ITEMS` from `MilestoneMetric` in `emit_project_metrics_telemetry` and `_record_workflow_and_milestone_metrics`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Spec Delta

## ADDED Requirements

### Requirement: The items gauge counts the items of the project board
`devops_cli_project_items` SHALL count the items of the project board, open and closed, with the labels `milestone`, `state`, `type` and `priority`. The `milestone` label SHALL be empty for an item in no milestone. The `type` label SHALL be the `type/*` label of the issue without its prefix, and the `priority` label SHALL be the board Priority, each empty when the item has none.

#### Scenario: An open item in no milestone
- **WHEN** the board holds two open items of type `bug` with Priority `P1-High` and no milestone
- **THEN** the report has one item count with `milestone` empty, `state` `open`, `type` `bug`, `priority` `P1-High` and a count of 2

#### Scenario: Open and closed items of a milestone
- **WHEN** the board holds one open item and one closed item in the milestone `2026-11-01`
- **THEN** the report has one count for each state, and both name the milestone `2026-11-01`

#### Scenario: A pull request or an issue that is not on the board
- **WHEN** the repository has a pull request, and an issue with no card on the board
- **THEN** the report counts neither

#### Scenario: The board cannot be read
- **WHEN** the read of the board fails
- **THEN** the collection of the report raises the failure and returns no report

### Requirement: A label set that has no items is sent as 0 once
After a snapshot, `emit_project_metrics_telemetry` SHALL send the value 0 for each label set that the last snapshot of the same process sent and the new snapshot does not hold. It SHALL send that 0 once.

#### Scenario: The last item of a label set closes
- **WHEN** a snapshot holds one open item of type `bug`, and the next snapshot holds that item as closed
- **THEN** the next snapshot sends 0 for the open set and 1 for the closed set, and the snapshot after it sends neither the 0 nor the open set

### Requirement: The panels that read the items gauge describe what it counts
The panels "Items by Milestone" and "Active Items by State" SHALL group `devops_cli_project_items` only by labels that the gauge sends. The description of each panel and of the instrument SHALL name the labels, and the panel "Items by Milestone" SHALL show an item in no milestone as `none`.

#### Scenario: A panel groups by a label that the gauge does not send
- **WHEN** a query of the project dashboard groups `devops_cli_project_items` by a label that is not `milestone`, `state`, `type` or `priority`
- **THEN** the dashboard invariant of `tests/test_telemetry_instruments.py` fails and names the query and the label

#### Scenario: The items of each milestone
- **WHEN** the panel "Items by Milestone" reads the items gauge
- **THEN** its query is `label_replace(sum by (milestone, state) (last_over_time(devops_cli_project_items[$__range])), "milestone", "none", "milestone", "^$")`

#### Scenario: The items of each state
- **WHEN** the panel "Active Items by State" reads the items gauge
- **THEN** its query is `sum by (state) (last_over_time(devops_cli_project_items[$__range]))`
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Tasks

## 1. Failing tests

- [x] Add the tests that fail on `main`: the item counts of the board, the milestone filter, a failed board read, the labels on the wire, the 0 for a label set that left, the panel queries, and the Service job that counts the items of its own store
- Verification: `uv run devops ci test tests/test_github_metrics.py tests/test_telemetry_instruments.py tests/test_roadmap_run.py`
- [x] Move the `captured` fixture to `tests/support/telemetry_capture.py` so that both metrics test modules share one double of the OTLP edge
- Verification: `uv run devops ci test tests/test_telemetry_instruments.py`

## 2. Item counts

- [x] Add `PROJECT_ITEM_LABELS` to `src/devops_cli/telemetry/instruments.py` and write the description of `PROJECT_ITEMS` with the labels
- Verification: `uv run devops ci test tests/test_telemetry_instruments.py`
- [x] Add `ItemCountMetric`, `get_item_metrics` and the `store` argument of `collect_project_metrics_report` to `src/devops_cli/github/metrics.py`, and pass the store of the job from `_run_metrics_adapter` in `src/devops_cli/roadmap/run.py`
- Verification: `uv run devops ci test tests/test_github_metrics.py tests/test_roadmap_run.py`
- [x] Send the item counts and the 0 for each label set that left, record them in the in-memory registry, and delete the loops that sent the REST milestone counts; register `reset_sent_item_series` in `tests/conftest.py`
- Verification: `uv run devops ci test tests/test_github_metrics.py tests/test_architectural_invariants.py`

## 3. Dashboard and documentation

- [x] Change the two panels of `k8s/monitoring/dashboards/project-metrics.json`: the descriptions, and `none` for an item in no milestone
- Verification: `uv run devops ci test tests/test_telemetry_instruments.py`
- [x] Regenerate the documentation with `devops docs generate --sync-readme`
- Verification: `uv run devops ci test tests/test_docs.py`

## 4. Verification and static checks

- [x] Verify the fail-to-pass check run against `origin/main`
- Verification: `uv run devops ci fail-to-pass --base origin/main`
- [x] Verify that the full static checks pass
- Verification: `uv run devops ci`

## Workflow follow-up

- #2288: the double count of a gauge that reaches Prometheus through the scrape of the Service pod and through OTLP.
- Pending a person: review the diff in tuicr (`tuicr -r origin/main..HEAD`).
Loading