Public: anyone can read this; the crew can change it.

/explore evaluates rate, sum by and topk over the metric series and draws the result as a chart above a table #17063

opened this

Merged 44h 8m ago, live in production

/explore now has a metric query box for site admins. It takes a series name, rate(x[5m]), sum by (label)(x) and topk(n, x). The result draws as a chart.ts chart above a table, in boxes that hold their height.

Notes

opened this

/explore now has a metric query box for site admins. It takes a series name, rate(x[5m]), sum by (label)(x) and topk(n, x). The result draws as a chart.ts chart above a table, in boxes that hold their height. The new tests pass (10), as do the unused-exports, doorless, hollow, guide and other explore suites I ran, and tsc is clean. I did not run the whole suite.

What changed

  • Parser and evaluator: both are in src/boards/query.ts (parseMetric, evalMetric). The text is matched against a fixed grammar and never evaluated. Rows come through the existing runQuery, so scope, bound parameters and the row limit still apply.
  • Series: the metric names come from the reach source (visitors, server_p95, lcp_p75…) and the spawn_time source (p50, p95, budget). A name outside those is refused.
  • Refusals: an unsupported query is a 422 that names the first unsupported token. The page re-renders with that line, escaped, and carries no etag.
  • Caps: at most 8 lines, 120 table rows, query text up to 200 characters, topk up to 20, rate windows up to 31 days.
  • Action and page: exploreMetric, metricCells and metricLines in src/actions/explore.ts gate it to a site admin who is a person; anyone else gets no box and nothing runs. The page wiring is in src/web/studio/explore.ts, with the query in ?m=.
  • Terminal and docs: m in the terminal's data explorer prints the same rows as the page table. docs/features/explore.md has the how-to.
  • Tests: test/explore_query.test.ts covers each accepted form, refusals, the evaluator on a fixed series, the page (chart before table, escaped, 422, admin-only) and terminal parity. The test builds a real admin user rather than as never.

Reused: runQuery, drawChart and chartFrame, the data explorer's palette entry and prompt, and adminCookie/seedAdmin in tests.

Left out

  • Select-to-explain, pin and reports.
  • Real PromQL: no label matchers, arithmetic or other functions.
  • Metric series for non-admins, since reach and spawn_time are admin-only sources.
  • A rate window holding only one point yields nothing. The data is daily, so use windows of 2d or more.
  • sum by accepts only the source's own label, so it returns the same lines as the bare series.

Try it: as a site admin on the preview, open /explore?m=topk(3,server_p95), then /explore?m=avg(visitors) for the 422. In the terminal, open the data explorer and press m.

Review

[
  {"go": "/explore?m=server_p95", "look": "the chart sits above a table under the query line", "expect": "no layout shift; the list below is unchanged"},
  {"go": "/explore?m=avg(visitors)", "look": "one line under the box", "expect": "status 422, text: unsupported: \"avg\""},
  {"go": "/explore?m=topk(3,server_p95)", "look": "chart and table", "expect": "at most 3 lines, highest latest value first"}
]

Closes #17049

3 earlier comments
commented

/explore now has a metric query box for site admins. It takes a series name, rate(x[5m]), sum by (label)(x) and topk(n, x). The result draws as a chart.ts chart above a table, in boxes that hold their height. The new tests pass (10), as do the unused-exports, doorless, hollow, guide and other explore suites I ran, and tsc is clean. I did not run the whole suite.

What changed

  • Parser and evaluator: both are in src/boards/query.ts (parseMetric, evalMetric). The text is matched against a fixed grammar and never evaluated. Rows come through the existing runQuery, so scope, bound parameters and the row limit still apply.
  • Series: the metric names come from the reach source (visitors, server_p95, lcp_p75…) and the spawn_time source (p50, p95, budget). A name outside those is refused.
  • Refusals: an unsupported query is a 422 that names the first unsupported token. The page re-renders with that line, escaped, and carries no etag.
  • Caps: at most 8 lines, 120 table rows, query text up to 200 characters, topk up to 20, rate windows up to 31 days.
  • Action and page: exploreMetric, metricCells and metricLines in src/actions/explore.ts gate it to a site admin who is a person; anyone else gets no box and nothing runs. The page wiring is in src/web/studio/explore.ts, with the query in ?m=.
  • Terminal and docs: m in the terminal's data explorer prints the same rows as the page table. docs/features/explore.md has the how-to.
  • Tests: test/explore_query.test.ts covers each accepted form, refusals, the evaluator on a fixed series, the page (chart before table, escaped, 422, admin-only) and terminal parity. The test builds a real admin user rather than as never.

Reused: runQuery, drawChart and chartFrame, the data explorer's palette entry and prompt, and adminCookie/seedAdmin in tests.

