Skip to content

feat(monitoring): grafana and prometheus take the route names #5231

Done

Description

@dan-petty

Problem or Motivation

The owner asked on 2026-11-12 that a devops command on an HTTP API take its names from the API routes (ADR 0026, #5223). Sources: grafana/client.py and prometheus/client.py.

devops command Route Mismatch
grafana alerts GET /api/v1/provisioning/alert-rules The resource is alert rules. Grafana serves firing alerts at another route.
grafana dashboards export <uid> GET /api/dashboards/uid/{uid} GET of one dashboard
grafana dashboards import <file> POST /api/dashboards/db (Create / Update dashboard) Grafana has a route POST /api/dashboards/import with another meaning.
grafana datasources GET /api/datasources A collection with no list
prometheus rules, prometheus targets GET /api/v1/rules, GET /api/v1/targets Collections with no list

These commands already match their routes: grafana search, grafana dashboards list, prometheus query and prometheus query-range. Loki holds no usage error for these groups in the 7 days to 2026-11-12.

Proposed Solution & Architectural Design

  • Rename to grafana alert-rules list, grafana dashboards get <uid> [-o <file>], grafana dashboards update <file>, grafana datasources list, prometheus rules list and prometheus targets list.
  • dashboards update: the command sends overwrite: true (grafana/client.py:80-81,122), so the operation is an upsert, which ADR 0026 names update. The segments uid and db give no word (key selector and storage form).
  • dashboards sync, dashboards lint and prometheus analyze stay project verbs: they read files or send several reads.
  • Change the MCP rows of the renamed commands. grafana dashboards list and prometheus query do not change.
  • Add grafana and prometheus to the groups of tests/commands/test_api_command_names.py.

Target Subsystem

Monitoring (devops grafana, devops prometheus).

Existing Tool Considered

The Grafana and Prometheus HTTP API references give the names. Nothing is built.

Acceptance Criteria

  • devops grafana alert-rules list --dry-run prints GET /api/v1/provisioning/alert-rules and sends 0 requests.
  • devops grafana alerts, devops grafana dashboards export and devops grafana dashboards import exit 2.
  • devops prometheus rules list --dry-run prints GET /api/v1/rules.
  • tests/commands/test_api_command_names.py passes for both groups.
  • devops docs check passes.

Dependencies

Open the pull request after the pull request of #5230 merges (generated command reference, CONST_MCP_EXPOSURE_TABLE, the API name test).

Source: #5223

Alternatives check of 2026-11-29: none.
Tool: none found.
Reason: Searches returned only Grafana container images and generic API pages, no open tool that renames this project's own grafana and prometheus Typer command paths to route names; the work edits existing command modules.

Lacks:

  • Route-named command paths for grafana and prometheus groups
  • Dry run that prints the route and sends no request
  • Removal of the old grafana alerts, export and import paths

Proposed design

Problem statement

Rename the devops grafana and devops prometheus command paths that do not match their HTTP API routes. ADR 0037 requires this, and the issue body names ADR 0026 by mistake. Remove the old Grafana paths and keep the commands that already match or read files. Update the MCP exposure table and the generated command reference.

Acceptance criteria

Requirement: Grafana alert-rules list

The devops grafana alert-rules list command SHALL read the Grafana alert-rules route.

Scenario: Dry run prints the alert-rules route

  • WHEN A test runs uv run devops grafana alert-rules list --dry-run.
  • THEN The command exits 0, prints a GET request whose target ends in /api/v1/provisioning/alert-rules, and sends 0 HTTP requests.

Requirement: Grafana dashboards get

The devops grafana dashboards get <uid> command SHALL read one dashboard by UID and write it to the file of -o.

Scenario: Get sends the item route

  • WHEN A test runs uv run devops grafana dashboards get abc123 -o out.json against a fake Grafana server.
  • THEN The command sends GET /api/dashboards/uid/abc123 and writes the dashboard JSON to out.json.

Requirement: Grafana dashboards update

The devops grafana dashboards update <file> command SHALL create or replace a dashboard.

Scenario: Update sends overwrite true

  • WHEN A test runs uv run devops grafana dashboards update dashboard.json against a fake Grafana server.
  • THEN The command sends POST /api/dashboards/db with overwrite true in the request body.

Requirement: Grafana datasources list

The devops grafana datasources list command SHALL read the data sources collection.

Scenario: Data sources list sends the collection route

  • WHEN A test runs uv run devops grafana datasources list against a fake Grafana server.
  • THEN The command sends GET /api/datasources and prints the data sources.

Requirement: Prometheus rules list

The devops prometheus rules list command SHALL read the Prometheus rules route.

Scenario: Dry run prints the rules route

  • WHEN A test runs uv run devops prometheus rules list --dry-run.
  • THEN The command exits 0, prints a GET request whose target ends in /api/v1/rules, and sends 0 HTTP requests.

Requirement: Prometheus targets list

The devops prometheus targets list command SHALL read the Prometheus targets route.

Scenario: Targets list sends the targets route

  • WHEN A test runs uv run devops prometheus targets list against a fake Prometheus server.
  • THEN The command sends GET /api/v1/targets and prints the targets.

Requirement: Removed Grafana command paths

The old paths devops grafana alerts, devops grafana dashboards export and devops grafana dashboards import MUST exit with code 2.

Scenario: Removed Grafana command paths fail

  • WHEN A test runs each old path with the arguments that the old command accepted.
  • THEN Each command exits with code 2 and prints no request.

Requirement: Retained command paths

The commands grafana search, grafana dashboards list, grafana dashboards sync, grafana dashboards lint, prometheus query, prometheus query-range and prometheus analyze MUST keep their current paths.

Scenario: Retained command paths answer help

  • WHEN A test runs --help for each of these seven paths.
  • THEN Each command exits with code 0.

Requirement: MCP exposure table

CONST_MCP_EXPOSURE_TABLE MUST name no removed monitoring path and MUST name a new path wherever it named an old path.

Scenario: MCP exposure table test passes

  • WHEN A test runs uv run pytest tests/ai/mcp/test_mcp_exposure_table.py.
  • THEN The test passes, because no entry names a command that the rename removed.

Requirement: API command name test

tests/commands/test_api_command_names.py SHALL cover the renamed commands of the grafana and prometheus groups whose route gives the new path.

Scenario: API command name test passes for both groups

  • WHEN A test runs uv run pytest tests/commands/test_api_command_names.py -k 'grafana or prometheus'.
  • THEN The test passes for the five covered commands of the two groups.

Requirement: Dry-run class ratchet

Each renamed monitoring command MUST keep the dry-run class that its old path had.

Scenario: Dry-run class ratchet passes

  • WHEN A test runs uv run pytest tests/invariants/test_dry_run_class_ratchet.py.
  • THEN The test passes with the renamed command paths.

Requirement: Generated command reference

The generated command reference MUST name the renamed commands and MUST NOT name a removed path.

Scenario: Documentation check passes

  • WHEN A test runs uv run devops docs check.
  • THEN The command exits with code 0.

Existing Tool Considered

No open, maintained tool or library covers the need. The alternatives check of 2026-11-29 in the issue body records verdict none with no tool, and lists what a tool would lack. The change renames paths in existing command modules and builds no code, so it has no build cost.

Key questions

  • Which project record requires an API-based command to take its HTTP API route names?: ADR 0037 records the owner request of 2026-11-12 in feat(cli): tool commands pass unknown arguments to the tool #5223: a command for an API-based tool takes the names of the API route. The issue body cites ADR 0026, which records GitHub settings in OpenTofu. [sources: docs/adr/0037-tool-commands-mirror-and-pass-through-options.md, docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md]
  • Which name does the dashboard write command take: import, create or update?: Use update. The client sets overwrite true on POST /api/dashboards/db, so the call creates or replaces a dashboard. import names a different Grafana route. (best practice) [sources: src/devops_cli/grafana/client.py, src/devops_cli/commands/grafana.py, docs/adr/0037-tool-commands-mirror-and-pass-through-options.md]
    • Chosen: update. The call sets overwrite true, so it creates or replaces a dashboard.
    • Rejected: create. The call can replace an existing dashboard, so create alone is wrong.
    • Rejected: import. Grafana serves POST /api/dashboards/import with another meaning.
  • Which name does the single-dashboard read command take: export or get?: Use get. The route GET /api/dashboards/uid/{uid} reads one dashboard by UID, and the name test maps GET of an item route to get. The -o <file> option writes the result to a file. (best practice) [sources: tests/commands/test_api_command_names.py, src/devops_cli/grafana/client.py, src/devops_cli/commands/grafana.py]
    • Chosen: get. The route reads one dashboard by UID, and the name test maps an item GET to get.
    • Rejected: export. export names a file write and not the API read.
  • Do the collection commands take a list subcommand?: Add list. The name test maps GET of a collection route to list, and grafana dashboards list already uses this form. (best practice) [sources: tests/commands/test_api_command_names.py, src/devops_cli/commands/grafana.py, src/devops_cli/commands/prometheus.py]
    • Chosen: add list. A collection read is a list, and grafana dashboards list already uses this form.
    • Rejected: keep the bare name. A bare name hides the read operation and breaks the group pattern.
  • Which monitoring command paths stay as they are?: grafana search, grafana dashboards list, grafana dashboards sync, grafana dashboards lint, prometheus query, prometheus query-range and prometheus analyze stay. These commands read files, send several reads, or already name their route. (best practice) [sources: src/devops_cli/commands/grafana.py, src/devops_cli/commands/prometheus.py, docs/adr/0037-tool-commands-mirror-and-pass-through-options.md]
    • Chosen: keep the seven paths. No single API route names sync, lint or analyze, and the body keeps query and query-range.
    • Rejected: rename all seven to route names. No single route names the file reads and the multi-read commands.
  • Which monitoring commands join COVERED_API_COMMANDS of the API command name test?: Add the five commands whose route gives the new path: alert-rules list, dashboards get, datasources list, rules list and targets list. POST /api/dashboards/db derives devops grafana db create, so a test in tests/commands/test_grafana.py asserts the dashboards update path and its request instead. (best practice) [sources: tests/commands/test_api_command_names.py, tests/commands/test_grafana.py]
    • Chosen: cover the five matching commands. Each of the five route targets derives the new command path.
    • Rejected: cover all six with an override in the derivation. It changes the shared derivation of feat(argo): argo cd commands take the Argo CD route names #5230 for one route.
    • Rejected: cover no monitoring command. The body asks for both groups in the test.
  • Do the old Grafana command paths stay as aliases after the rename?: Remove the old paths. devops grafana alerts, devops grafana dashboards export and devops grafana dashboards import exit with code 2, as the removed Argo CD paths do. (best practice) [sources: docs/adr/0037-tool-commands-mirror-and-pass-through-options.md, tests/commands/test_api_command_names.py]
    • Chosen: remove the old paths. The route name is the only command name, so the old path exits with code 2.
    • Rejected: keep aliases. An alias keeps a name that does not match the route and hides the rename.
  • Which rows of CONST_MCP_EXPOSURE_TABLE change?: The table keeps its grafana dashboards list and prometheus query rows. Each row that names a renamed path takes the new path. tests/ai/mcp/test_mcp_exposure_table.py fails on an entry that names no command of the tree. [sources: src/devops_cli/config/constants.py:306, tests/ai/mcp/test_mcp_exposure_table.py]
  • Does this item still wait on feat(argo): argo cd commands take the Argo CD route names #5230?: No. tests/commands/test_api_command_names.py exists at this commit and covers argo cd applications and the removed argo cd apps paths, which feat(argo): argo cd commands take the Argo CD route names #5230 delivered. [sources: tests/commands/test_api_command_names.py, docs/CLI_REFERENCE.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 12, 2026
  5. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 90a3d2a while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

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

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (4)

    Searches run:

    • Grafana Prometheus CLI wrapper open source commands alerts dashboards datasources, results: 5
    • open source tool generates CLI command names from OpenAPI HTTP routes, results: 5
    • grafana dashboards import export CLI tool github, results: 5
    • prometheus CLI rules targets query tool github, results: 5

    Sources:

  7. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  8. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

  9. added
    status/ready
    and removed
    status/new
    on Nov 29, 2026
  10. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

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

  11. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  12. removed
    status/in-review
    on Nov 29, 2026
  13. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 16:50 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/mediumpriority/p2-mediumscope/monitoringsource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions