Repository navigation
[HDX-5191] Support chart alerts in the external API v2 and MCP #3043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
81925f3
3dab96c
339f718
1d0a5d5
04dad3a
cef1198
9af7b7d
fe52e6e
9eee2d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| '@hyperdx/api': minor | ||
| --- | ||
|
|
||
| Support inline chart alerts (source `inline` + `chartConfig`) in the external | ||
| API v2 and the MCP `clickstack_save_alert` / `clickstack_get_alert` tools. | ||
| Inline alerts can now be created, updated, listed, and deleted through | ||
| `/api/v2/alerts` using the same tile-config dialect as v2 dashboards, with the | ||
| same validation rules as the internal API: display-type allowlist, metric | ||
| formula validation, the formula source-kind gate, raw SQL template validation, | ||
| and team-scoped source/connection ownership. Passing a `chartConfig` to a | ||
| `tile` or `saved_search` alert is now rejected instead of silently dropped, | ||
| and reading an inline alert whose config carries internal-only fields omits | ||
| `chartConfig` rather than returning a lossy approximation. | ||
|
|
||
| Also fixes three pre-existing issues on the external v2 dashboards path: a | ||
| gauge tile saved through `clickstack_save_dashboard` with `isDelta: true` was | ||
| persisted as a non-delta (the flag was dropped converting MCP tiles to the | ||
| internal shape); a tile config carrying an unrecognized `configType` (e.g. | ||
| `promql`) was silently stored as a builder config and skipped the formula and | ||
| number-select rules, and is now rejected; and validation errors on alert | ||
| bodies no longer collapse to `Invalid input` — the schema reports the failing | ||
| branch's own message. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { | ||
| displayTypeSupportsBuilderAlerts, | ||
| displayTypeSupportsRawSqlAlerts, | ||
| isFormulaSourceKind, | ||
| validateRawSqlForAlert, | ||
| } from '@hyperdx/common-utils/dist/core/utils'; | ||
| import { isRawSqlSavedChartConfig } from '@hyperdx/common-utils/dist/guards'; | ||
|
|
@@ -189,6 +190,19 @@ export const validateAlertInput = async ( | |
| if (source == null) { | ||
| throw new Api400Error('Source not found'); | ||
| } | ||
|
|
||
| // Same formula source-kind gate as dashboard tiles ("Add Formula" is | ||
| // disabled in the editor for these kinds), so the API cannot persist a | ||
| // config the editor refuses. | ||
| if ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — Formula source-kind gate is unscoped on update, so a later source-kind change permanently blocks editing an existing alert
|
||
| 'formulas' in chartConfig && | ||
| (chartConfig.formulas?.length ?? 0) > 0 && | ||
| !isFormulaSourceKind(source.kind) | ||
| ) { | ||
| throw new Api400Error( | ||
| 'Alerts with formulas require a Metric, Log, or Trace source', | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 minor — New formula source-kind gate has no "unchanged config" grandfathering, unlike the parallel dashboard-tile gate
filterChangedFormulaTiles(packages/api/src/routers/external-api/v2/utils/dashboards.ts:1121) deliberately skips this check for a tile that already carried the same formulas on the same source, "so the user can edit other parts of the dashboard without being blocked when the source'skindwas changed after the formulas were originally accepted."validateAlertInputapplies the gate unconditionally on every create and update, so an existing inline alert whose source kind later changes becomes permanently un-editable — even to adjust its threshold or channels. Skip the check on update whenchartConfig.formulasandchartConfig.sourceare unchanged from the stored alert.