[HDX-5080] Chart editor UI for metric formulas - #2909
Conversation
🦋 Changeset detectedLatest commit: 6c9d2db The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThe PR exposes metric formulas in the chart editor and carries their positional value-column contract through rendering, formatting, tables, drill-down behavior, and tile alerts.
Confidence Score: 4/5The PR is not yet safe to merge because series mutations can still silently change which metrics existing formula letters reference. Formula references resolve by series position, while the current move, duplicate, and remove handlers mutate only the series array; displaying updated badges does not preserve operand identity or rewrite affected expressions. Files Needing Attention: packages/app/src/components/DBEditTimeChartForm/ChartSeriesEditor.tsx and packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx
|
| Filename | Overview |
|---|---|
| packages/app/src/components/DBEditTimeChartForm/ChartEditorControls.tsx | Adds formula field-array controls, operand visibility, ratio exclusion, and formula-aware Number-series limits. |
| packages/app/src/components/DBEditTimeChartForm/ChartFormulaEditor.tsx | Introduces the formula expression, alias, validation, removal, and number-format editing UI. |
| packages/app/src/components/ChartEditor/utils.ts | Adds formula-capable display normalization and save-time structured formula validation. |
| packages/app/src/source.ts | Maps number formats and value-column counts across operand, formula, ratio, and hidden-operand query shapes. |
| packages/app/src/components/DBTableChart.tsx | Uses formula-aware value-column counts for group-by and per-column rendering behavior. |
| packages/app/src/components/DBTimeChart.tsx | Avoids deriving operand range filters from formula-only result columns. |
| packages/api/src/tasks/checkAlerts/index.ts | Preserves formula and ratio configuration while rebuilding metric tile queries for alert evaluation. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Editor[Chart editor series and formulas] --> Validation[Formula validation]
Validation --> Saved[Saved chart config]
Saved --> Query[Composed metric query]
Query --> Columns[Operand and formula columns]
Columns --> Charts[Time, table, and number charts]
Saved --> Alerts[Tile alert config reconstruction]
Alerts --> AlertQuery[Formula-only alert query]
AlertQuery --> Threshold[Threshold evaluation]
Reviews (5): Last reviewed commit: "fix: evaluate metric formulas in tile al..." | Re-trigger Greptile
Deep Review✅ No critical issues found. The diff was traced against the renderer's actual projection contract in 🟡 P2 — recommended
🔵 P3 nitpicks (3)
Reviewers (6): correctness, adversarial, kieran-typescript, testing, maintainability, reliability. Testing gaps:
|
8d9e37e to
41b2354
Compare
2067484 to
226e1a9
Compare
226e1a9 to
1010ee4
Compare
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Additional context: touches background tasks or the delivery pipeline lightly (11 lines, under the 30-line bar for Tier 4) Review process: Full human review — logic, architecture, edge cases. Stats
|
E2E Test Results✅ All tests passed • 225 passed • 1 skipped • 829s
Tests ran across 3 shards in parallel. |
Expose metric formulas (HDX-5078 schema, HDX-5079 rendering) in the chart editor for metric sources: - Formula rows in the builder (Add Formula / Remove Formula) with a letter-ref expression input, alias, and per-formula number format - Inline validation via the structured validator (malformed expressions, unknown series refs) plus save-time validation in validateChartForm - Letter badges (A, B, C) on metric series rows so refs are discoverable - Show input series toggle (showOperandSeries) for formula-only output; Number tiles default to hidden operands since they render the first value column - Formulas and the As Ratio toggle are mutually exclusive in the editor - normalizeChartConfig strips formulas for non-metric sources and display types the composed metric query does not render - useChartNumberFormats / DBTableChart / DBTimeChart updated for the formula-aware value-column projection (operands first unless hidden, then formula columns)
1010ee4 to
862a3cf
Compare
getChartConfigFromAlert rebuilds a builder tile's chart config from an explicit field list and dropped formulas/showOperandSeries, so an alert on a formula tile queried only the raw operand series and compared the threshold against the last operand's value (e.g. raw bytes) instead of the formula result — regardless of the tile's "Show input series" toggle. - Pass formulas through and always drop operand columns from the alert query (showOperandSeries: false) so the formula is the value column parseAlertData picks - Also pass ratioMode through: grouped share_of_total ratio tile alerts previously evaluated as per_group (the default) - Integration tests: formula value drives the alert (value distinct from both operands), toggle-independence, NULL formula (zero denominator) skipped, and share_of_total ratioMode honored


