Skip to content

feat: add experimental metrics list command for metric name discovery#112

Open
sagivoulu-0 wants to merge 15 commits intomainfrom
eng-7969-featcli-add-metrics-list-command-for-metric-name-discovery
Open

feat: add experimental metrics list command for metric name discovery#112
sagivoulu-0 wants to merge 15 commits intomainfrom
eng-7969-featcli-add-metrics-list-command-for-metric-name-discovery

Conversation

@sagivoulu-0
Copy link
Copy Markdown

Why

The CLI has no way to discover available metric names. Users writing PromQL queries via dash0 metrics instant must already know exact metric names. The only discovery path today is the Dash0 UI Metric Explorer.

What

Adds dash0 -X metrics list for metric name discovery, backed by the Prometheus-compatible label values and metadata APIs.

  • -o table (default): Single NAME column via label values API (~850ms, ~348KB)
  • -o wide: NAME + TYPE + UNIT + DESCRIPTION via metadata API (~2s, ~1.1MB)
  • -o json: Array of objects with full metadata
  • -o csv: Same columns as wide
  • --filter for substring/regex matching on metric names (client-side)
  • --from/--to time range (default: last 1 hour)
  • --limit, --skip-header, --dataset flags
  • New shared ResolveToEpochSeconds() utility for Prometheus API time params

Linear: ENG-7969

🤖 Generated with Claude Code

sagivoulu-0 and others added 4 commits April 2, 2026 22:35
The Prometheus label values and metadata APIs require start/end as Unix
epoch seconds, unlike the Dash0 API which accepts relative expressions.
This utility handles "now", "now-1h", "now-7d", and absolute ISO 8601
timestamps.

Also adds .claude/settings.local.json to .gitignore.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds `dash0 -X metrics list` for metric name discovery. Supports:
- table output (names only, via label values API)
- wide output (name + type + unit + description, via metadata API)
- json and csv output formats
- --filter for substring/regex matching on metric names
- --from/--to time range (default: last 1 hour)
- --limit to cap results
- --skip-header for table/wide/csv

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
24 tests covering: table/wide/json/csv output, skip-header, filter
(substring + regex), limit, empty results, API errors, experimental
gate, time range params, dataset handling, auth header, alias (ls),
endpoint selection (label values vs metadata), and missing config.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Updates docs/commands.md with full flag reference, examples, and output
samples. Adds metrics list examples to README.md. Creates changelog
entry for the new experimental command.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

sagivoulu-0 and others added 7 commits April 2, 2026 22:57
Wide/json/csv formats now fetch both label values (time-scoped names)
and metadata (type/unit/help), then enrich only the names present in
the time range. This makes results consistent across all output formats.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prevents env var leaks between tests by using t.Setenv which
automatically restores the original value after the test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Package-level httpClient enables connection reuse between the label
values and metadata API calls in the wide/json/csv code path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Avoids checking regexErr on every iteration. Also caches the lowercased
filter string for the substring path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Ensures users see "unknown output format" instead of a misleading
"--skip-header is not supported" error when both are invalid.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Covers two previously untested paths: --skip-header with -o wide, and
agent mode auto-defaulting to JSON output when -o is omitted.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sagivoulu-0
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

sagivoulu-0 and others added 4 commits April 2, 2026 23:28
Other commands use a single sentence for the Long description. Removes
implementation details about the label values API, metadata API, and
filter regex behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds explanatory notes at the end of the Examples section (matching
the pattern used by logs query and spans query for column aliases).
Clarifies filter regex behavior and which formats include metadata.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Matches the convention used by logs query, spans query, traces get,
and teams commands throughout the codebase.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds now-1h as an example in the --to flag description so users know
relative time expressions work for both --from and --to.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sagivoulu-0 sagivoulu-0 marked this pull request as ready for review April 2, 2026 20:39
Copy link
Copy Markdown
Member

@mmanciop mmanciop left a comment

Choose a reason for hiding this comment

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

The filters have a different syntax than with other commands, that is going to be very surprising in a bad way.

$ dash0 metrics instant --query 'sum(rate(http_requests_total[5m]))'
```

### `metrics list` (experimental)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better make it a metrics get like traces get. List commands do not have filters and might never have, and metrics query is already planned to do something else.

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