Skip to content

Commit 4fb555a

Browse files
authored
Merge branch 'main' into seed-schemas-zstd3
2 parents ca2ee61 + 4fdea1a commit 4fb555a

28 files changed

Lines changed: 685 additions & 176 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@hyperdx/api': minor
3+
'@hyperdx/app': minor
4+
'@hyperdx/common-utils': minor
5+
---
6+
7+
feat: add optional `titleEmoji` webhook option; `false` removes the emoji prefix from notification titles sent through that webhook
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@hyperdx/api': patch
3+
'@hyperdx/common-utils': patch
4+
---
5+
6+
fix: reject alerts on dashboard tiles the alert checker never evaluates (PromQL
7+
tiles, and builder tiles with unsupported display types), and drop them when a
8+
dashboard is saved

‎packages/api/openapi.json‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5827,6 +5827,11 @@
58275827
"description": "Webhook description, shown in the UI",
58285828
"example": "Sends critical alerts to the #incidents channel"
58295829
},
5830+
"titleEmoji": {
5831+
"type": "boolean",
5832+
"description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.",
5833+
"example": false
5834+
},
58305835
"updatedAt": {
58315836
"type": "string",
58325837
"format": "date-time",
@@ -5879,6 +5884,11 @@
58795884
"description": "Webhook description, shown in the UI",
58805885
"example": "Routes alerts to incident.io for on-call escalation"
58815886
},
5887+
"titleEmoji": {
5888+
"type": "boolean",
5889+
"description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.",
5890+
"example": false
5891+
},
58825892
"updatedAt": {
58835893
"type": "string",
58845894
"format": "date-time",
@@ -5931,6 +5941,11 @@
59315941
"description": "Webhook description, shown in the UI",
59325942
"example": "Forwards alert payloads to an external monitoring service"
59335943
},
5944+
"titleEmoji": {
5945+
"type": "boolean",
5946+
"description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.",
5947+
"example": false
5948+
},
59345949
"body": {
59355950
"type": "string",
59365951
"description": "Optional request body template",
@@ -6023,7 +6038,7 @@
60236038
"service",
60246039
"url"
60256040
],
6026-
"description": "Webhook create/update body. `body`, `headers`, and `queryParams`\nonly take effect for services that issue a templated HTTP request\n(`generic`, `incidentio`). The `slack` service posts a fixed payload\nto its incoming-webhook URL and ignores them, so supplying any of\nthese fields on a `slack` webhook is rejected. `headers` and\n`queryParams` are write-only — they are accepted here but never\nreturned by any read endpoint, so secrets such as auth tokens do\nnot leak. On\nupdate (PUT), omitted readable fields (`description`, `body`) are\ncleared, while omitted `headers`/`queryParams` are preserved —\nsend an explicit `{}` to clear them. Exception: if the destination\n(`url` or `service`) changes, omitted `headers`/`queryParams` are\ncleared rather than preserved, so stored secrets are never forwarded\nto a new destination; re-supply them for the new destination.\n",
6041+
"description": "Webhook create/update body. `body`, `headers`, and `queryParams`\nonly take effect for services that issue a templated HTTP request\n(`generic`, `incidentio`). The `slack` service posts a fixed payload\nto its incoming-webhook URL and ignores them, so supplying any of\nthese fields on a `slack` webhook is rejected. `headers` and\n`queryParams` are write-only — they are accepted here but never\nreturned by any read endpoint, so secrets such as auth tokens do\nnot leak. On\nupdate (PUT), omitted readable fields (`description`, `titleEmoji`, `body`) are\ncleared, while omitted `headers`/`queryParams` are preserved —\nsend an explicit `{}` to clear them. Exception: if the destination\n(`url` or `service`) changes, omitted `headers`/`queryParams` are\ncleared rather than preserved, so stored secrets are never forwarded\nto a new destination; re-supply them for the new destination.\n",
60276042
"properties": {
60286043
"name": {
60296044
"type": "string",
@@ -6054,6 +6069,11 @@
60546069
"description": "Webhook description, shown in the UI.",
60556070
"example": "Sends critical alerts to the #incidents channel"
60566071
},
6072+
"titleEmoji": {
6073+
"type": "boolean",
6074+
"description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.",
6075+
"example": false
6076+
},
60576077
"body": {
60586078
"type": "string",
60596079
"maxLength": 16384,
@@ -9178,7 +9198,7 @@
91789198
"/api/v2/webhooks/{id}": {
91799199
"put": {
91809200
"summary": "Update Webhook",
9181-
"description": "Replaces an existing webhook. Readable optional fields\n(`description`, `body`) are a full replace: omitting them clears\nthem. The write-only fields `headers` and `queryParams` are never\nreturned on read, so omitting them preserves the stored values;\nsend an explicit empty object (`{}`) to clear them. Exception: if the\ndestination (`url` or `service`) changes, omitted `headers`/\n`queryParams` are cleared rather than preserved so stored secrets are\nnever forwarded to a new destination.\n",
9201+
"description": "Replaces an existing webhook. Readable optional fields\n(`description`, `titleEmoji`, `body`) are a full replace: omitting them clears\nthem. The write-only fields `headers` and `queryParams` are never\nreturned on read, so omitting them preserves the stored values;\nsend an explicit empty object (`{}`) to clear them. Exception: if the\ndestination (`url` or `service`) changes, omitted `headers`/\n`queryParams` are cleared rather than preserved so stored secrets are\nnever forwarded to a new destination.\n",
91829202
"operationId": "updateWebhook",
91839203
"tags": [
91849204
"Webhooks"

‎packages/api/src/controllers/alerts.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import {
22
displayTypeSupportsBuilderAlerts,
33
displayTypeSupportsRawSqlAlerts,
44
isFormulaSourceKind,
5+
savedChartConfigSupportsAlerts,
56
validateRawSqlForAlert,
67
} from '@hyperdx/common-utils/dist/core/utils';
7-
import { isRawSqlSavedChartConfig } from '@hyperdx/common-utils/dist/guards';
8+
import {
9+
isPromqlSavedChartConfig,
10+
isRawSqlSavedChartConfig,
11+
} from '@hyperdx/common-utils/dist/guards';
812
import { isRangeThresholdType } from '@hyperdx/common-utils/dist/types';
913
import { groupBy } from 'lodash';
1014
import { Types } from 'mongoose';
@@ -91,13 +95,20 @@ export const validateAlertInput = async (
9195
throw new Api400Error('Tile not found');
9296
}
9397

94-
if (tile.config != null && isRawSqlSavedChartConfig(tile.config)) {
95-
if (!displayTypeSupportsRawSqlAlerts(tile.config.displayType)) {
96-
throw new Api400Error(
97-
'Alerts on Raw SQL tiles are only supported for Line, Stacked Bar, or Number display types',
98-
);
98+
// The alert checker cannot evaluate these tiles, so the alert would never run.
99+
if (tile.config != null && !savedChartConfigSupportsAlerts(tile.config)) {
100+
if (isPromqlSavedChartConfig(tile.config)) {
101+
throw new Api400Error('Alerts are not supported on PromQL tiles');
99102
}
103+
const tileKind = isRawSqlSavedChartConfig(tile.config)
104+
? 'Raw SQL tiles'
105+
: 'dashboard tiles';
106+
throw new Api400Error(
107+
`Alerts on ${tileKind} are only supported for Line, Stacked Bar, or Number display types`,
108+
);
109+
}
100110

111+
if (tile.config != null && isRawSqlSavedChartConfig(tile.config)) {
101112
const { errors } = validateRawSqlForAlert(tile.config);
102113
if (errors.length > 0) {
103114
throw new Api400Error(

‎packages/api/src/controllers/dashboard.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { savedChartConfigSupportsAlerts } from '@hyperdx/common-utils/dist/core/utils';
12
import {
23
DashboardWithoutIdSchema,
34
resolveChartPaletteToken,
@@ -20,10 +21,19 @@ import type { AlertDocument, IAlert } from '@/models/alert';
2021
import Dashboard, { IDashboard } from '@/models/dashboard';
2122
import { resolveAlertDisplayFields } from '@/utils/alerts';
2223

24+
// Drop alerts on tiles the alert checker cannot evaluate (e.g. PromQL), so
25+
// they are never stored and any existing ones are deleted on save.
26+
function getSupportedTileAlert(tile: Tile) {
27+
return savedChartConfigSupportsAlerts(tile.config)
28+
? tile.config.alert
29+
: undefined;
30+
}
31+
2332
function pickAlertsByTile(tiles: Tile[]) {
2433
return tiles.reduce((acc, tile) => {
25-
if (tile.config.alert) {
26-
acc[tile.id] = tile.config.alert;
34+
const alert = getSupportedTileAlert(tile);
35+
if (alert) {
36+
acc[tile.id] = alert;
2737
}
2838
return acc;
2939
}, {});
@@ -94,7 +104,7 @@ async function syncDashboardAlerts(
94104

95105
const newTilesForAlertSync: TileForAlertSync[] = newTiles.map(t => ({
96106
id: t.id,
97-
config: { alert: t.config.alert },
107+
config: { alert: getSupportedTileAlert(t) },
98108
}));
99109
const { tileIds: newTileIds, tileIdsWithAlerts: newTileIdsWithAlerts } =
100110
extractTileAlertData(newTilesForAlertSync);

‎packages/api/src/controllers/webhook.ts‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface WebhookInput {
1111
service: WebhookService;
1212
url: string;
1313
description?: string;
14+
titleEmoji?: boolean;
1415
queryParams?: Record<string, string>;
1516
headers?: Record<string, string>;
1617
body?: string;
@@ -22,7 +23,16 @@ export interface WebhookInput {
2223
*/
2324
export async function createWebhook(
2425
team: ObjectId | string,
25-
{ name, service, url, description, queryParams, headers, body }: WebhookInput,
26+
{
27+
name,
28+
service,
29+
url,
30+
description,
31+
titleEmoji,
32+
queryParams,
33+
headers,
34+
body,
35+
}: WebhookInput,
2636
) {
2737
validateWebhookConfig({ service, url, body });
2838

@@ -32,6 +42,7 @@ export async function createWebhook(
3242
service,
3343
url,
3444
description,
45+
titleEmoji,
3546
queryParams,
3647
headers,
3748
body,
@@ -53,7 +64,16 @@ export type UpdateWebhookResult =
5364
export async function updateWebhook(
5465
team: ObjectId | string,
5566
webhookId: string,
56-
{ name, service, url, description, queryParams, headers, body }: WebhookInput,
67+
{
68+
name,
69+
service,
70+
url,
71+
description,
72+
titleEmoji,
73+
queryParams,
74+
headers,
75+
body,
76+
}: WebhookInput,
5777
): Promise<UpdateWebhookResult> {
5878
const existing = await Webhook.findOne({ _id: webhookId, team });
5979
if (existing == null) {
@@ -71,6 +91,9 @@ export async function updateWebhook(
7191
if (description === undefined) unsetFields.description = 1;
7292
else setFields.description = description;
7393

94+
if (titleEmoji === undefined) unsetFields.titleEmoji = 1;
95+
else setFields.titleEmoji = titleEmoji;
96+
7497
if (body === undefined) unsetFields.body = 1;
7598
else setFields.body = body;
7699

‎packages/api/src/mcp/tools/alerts/saveWebhook.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ const mcpSaveWebhookSchema = z.object({
5959
'Description shown in the UI. On update this is a full replace: ' +
6060
'omitting it clears the stored description.',
6161
),
62+
titleEmoji: z
63+
.boolean()
64+
.optional()
65+
.describe(
66+
'Set to false to omit the state emoji prefix from notification titles ' +
67+
'sent through this webhook. On update this is a full replace: ' +
68+
'omitting it restores the default prefix.',
69+
),
6270
headers: z
6371
.record(z.string(), z.string())
6472
.optional()
@@ -105,8 +113,8 @@ export function registerSaveWebhook({
105113
'clickstack_save_alert. For the slack service the url host must end ' +
106114
'in slack.com and headers/queryParams/body are not supported. On ' +
107115
'update, every alert using this webhook sends its next notifications ' +
108-
'with the new settings, including a changed url. description and body ' +
109-
'are a full replace (omitting them clears them), while write-only ' +
116+
'with the new settings, including a changed url. description, titleEmoji and ' +
117+
'body are a full replace (omitting them clears them), while write-only ' +
110118
'headers/queryParams are preserved when omitted (send {} to clear); ' +
111119
'changing url or service clears omitted headers/queryParams. ' +
112120
'url, headers, and queryParams are never returned.',

‎packages/api/src/models/webhook.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface IWebhook {
2323
updatedAt: Date;
2424
url?: string;
2525
description?: string;
26+
// false drops the state emoji prefix from notification titles
27+
titleEmoji?: boolean;
2628
// reminder to serialize/convert the Mongoose model instance to a plain javascript object when using
2729
// to strip the additional properties that are related to the Mongoose internal representation -> webhook.headers.toJSON()
2830
queryParams?: MongooseMap;
@@ -50,6 +52,10 @@ const WebhookSchema = new Schema<IWebhook>(
5052
type: String,
5153
required: false,
5254
},
55+
titleEmoji: {
56+
type: Boolean,
57+
required: false,
58+
},
5359
queryParams: {
5460
type: Map,
5561
of: String,

‎packages/api/src/routers/api/__tests__/alerts.int.test.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,68 @@ describe('alerts router', () => {
11421142
.expect(400);
11431143
});
11441144

1145+
it('rejects creating an alert on a builder table tile', async () => {
1146+
const tile = makeTile();
1147+
tile.config = { ...tile.config, displayType: DisplayType.Table };
1148+
const dashboard = await agent
1149+
.post('/dashboards')
1150+
.send({ name: 'Test Dashboard', tiles: [tile], tags: [] })
1151+
.expect(200);
1152+
1153+
const res = await agent
1154+
.post('/alerts')
1155+
.send(
1156+
makeAlertInput({
1157+
dashboardId: dashboard.body.id,
1158+
tileId: tile.id,
1159+
webhookId: webhook._id.toString(),
1160+
}),
1161+
)
1162+
.expect(400);
1163+
expect(JSON.stringify(res.body)).toContain(
1164+
'Alerts on dashboard tiles are only supported',
1165+
);
1166+
});
1167+
1168+
it('rejects creating an alert on a PromQL tile', async () => {
1169+
const promqlTileId = randomMongoId();
1170+
const dashboard = await Dashboard.create({
1171+
name: 'PromQL Dashboard',
1172+
team: team._id,
1173+
tiles: [
1174+
{
1175+
id: promqlTileId,
1176+
x: 0,
1177+
y: 0,
1178+
w: 6,
1179+
h: 3,
1180+
config: {
1181+
configType: 'promql',
1182+
name: 'Up',
1183+
displayType: DisplayType.Line,
1184+
source: randomMongoId(),
1185+
promqlExpression: [{ expression: 'up' }],
1186+
},
1187+
},
1188+
],
1189+
});
1190+
1191+
const res = await agent
1192+
.post('/alerts')
1193+
.send(
1194+
makeAlertInput({
1195+
dashboardId: dashboard._id.toString(),
1196+
tileId: promqlTileId,
1197+
webhookId: webhook._id.toString(),
1198+
}),
1199+
)
1200+
.expect(400);
1201+
expect(JSON.stringify(res.body)).toContain(
1202+
'Alerts are not supported on PromQL tiles',
1203+
);
1204+
expect(await Alert.countDocuments({ team: team._id })).toBe(0);
1205+
});
1206+
11451207
it('rejects creating an alert on a raw SQL tile without interval params', async () => {
11461208
const rawSqlTile = makeRawSqlTile({
11471209
sqlTemplate: 'SELECT count() FROM otel_logs',

0 commit comments

Comments
 (0)