Summary
Exposes metric formulas (HDX-5078's
formulasconfig, rendered by HDX-5079) in the chart editor for metric sources, so a derived series likeA / (A + B + C) * 100can be built, validated, saved, and reloaded from the UI.Rebased onto main now that #2908 (HDX-5079 rendering) has merged.
Editor
ChartFormulaEditor) on metric-source builder charts (time series / table / number): "Add Formula" appends a row with a monospace letter-ref expression input, an alias, a per-formula number format (reuses the per-series format drawer), and "Remove Formula".validateFormula): malformed expressions, unknown series refs, constant-only expressions, etc. surface live under the input;validateChartFormblocks save/run with the same messages so an invalid expression can never reach ClickHouse.A,B,C, ...) on metric series rows so formula refs are discoverable.showOperandSeries(formula + raw operand series vs formula column(s) only). Adding a formula on a Number tile defaults operands to hidden, since Number tiles render the first value column.A / (A + B + C)can be built.normalizeChartConfigstripsformulas/showOperandSerieson save for non-metric sources and for display types the composed metric query does not render (pie/bar/heatmap/search/patterns), mirroring the existingmetricName/havingstripping. The form state keeps them, so switching back restores the rows.Rendering consumers (positional value-column contract)
The composed metric query projects operand columns (unless hidden) then formula columns, ahead of group-by passthrough columns. Updated the consumers that map columns positionally:
useChartNumberFormats: operand columns →select[i].numberFormat, formula columns →formulas[j].numberFormat, both falling back to the chart-wide format; chart-wide axis format prefers formula formats when operands are hidden.getBuilderValueColumnCounthelper (formula/ratio-aware) used byDBTableChartfor group-by column inference; per-column color mapping skips hidden-operand formula configs.DBTimeChartdrill-down skips the value-range filter when operands are hidden (formula columns don't map ontoselectexpressions).alias || expression).Persistence needs no API changes: tiles validate against
SavedChartConfigSchema, which already carriesformulas/showOperandSeries, andbuilderToRawSqlalready rejects formula configs with a clear message on the Builder → SQL switch.Alerts on formula tiles (
packages/api)Contrary to #2908's "alerts work with no changes" claim, the alert task does not run the tile config as-is —
getChartConfigFromAlertrebuilds it from an explicit field list that droppedformulas/showOperandSeries. An alert on a formula tile therefore queried only the raw operand series and compared the threshold against the last operand's value (e.g.740442112.0 meets or exceeds 0.1for a byte-valued operand), regardless of the tile's "Show input series" toggle. Fixed here:formulasis passed through, and operand columns are always dropped from the alert query (showOperandSeries: false) so the formula is the value columnparseAlertDatapicks — the alert evaluates exactly what the tile displays.ratioModeis now passed through, so groupedshare_of_totalratio tile alerts no longer silently evaluate asper_group.make dev-int FILE=checkAlerts, 168 passing): formula value drives the alert (fixture chosen so the formula result differs from both operands), toggle-independence, NULL formula (zero denominator) skipped without NaN history, andshare_of_totalhonored (asserting the exact share value aper_groupfallback couldn't produce).Testing
make ci-lint,make ci-unitpass.DBEditTimeChartForm.test.tsx: Add/Remove Formula, inline validation (malformed / unknown ref / clears when fixed), save round-trip, save blocked on invalid expression, ratio mutual exclusion,showOperandSeriestoggle, non-metric sources show no formula controls.ChartEditor/utils.test.ts:validateChartFormformula rules (including the Number-tile cap lift) and normalization stripping/round-trip.source.test.ts:useChartNumberFormatsformula-column mapping (operands shown/hidden, ratio precedence, chart-format fallbacks) andgetBuilderValueColumnCount.make dev-e2e FILE=dashboard GREP="Metric formulas", passing): creates a metric table tile with two gauge series +A / (A + B) * 100, asserts the inline error for an invalid ref, hides operands, saves, reloads the page, verifies the formula column renders with a finite value, and reopens the editor to verify the round-trip.How to test on Vercel preview
A/Bbadges), click Add Formula, enterA / (A + B) * 100.A / Cto see the inline error; toggle Show input series; save, reload, and confirm the tile renders the formula series.References
Screenshots