Skip to content

feat(metrics): harden metrics scripts and correct discovery-time docs#54

Open
Licenser wants to merge 5 commits into
mainfrom
improve-metrics-skill
Open

feat(metrics): harden metrics scripts and correct discovery-time docs#54
Licenser wants to merge 5 commits into
mainfrom
improve-metrics-skill

Conversation

@Licenser

@Licenser Licenser commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Hardens the query-metrics / building-dashboards metrics scripts and fixes a documentation claim that contradicted actual behavior. All changes were verified live against the axiom deployment.

axiom-api

  • Add --connect-timeout (10s) and --max-time (120s), overridable via AXIOM_CONNECT_TIMEOUT / AXIOM_MAX_TIME. Requests now fail fast instead of hanging indefinitely.

metrics-info

  • URL-encode dataset, metric, and tag names plus time params (jq @uri) across all endpoint paths, so OTel names (/, ., spaces) and RFC3339 +offset survive reserved characters.
  • Relative --start/--end (now, now-<N>[smhdw]), resolved to RFC3339 UTC client-side because the info endpoints only parse RFC3339.
  • Concurrent per-tag value fetches in describe: collect → check all failures → then parse, so a failed fetch aborts loudly instead of emitting partial JSON.
  • Fail-loud type probe: propagate query failures instead of swallowing them, so a failed probe is never misreported as the tag being "absent".

query-metrics/SKILL.md

  • Document timeouts, single-quoting MPL, bounding group by cardinality, and 429 back-off.
  • Correct the relative-time docs. Previously claimed metrics-info accepts "the same relative forms as metrics-query" — it does not. metrics-query forwards times to the server unparsed (broader grammar, e.g. now-1y), while metrics-info only handles now / now-<N>[smhdw] client-side.

Verification (against axiom deployment)

Form metrics-query (server _mpl) metrics-info
now-7d OK OK
now-1y OK (server parses y) 400 (not in s/m/h/d/w)
now-1mo 400 (unexpected token "mo") 400 (RFC3339 parse error)

Also confirmed accurate against the live API and left unchanged: the {"code","message"} error shape + annotated MPL source-pointer, and the histogram bucket … using / quantile / temporality spec wording.

metrics-chart/SKILL.md

image

Test plan

  • bash -n passes on both metrics-info copies and metrics-query
  • Both metrics-info copies remain byte-identical
  • Live re-run confirms docs match behavior (now-7d OK / now-1y 400 in info; now-1y OK in query)

🤖 Generated with Claude Code


Note

Low Risk
Mostly additive CLI/docs and local chart rendering; script changes improve URL safety and error handling without altering auth or query semantics.

Overview
Adds a new metrics-chart skill that turns metrics v2/v3 JSON into multi-series line charts (stdlib braille ASCII by default, optional gnuplot PNG/SVG/sixel, series collapse/top-N, agent-friendly PNG handoff), plus examples and unit tests. The root README lists the skill.

axiom-api (query-metrics and building-dashboards) now uses 10s connect / 120s total curl timeouts, overridable via AXIOM_CONNECT_TIMEOUT / AXIOM_MAX_TIME.

metrics-info (both skill copies) is hardened: URL-encoding for dataset/metric/tag names and time query params; client-side now / now-<N>[smhdw] normalization (narrower than metrics-query); parallel per-tag value fetches in describe with fail-fast on errors; tag type probes exit on query failure instead of reporting "absent".

query-metrics/SKILL.md documents MPL single-quoting, high-cardinality group by risk, histogram bucket guidance, corrected relative-time semantics for metrics-info vs metrics-query, timeouts, and 429 backoff.

Reviewed by Cursor Bugbot for commit d174ce6. Bugbot is set up for automated code reviews on this repo. Configure here.

@Licenser Licenser force-pushed the improve-metrics-skill branch from 20f824c to 116b4aa Compare June 15, 2026 08:19
@Licenser Licenser requested a review from aisha331 June 15, 2026 13:02
Comment thread skills/metrics-chart/scripts/metrics_chart.py
Comment thread skills/metrics-chart/scripts/metrics_chart.py Outdated
Licenser and others added 4 commits July 6, 2026 11:47
axiom-api:
- Add --connect-timeout (10s) and --max-time (120s), overridable via
  AXIOM_CONNECT_TIMEOUT / AXIOM_MAX_TIME, so requests fail fast rather
  than hang.

metrics-info:
- URL-encode dataset, metric, and tag names plus time params (jq @uri)
  so OTel names and RFC3339 offsets survive reserved characters.
- Accept relative --start/--end (now, now-<N>[smhdw]); resolved to
  RFC3339 UTC client-side because the info endpoints only parse RFC3339.
- Fetch per-tag values concurrently in `describe`; collect, check all
  failures, then parse, so a failed fetch aborts instead of emitting
  partial JSON.
- Propagate type-probe query failures instead of swallowing them, so a
  failed query is never misreported as the tag being "absent".

query-metrics/SKILL.md:
- Document the timeouts, single-quoting MPL, bounding `group by`
  cardinality, and 429 back-off.
- Correct the relative-time docs: metrics-info handles only
  now / now-<N>[smhdw], while metrics-query forwards times to the server,
  which accepts a broader set (e.g. now-1y). Verified against the axiom
  deployment.

Both metrics-info copies (query-metrics, building-dashboards) kept in sync.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Render Axiom metrics query results (application/vnd.metrics.v3+json) as
multi-series line charts.

- Zero-dependency Python stdlib Unicode/braille renderer (default, works in
  any terminal/transcript/CI log)
- Optional gnuplot backend for PNG/SVG/sixel; font/line weight scale with the
  canvas; non-ASCII (e.g. em dash) emitted as real UTF-8
- Series reduction: collapse near-overlapping lines, cap at top-N by peak, and
  report dropped counts in the legend
- Local-time x-axis (--tz override), null points drawn as gaps, group_keys
  legends (e.g. "200 | GET"), units from response metadata
- auto format: inline image on image-capable terminals; a PNG file plus an
  explicit "display this file" instruction when piped (AI agent harness);
  ASCII in a plain terminal or when gnuplot is absent
- 35 unit tests (parser pinned to service/query/src/server/tests.rs goldens)
- Registered in the repo README and given a per-skill README

Co-authored-by: Claude <noreply@anthropic.com>
select_series caps with reps[:top_n], so --top 0 selected nothing and
negatives dropped a suffix instead of limiting to N peaks, leaving an
empty plot that crashes gnuplot on otherwise-valid JSON.

Validate --top at the CLI boundary with a positive-int argparse type
(exit 2 with a clear message) before any input is read. Add tests for
the helper and main() integration, and note the >= 1 constraint in
SKILL.md.

Co-authored-by: Claude <noreply@anthropic.com>
collapse_overlapping short-circuited on rng == 0, merging every series
whose values share a single number even when two series have no
timestamps in common. The later series was dropped from the chart and
legend despite never aligning with the kept line.

_aligned_max_diff already returns +inf for series with no shared points,
so the short-circuit was both wrong (merged disjoint lines) and redundant
(identical overlapping flat lines still collapse, since 0 <= eps*0). No
division by rng exists, so removing it carries no zero-division risk.
Add regression tests for the disjoint and overlapping flat-line cases.

Co-authored-by: Claude <noreply@anthropic.com>
@Licenser Licenser force-pushed the improve-metrics-skill branch from bfd99ff to c82aad1 Compare July 6, 2026 09:47

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c82aad1. Configure here.

Comment thread skills/metrics-chart/scripts/metrics_chart.py
_tz_offset_seconds returned 0 for tz=None because a naive datetime's
utcoffset() is None, so PNG/SVG/sixel charts labeled the x-axis in UTC
while ASCII used local time. Attach the local zone when tz is None, and
shift each epoch by the offset at its own instant so tick labels stay
correct across a DST transition instead of using one offset from the
first sample.

Co-authored-by: pi <noreply@earendil.works>
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.

1 participant