Skip to content

fix(alerts): pretty-print + highlight raw SQL, stop raw-query chart flash#155

Merged
Makisuo merged 1 commit into
mainfrom
feat/alerts-raw-sql-format-and-chart-flash
Jun 30, 2026
Merged

fix(alerts): pretty-print + highlight raw SQL, stop raw-query chart flash#155
Makisuo merged 1 commit into
mainfrom
feat/alerts-raw-sql-format-and-chart-flash

Conversation

@Makisuo

@Makisuo Makisuo commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

What

On the alert detail Overview (/alerts/$ruleId), two fixes for raw SQL rules:

  1. Raw SQL is now pretty-printed and syntax-highlighted. It was an unstyled, right-aligned monospace blob squeezed into a config cell. It now renders as a full-width code block with ClickHouse-aware highlighting that matches the dashboard SQL editor.
  2. No more "no chart for raw query" flash. Raw-SQL rules chart from their recorded checks, but the chart briefly showed the "Raw SQL has no live preview" placeholder before the separate listRuleChecks query resolved — a confusing "says no chart, then shows one" moment.

Why

useAlertRuleChart returns chartLoading: false immediately for raw queries (they have no warehouse preview), and the route only passed loading={chartLoading}. So on first paint data=[], checks=[], loading=false → the raw placeholder showed, then checks loaded and the chart replaced it.

How

  • apps/web/src/lib/sql-format.ts (new)formatSql(): a conservative, dependency-free, ClickHouse-aware pretty-printer. Breaks top-level clauses / SELECT columns / WHERE AND/OR onto their own lines while keeping string literals, comments, $__macros, Map['key'] access, and function-call commas (quantile(0.95)(Duration / 1e6)) atomic. Falls back to the original text on any error.
  • apps/web/src/lib/sql-format.test.ts (new) — 9 unit tests, including an exact-output assertion for the canonical alert query plus footgun coverage (nested vs top-level AND, map access, macros, string literals, GROUP BY, idempotency, no-throw on odd input).
  • apps/web/src/routes/alerts/$ruleId.tsx — render the Raw SQL via tokenizeSql(formatSql(...)) as a full-width highlighted block; gate the hero chart's loading on Result.isInitial(checksResult) for raw_query rules so the placeholder no longer flashes. The genuine "no checks recorded yet" empty state is unchanged.

Before:

SELECT quantile(0.95)(Duration / 1e6) AS value, count() AS samples FROM traces WHERE ServiceName = 'api-v2' AND SpanName = 'ChartService.getChartData' AND SpanAttributes['cache.fluxSeconds'] = '604800' AND $__timeFilter(Timestamp) AND $__orgFilter

After:

SELECT
  quantile(0.95)(Duration / 1e6) AS value,
  count() AS samples
FROM traces
WHERE ServiceName = 'api-v2'
  AND SpanName = 'ChartService.getChartData'
  AND SpanAttributes['cache.fluxSeconds'] = '604800'
  AND $__timeFilter(Timestamp)
  AND $__orgFilter

Verification

  • vitest run apps/web/src/lib/sql-format.test.ts → 9/9 pass.
  • bun --filter=@maple/web typecheck → clean.
  • Live browser pass was blocked by the local dev-server cap (another session held the slots); the formatter's exact output is asserted in tests and the route edits are mechanical.

🤖 Generated with Claude Code


Open in Devin Review

…lash

On the alert overview, raw-SQL rules showed their query as an unstyled,
right-aligned blob and flashed a "Raw SQL has no live preview" placeholder
before the checks-driven chart loaded.

- Add formatSql() (apps/web/src/lib/sql-format.ts): a conservative,
  dependency-free, ClickHouse-aware pretty-printer that breaks top-level
  clauses, SELECT columns, and WHERE AND/OR onto their own lines while keeping
  strings, comments, $__macros, Map['key'] access, and function-call commas
  atomic. Falls back to the original text on any failure. Unit-tested.
- Render the Raw SQL in the Configuration card as a full-width, syntax-
  highlighted code block (reusing tokenizeSql) that matches the dashboard SQL
  editor.
- Gate the hero chart's loading state on checks for raw_query rules
  (Result.isInitial(checksResult)) so the placeholder no longer flashes before
  the checks-driven chart appears; the genuine "no checks yet" empty state is
  unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pullfrog

pullfrog Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Your LLM provider API key was rejected. Rotate the key in your provider dashboard, then update the matching GitHub Actions secret.

Update repo secret → · Model settings → · Setup docs → · Ask in Discord →

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Rerun failed job ➔View workflow run | via Pullfrog | Using Claude Opus𝕏

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@Makisuo Makisuo merged commit 739608c into main Jun 30, 2026
7 checks passed
@Makisuo Makisuo deleted the feat/alerts-raw-sql-format-and-chart-flash branch June 30, 2026 23:44
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