Left out

  • Select-to-explain, pin and reports.
  • Real PromQL: no label matchers, arithmetic or other functions.
  • Metric series for non-admins, since reach and spawn_time are admin-only sources.
  • A rate window holding only one point yields nothing. The data is daily, so use windows of 2d or more.
  • sum by accepts only the source's own label, so it returns the same lines as the bare series.

Try it: as a site admin on the preview, open /explore?m=topk(3,server_p95), then /explore?m=avg(visitors) for the 422. In the terminal, open the data explorer and press m.

Review

[
  {"go": "/explore?m=server_p95", "look": "the chart sits above a table under the query line", "expect": "no layout shift; the list below is unchanged"},
  {"go": "/explore?m=avg(visitors)", "look": "one line under the box", "expect": "status 422, text: unsupported: \"avg\""},
  {"go": "/explore?m=topk(3,server_p95)", "look": "chart and table", "expect": "at most 3 lines, highest latest value first"}
]
commented

/explore now answers 200 for an admin who hasn't typed a query. The metric box had been returning 422 in that case, which is what failed the client-size and no-polling checks.

Cause. An empty metric box was parsed as a query, and the parser refused it. /explore then answered 422 for every admin visiting without ?m=.

Fix. An empty or blank box now runs nothing. A new mayQueryMetric check in src/actions/explore.ts decides who sees the form (admins who are people), and the page shows it from that check rather than from the result of a query. Typed queries behave as before, including the 422 with the unsupported token named.

Tests. test/client-size.test.ts, test/no-polling.test.ts and test/explore_query.test.ts pass (31 tests), and tsc is clean. I did not run the full suite; the forge runs it on the push.

Gate. gate.ts --fix reported three files with comment lines over 100 columns and left them for the nightly rewrap.

The commit carries a No door: line, because the terminal side and the how-to are unchanged by this fix.

commented

I fixed one of the four failures, which was caused by this pull, and pushed the fix. I can't say yet whether the daily-cap failure is real, and the check will have to confirm the rest.

  • First-view budgets (the two attention tests, which cover /changelog): the admin-only metric box on /explore adds its Run button, which is one more word and one more block. I raised the explore budget in docs/design/attention-budget.json from 46 words and 9 blocks to 47 and 10. A note in the file says why. test/attention.test.ts and test/attention-stamped.test.ts now pass.
  • "A cold home answers from the picture" (test/observability-budget.test.ts): it fails on a timing limit here, and the check log says it is red on main too, so it isn't counted against this pull. I didn't change it.
  • The daily-cap terminal test: I couldn't find it in the files I ran. test/bets.test.ts passes, but that is the only file I ran that mentions a daily cap. It looks like a timing flake in a part of the code this pull doesn't touch. If it fails again, the log will show why.
commented

All five of @juniper's points are done and pushed. The tests for the metric box, the terminal's data screen, the attention budget, client size and no-polling pass, tsc is clean and the design lint is clean. I did not run the full suite, and I did not try the preview.

  • sum by now sums. It adds the points that share a timestamp and returns one line named for the metric. On the fixed series, /x, /y and /z on 2026-10-01 give 114, then 30 and 50 for the next two days. The old test that asserted sum by equals the bare series now asserts these values.
  • Empty answer. The page shows one plain line, "No points: nothing matches this query.", with no empty chart or table. The terminal uses the same text from one shared NO_POINTS constant, so the two cannot drift. A page test covers it with rate(visitors[5m]).
  • Refusals. They now read avg is not supported. Try rate, sum by or topk. and still name the first bad token. An empty box says "Nothing to run." and an over-long one says "That query is too long."
  • Table size and blank line. The page uses MAX_TABLE instead of the literal 120, and the doubled blank line is gone.
  • New tests.
    • Page: rate(server_p95[2d]) answers 200 with a chart.
    • Cut: with ten routes, the page shows "Showing the first 8 lines by latest value." and cut is true, and topk(3, …) shows no such line.
    • Terminal: the m key is tested for an admin, for a refused query, and for a non-admin and a signed-out user. The non-admin and signed-out cases get no prompt and no answer.
  • How-to. I updated docs/features/explore.md for the sum behaviour, the empty line and the new refusal wording.

Earlier fixes still in this branch.

  • An empty box no longer returns 422 for admins. That bug failed the client-size and no-polling checks.
  • The explore attention budget is raised by one word and one block for the Run button, with a note in the budget file.
  • The observability-budget timing test is red on main too, so I left it alone.

What I did not do. The terminal screen still has its own mayExplore check, even though the page uses the new mayQueryMetric. They say the same thing, and I did not merge them in this round.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs