diff --git a/.changeset/alert-title-emoji-toggle.md b/.changeset/alert-title-emoji-toggle.md new file mode 100644 index 0000000000..86158ae7c7 --- /dev/null +++ b/.changeset/alert-title-emoji-toggle.md @@ -0,0 +1,7 @@ +--- +'@hyperdx/api': minor +'@hyperdx/app': minor +'@hyperdx/common-utils': minor +--- + +feat: add optional `titleEmoji` webhook option; `false` removes the emoji prefix from notification titles sent through that webhook diff --git a/packages/api/openapi.json b/packages/api/openapi.json index f6ea5912f6..83203b68af 100644 --- a/packages/api/openapi.json +++ b/packages/api/openapi.json @@ -5827,6 +5827,11 @@ "description": "Webhook description, shown in the UI", "example": "Sends critical alerts to the #incidents channel" }, + "titleEmoji": { + "type": "boolean", + "description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.", + "example": false + }, "updatedAt": { "type": "string", "format": "date-time", @@ -5879,6 +5884,11 @@ "description": "Webhook description, shown in the UI", "example": "Routes alerts to incident.io for on-call escalation" }, + "titleEmoji": { + "type": "boolean", + "description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.", + "example": false + }, "updatedAt": { "type": "string", "format": "date-time", @@ -5931,6 +5941,11 @@ "description": "Webhook description, shown in the UI", "example": "Forwards alert payloads to an external monitoring service" }, + "titleEmoji": { + "type": "boolean", + "description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.", + "example": false + }, "body": { "type": "string", "description": "Optional request body template", @@ -6023,7 +6038,7 @@ "service", "url" ], - "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", + "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", "properties": { "name": { "type": "string", @@ -6054,6 +6069,11 @@ "description": "Webhook description, shown in the UI.", "example": "Sends critical alerts to the #incidents channel" }, + "titleEmoji": { + "type": "boolean", + "description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.", + "example": false + }, "body": { "type": "string", "maxLength": 16384, @@ -9178,7 +9198,7 @@ "/api/v2/webhooks/{id}": { "put": { "summary": "Update Webhook", - "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", + "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", "operationId": "updateWebhook", "tags": [ "Webhooks" diff --git a/packages/api/src/controllers/webhook.ts b/packages/api/src/controllers/webhook.ts index a37f41fcbe..5f5a66b30b 100644 --- a/packages/api/src/controllers/webhook.ts +++ b/packages/api/src/controllers/webhook.ts @@ -11,6 +11,7 @@ export interface WebhookInput { service: WebhookService; url: string; description?: string; + titleEmoji?: boolean; queryParams?: Record; headers?: Record; body?: string; @@ -22,7 +23,16 @@ export interface WebhookInput { */ export async function createWebhook( team: ObjectId | string, - { name, service, url, description, queryParams, headers, body }: WebhookInput, + { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + }: WebhookInput, ) { validateWebhookConfig({ service, url, body }); @@ -32,6 +42,7 @@ export async function createWebhook( service, url, description, + titleEmoji, queryParams, headers, body, @@ -53,7 +64,16 @@ export type UpdateWebhookResult = export async function updateWebhook( team: ObjectId | string, webhookId: string, - { name, service, url, description, queryParams, headers, body }: WebhookInput, + { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + }: WebhookInput, ): Promise { const existing = await Webhook.findOne({ _id: webhookId, team }); if (existing == null) { @@ -71,6 +91,9 @@ export async function updateWebhook( if (description === undefined) unsetFields.description = 1; else setFields.description = description; + if (titleEmoji === undefined) unsetFields.titleEmoji = 1; + else setFields.titleEmoji = titleEmoji; + if (body === undefined) unsetFields.body = 1; else setFields.body = body; diff --git a/packages/api/src/mcp/tools/alerts/saveWebhook.ts b/packages/api/src/mcp/tools/alerts/saveWebhook.ts index 3d0e0f801f..5542f47f60 100644 --- a/packages/api/src/mcp/tools/alerts/saveWebhook.ts +++ b/packages/api/src/mcp/tools/alerts/saveWebhook.ts @@ -59,6 +59,14 @@ const mcpSaveWebhookSchema = z.object({ 'Description shown in the UI. On update this is a full replace: ' + 'omitting it clears the stored description.', ), + titleEmoji: z + .boolean() + .optional() + .describe( + 'Set to false to omit the state emoji prefix from notification titles ' + + 'sent through this webhook. On update this is a full replace: ' + + 'omitting it restores the default prefix.', + ), headers: z .record(z.string(), z.string()) .optional() @@ -105,8 +113,8 @@ export function registerSaveWebhook({ 'clickstack_save_alert. For the slack service the url host must end ' + 'in slack.com and headers/queryParams/body are not supported. On ' + 'update, every alert using this webhook sends its next notifications ' + - 'with the new settings, including a changed url. description and body ' + - 'are a full replace (omitting them clears them), while write-only ' + + 'with the new settings, including a changed url. description, titleEmoji and ' + + 'body are a full replace (omitting them clears them), while write-only ' + 'headers/queryParams are preserved when omitted (send {} to clear); ' + 'changing url or service clears omitted headers/queryParams. ' + 'url, headers, and queryParams are never returned.', diff --git a/packages/api/src/models/webhook.ts b/packages/api/src/models/webhook.ts index c31bf1358c..58a5a87f54 100644 --- a/packages/api/src/models/webhook.ts +++ b/packages/api/src/models/webhook.ts @@ -23,6 +23,8 @@ export interface IWebhook { updatedAt: Date; url?: string; description?: string; + // false drops the state emoji prefix from notification titles + titleEmoji?: boolean; // reminder to serialize/convert the Mongoose model instance to a plain javascript object when using // to strip the additional properties that are related to the Mongoose internal representation -> webhook.headers.toJSON() queryParams?: MongooseMap; @@ -50,6 +52,10 @@ const WebhookSchema = new Schema( type: String, required: false, }, + titleEmoji: { + type: Boolean, + required: false, + }, queryParams: { type: Map, of: String, diff --git a/packages/api/src/routers/api/__tests__/webhooks.int.test.ts b/packages/api/src/routers/api/__tests__/webhooks.int.test.ts index 1bd86f6bfc..8fa8414e9b 100644 --- a/packages/api/src/routers/api/__tests__/webhooks.int.test.ts +++ b/packages/api/src/routers/api/__tests__/webhooks.int.test.ts @@ -121,6 +121,44 @@ describe('webhooks router', () => { expect(webhooks[0].url).toBe(MOCK_WEBHOOK.url); }); + it('POST / - stores titleEmoji false and GET / returns it', async () => { + const { agent } = await getLoggedInAgent(server); + + const response = await agent + .post('/webhooks') + .send({ ...MOCK_WEBHOOK, titleEmoji: false }) + .expect(200); + + expect(response.body.data.titleEmoji).toBe(false); + + const webhooks = await Webhook.find({}); + expect(webhooks).toHaveLength(1); + expect(webhooks[0].titleEmoji).toBe(false); + + const listResponse = await agent + .get('/webhooks') + .query({ service: WebhookService.Slack }) + .expect(200); + + expect(listResponse.body.data).toHaveLength(1); + expect(listResponse.body.data[0].titleEmoji).toBe(false); + }); + + it('POST / - leaves titleEmoji unset when not provided', async () => { + const { agent } = await getLoggedInAgent(server); + + const response = await agent + .post('/webhooks') + .send(MOCK_WEBHOOK) + .expect(200); + + expect(response.body.data).not.toHaveProperty('titleEmoji'); + + const webhooks = await Webhook.find({}); + expect(webhooks).toHaveLength(1); + expect(webhooks[0].titleEmoji).toBeUndefined(); + }); + it('POST / - returns 400 when webhook with same URL already exists', async () => { const { agent, team } = await getLoggedInAgent(server); @@ -787,6 +825,25 @@ describe('webhooks router', () => { }); }); + it('sets titleEmoji on an existing webhook', async () => { + const { agent, team } = await getLoggedInAgent(server); + + const webhook = await Webhook.create({ + ...MOCK_WEBHOOK, + team: team._id, + }); + + const response = await agent + .put(`/webhooks/${webhook._id}`) + .send({ ...MOCK_WEBHOOK, titleEmoji: false }) + .expect(200); + + expect(response.body.data.titleEmoji).toBe(false); + + const updatedWebhook = await Webhook.findById(webhook._id); + expect(updatedWebhook?.titleEmoji).toBe(false); + }); + it('returns 404 when webhook does not exist', async () => { const { agent } = await getLoggedInAgent(server); diff --git a/packages/api/src/routers/api/webhooks.ts b/packages/api/src/routers/api/webhooks.ts index 516cb283a2..16cec1b95c 100644 --- a/packages/api/src/routers/api/webhooks.ts +++ b/packages/api/src/routers/api/webhooks.ts @@ -167,6 +167,7 @@ router.post( body: z.object({ body: z.string().optional(), description: z.string().optional(), + titleEmoji: z.boolean().optional(), headers: z .record(webhookHeaderNameSchema, webhookHeaderValueSchema) .optional(), @@ -188,8 +189,16 @@ router.post( if (teamId == null) { return res.sendStatus(403); } - const { name, service, url, description, queryParams, headers, body } = - req.body; + const { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + } = req.body; // The unique index is on (team, service, name), so the pre-flight check // must query the same fields — otherwise a name+service collision slips // past this guard and surfaces as an uncaught duplicate-key 500 below. @@ -203,6 +212,7 @@ router.post( service, url, description, + titleEmoji, queryParams, headers, body, @@ -233,6 +243,7 @@ router.put( body: z.object({ body: z.string().optional(), description: z.string().optional(), + titleEmoji: z.boolean().optional(), headers: z .record(webhookHeaderNameSchema, webhookHeaderValueSchema) .optional(), @@ -254,8 +265,16 @@ router.put( if (teamId == null) { return res.sendStatus(403); } - const { name, service, url, description, queryParams, headers, body } = - req.body; + const { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + } = req.body; const { id } = req.params; const existingWebhook = await Webhook.findOne({ @@ -323,6 +342,7 @@ router.put( service, url: resolvedUrl, description, + titleEmoji, body, }; const $unset: Record = {}; diff --git a/packages/api/src/routers/external-api/__tests__/webhooks.int.test.ts b/packages/api/src/routers/external-api/__tests__/webhooks.int.test.ts index 60ec86ef90..b5370a7b50 100644 --- a/packages/api/src/routers/external-api/__tests__/webhooks.int.test.ts +++ b/packages/api/src/routers/external-api/__tests__/webhooks.int.test.ts @@ -331,6 +331,27 @@ describe('External API v2 Webhooks', () => { .expect(401); }); + it('should round-trip titleEmoji through create and list', async () => { + const response = await authRequest('post', WEBHOOKS_BASE_URL) + .send({ ...MOCK_SLACK_WEBHOOK, titleEmoji: false }) + .expect(200); + expect(response.body.data.titleEmoji).toBe(false); + + const stored = await Webhook.findById(response.body.data.id).lean(); + expect(stored?.titleEmoji).toBe(false); + + const list = await authRequest('get', WEBHOOKS_BASE_URL).expect(200); + expect(list.body.data[0].titleEmoji).toBe(false); + }); + + it('should leave titleEmoji unset when not provided', async () => { + const response = await authRequest('post', WEBHOOKS_BASE_URL) + .send(MOCK_SLACK_WEBHOOK) + .expect(200); + + expect(response.body.data).not.toHaveProperty('titleEmoji'); + }); + it('should create a Slack webhook and never return sensitive fields', async () => { const response = await authRequest('post', WEBHOOKS_BASE_URL) .send(MOCK_GENERIC_WEBHOOK) @@ -635,6 +656,36 @@ describe('External API v2 Webhooks', () => { expect(stored?.description).toBeUndefined(); }); + it('should set titleEmoji on update and clear it when omitted', async () => { + const created = await Webhook.create({ + ...MOCK_SLACK_WEBHOOK, + team: team._id, + }); + const base = { + name: MOCK_SLACK_WEBHOOK.name, + service: WebhookService.Slack, + url: MOCK_SLACK_WEBHOOK.url, + }; + + const set = await authRequest( + 'put', + `${WEBHOOKS_BASE_URL}/${created._id}`, + ) + .send({ ...base, titleEmoji: false }) + .expect(200); + expect(set.body.data.titleEmoji).toBe(false); + expect((await Webhook.findById(created._id).lean())?.titleEmoji).toBe( + false, + ); + + await authRequest('put', `${WEBHOOKS_BASE_URL}/${created._id}`) + .send(base) + .expect(200); + expect( + (await Webhook.findById(created._id).lean())?.titleEmoji, + ).toBeUndefined(); + }); + it('should preserve omitted queryParams when the destination is unchanged', async () => { const created = await Webhook.create({ ...MOCK_GENERIC_WEBHOOK, diff --git a/packages/api/src/routers/external-api/v2/webhooks.ts b/packages/api/src/routers/external-api/v2/webhooks.ts index 479334e13e..61ce85274e 100644 --- a/packages/api/src/routers/external-api/v2/webhooks.ts +++ b/packages/api/src/routers/external-api/v2/webhooks.ts @@ -135,6 +135,10 @@ function formatExternalWebhook( * type: string * description: Webhook description, shown in the UI * example: "Sends critical alerts to the #incidents channel" + * titleEmoji: + * type: boolean + * description: Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix. + * example: false * updatedAt: * type: string * format: date-time @@ -175,6 +179,10 @@ function formatExternalWebhook( * type: string * description: Webhook description, shown in the UI * example: Routes alerts to incident.io for on-call escalation + * titleEmoji: + * type: boolean + * description: Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix. + * example: false * updatedAt: * type: string * format: date-time @@ -215,6 +223,10 @@ function formatExternalWebhook( * type: string * description: Webhook description, shown in the UI * example: Forwards alert payloads to an external monitoring service + * titleEmoji: + * type: boolean + * description: Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix. + * example: false * body: * type: string * description: Optional request body template @@ -379,7 +391,7 @@ router.get( * `queryParams` are write-only — they are accepted here but never * returned by any read endpoint, so secrets such as auth tokens do * not leak. On - * update (PUT), omitted readable fields (`description`, `body`) are + * update (PUT), omitted readable fields (`description`, `titleEmoji`, `body`) are * cleared, while omitted `headers`/`queryParams` are preserved — * send an explicit `{}` to clear them. Exception: if the destination * (`url` or `service`) changes, omitted `headers`/`queryParams` are @@ -407,6 +419,10 @@ router.get( * maxLength: 2048 * description: Webhook description, shown in the UI. * example: "Sends critical alerts to the #incidents channel" + * titleEmoji: + * type: boolean + * description: Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix. + * example: false * body: * type: string * maxLength: 16384 @@ -611,14 +627,23 @@ router.post( return res.status(403).json({ message: 'Forbidden' }); } - const { name, service, url, description, queryParams, headers, body } = - req.body; + const { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + } = req.body; const webhook = await createWebhook(teamId, { name, service, url, description, + titleEmoji, queryParams, headers, body, @@ -647,7 +672,7 @@ router.post( * summary: Update Webhook * description: | * Replaces an existing webhook. Readable optional fields - * (`description`, `body`) are a full replace: omitting them clears + * (`description`, `titleEmoji`, `body`) are a full replace: omitting them clears * them. The write-only fields `headers` and `queryParams` are never * returned on read, so omitting them preserves the stored values; * send an explicit empty object (`{}`) to clear them. Exception: if the @@ -721,14 +746,23 @@ router.put( return res.status(403).json({ message: 'Forbidden' }); } - const { name, service, url, description, queryParams, headers, body } = - req.body; + const { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + } = req.body; const result = await updateWebhook(teamId, req.params.id, { name, service, url, description, + titleEmoji, queryParams, headers, body, diff --git a/packages/api/src/tasks/checkAlerts/__tests__/__snapshots__/renderAlertTemplate.int.test.ts.snap b/packages/api/src/tasks/checkAlerts/__tests__/__snapshots__/renderAlertTemplate.int.test.ts.snap index a0204eb5c7..3aa000f644 100644 --- a/packages/api/src/tasks/checkAlerts/__tests__/__snapshots__/renderAlertTemplate.int.test.ts.snap +++ b/packages/api/src/tasks/checkAlerts/__tests__/__snapshots__/renderAlertTemplate.int.test.ts.snap @@ -1,72 +1,72 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state above threshold=5 alertValue=10 1`] = `"🚨 Alert for "My Search" - 10 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state above threshold=5 alertValue=10 1`] = `"Alert for "My Search" - 10 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state above_exclusive threshold=5 alertValue=10 1`] = `"🚨 Alert for "My Search" - 10 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state above_exclusive threshold=5 alertValue=10 1`] = `"Alert for "My Search" - 10 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state below threshold=5 alertValue=2 1`] = `"🚨 Alert for "My Search" - 2 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state below threshold=5 alertValue=2 1`] = `"Alert for "My Search" - 2 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state below_or_equal threshold=5 alertValue=3 1`] = `"🚨 Alert for "My Search" - 3 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state below_or_equal threshold=5 alertValue=3 1`] = `"Alert for "My Search" - 3 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state between threshold=5 alertValue=6 1`] = `"🚨 Alert for "My Search" - 6 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state between threshold=5 alertValue=6 1`] = `"Alert for "My Search" - 6 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state equal threshold=5 alertValue=5 1`] = `"🚨 Alert for "My Search" - 5 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state equal threshold=5 alertValue=5 1`] = `"Alert for "My Search" - 5 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state not_between threshold=5 alertValue=12 1`] = `"🚨 Alert for "My Search" - 12 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state not_between threshold=5 alertValue=12 1`] = `"Alert for "My Search" - 12 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state not_equal threshold=5 alertValue=10 1`] = `"🚨 Alert for "My Search" - 10 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts ALERT state not_equal threshold=5 alertValue=10 1`] = `"Alert for "My Search" - 10 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) above threshold=5 okValue=3 1`] = `"✅ Alert for "My Search" - 3 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) above threshold=5 okValue=3 1`] = `"Alert for "My Search" - 3 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) above_exclusive threshold=5 okValue=3 1`] = `"✅ Alert for "My Search" - 3 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) above_exclusive threshold=5 okValue=3 1`] = `"Alert for "My Search" - 3 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) below threshold=5 okValue=10 1`] = `"✅ Alert for "My Search" - 10 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) below threshold=5 okValue=10 1`] = `"Alert for "My Search" - 10 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) below_or_equal threshold=5 okValue=10 1`] = `"✅ Alert for "My Search" - 10 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) below_or_equal threshold=5 okValue=10 1`] = `"Alert for "My Search" - 10 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) between threshold=5 okValue=10 1`] = `"✅ Alert for "My Search" - 10 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) between threshold=5 okValue=10 1`] = `"Alert for "My Search" - 10 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) equal threshold=5 okValue=10 1`] = `"✅ Alert for "My Search" - 10 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) equal threshold=5 okValue=10 1`] = `"Alert for "My Search" - 10 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) not_between threshold=5 okValue=6 1`] = `"✅ Alert for "My Search" - 6 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) not_between threshold=5 okValue=6 1`] = `"Alert for "My Search" - 6 lines found"`; -exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) not_equal threshold=5 okValue=5 1`] = `"✅ Alert for "My Search" - 5 lines found"`; +exports[`buildAlertMessageTemplateTitle saved search alerts OK state (resolved) not_equal threshold=5 okValue=5 1`] = `"Alert for "My Search" - 5 lines found"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state above threshold=5 alertValue=10 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 10 meets or exceeds 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state above threshold=5 alertValue=10 1`] = `"Alert for "My Dashboard - Test Chart" - 10 meets or exceeds 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state above_exclusive threshold=5 alertValue=10 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 10 exceeds 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state above_exclusive threshold=5 alertValue=10 1`] = `"Alert for "My Dashboard - Test Chart" - 10 exceeds 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state below threshold=5 alertValue=2 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 2 falls below 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state below threshold=5 alertValue=2 1`] = `"Alert for "My Dashboard - Test Chart" - 2 falls below 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state below_or_equal threshold=5 alertValue=3 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 3 falls to or below 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state below_or_equal threshold=5 alertValue=3 1`] = `"Alert for "My Dashboard - Test Chart" - 3 falls to or below 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state between threshold=5 alertValue=6 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 6 falls between 5 and 7"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state between threshold=5 alertValue=6 1`] = `"Alert for "My Dashboard - Test Chart" - 6 falls between 5 and 7"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state decimal threshold 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 10.1 meets or exceeds 1.5"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state decimal threshold 1`] = `"Alert for "My Dashboard - Test Chart" - 10.1 meets or exceeds 1.5"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state equal threshold=5 alertValue=5 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 5 equals 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state equal threshold=5 alertValue=5 1`] = `"Alert for "My Dashboard - Test Chart" - 5 equals 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state integer threshold rounds value 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 11 meets or exceeds 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state integer threshold rounds value 1`] = `"Alert for "My Dashboard - Test Chart" - 11 meets or exceeds 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state not_between threshold=5 alertValue=12 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 12 falls outside 5 and 7"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state not_between threshold=5 alertValue=12 1`] = `"Alert for "My Dashboard - Test Chart" - 12 falls outside 5 and 7"`; -exports[`buildAlertMessageTemplateTitle tile alerts ALERT state not_equal threshold=5 alertValue=10 1`] = `"🚨 Alert for "My Dashboard - Test Chart" - 10 does not equal 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts ALERT state not_equal threshold=5 alertValue=10 1`] = `"Alert for "My Dashboard - Test Chart" - 10 does not equal 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) above threshold=5 okValue=3 1`] = `"✅ Alert for "My Dashboard - Test Chart" - 3 falls below 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) above threshold=5 okValue=3 1`] = `"Alert for "My Dashboard - Test Chart" - 3 falls below 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) above_exclusive threshold=5 okValue=3 1`] = `"✅ Alert for "My Dashboard - Test Chart" - 3 falls to or below 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) above_exclusive threshold=5 okValue=3 1`] = `"Alert for "My Dashboard - Test Chart" - 3 falls to or below 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) below threshold=5 okValue=10 1`] = `"✅ Alert for "My Dashboard - Test Chart" - 10 meets or exceeds 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) below threshold=5 okValue=10 1`] = `"Alert for "My Dashboard - Test Chart" - 10 meets or exceeds 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) below_or_equal threshold=5 okValue=10 1`] = `"✅ Alert for "My Dashboard - Test Chart" - 10 exceeds 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) below_or_equal threshold=5 okValue=10 1`] = `"Alert for "My Dashboard - Test Chart" - 10 exceeds 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) between threshold=5 okValue=10 1`] = `"✅ Alert for "My Dashboard - Test Chart" - 10 falls outside 5 and 7"`; +exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) between threshold=5 okValue=10 1`] = `"Alert for "My Dashboard - Test Chart" - 10 falls outside 5 and 7"`; -exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) equal threshold=5 okValue=10 1`] = `"✅ Alert for "My Dashboard - Test Chart" - 10 does not equal 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) equal threshold=5 okValue=10 1`] = `"Alert for "My Dashboard - Test Chart" - 10 does not equal 5"`; -exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) not_between threshold=5 okValue=6 1`] = `"✅ Alert for "My Dashboard - Test Chart" - 6 falls between 5 and 7"`; +exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) not_between threshold=5 okValue=6 1`] = `"Alert for "My Dashboard - Test Chart" - 6 falls between 5 and 7"`; -exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) not_equal threshold=5 okValue=5 1`] = `"✅ Alert for "My Dashboard - Test Chart" - 5 equals 5"`; +exports[`buildAlertMessageTemplateTitle tile alerts OK state (resolved) not_equal threshold=5 okValue=5 1`] = `"Alert for "My Dashboard - Test Chart" - 5 equals 5"`; exports[`renderAlertTemplate saved search alerts ALERT state above threshold=5 alertValue=10 1`] = ` " diff --git a/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts b/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts index 8ef7412f5c..dda67b51b5 100644 --- a/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts +++ b/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts @@ -1488,13 +1488,13 @@ describe('checkAlerts', () => { buildAlertMessageTemplateTitle({ view: defaultSearchView, }), - ).toMatchInlineSnapshot(`"🚨 Alert for "My Search" - 10 lines found"`); + ).toMatchInlineSnapshot(`"Alert for "My Search" - 10 lines found"`); expect( buildAlertMessageTemplateTitle({ view: defaultChartView, }), ).toMatchInlineSnapshot( - `"🚨 Alert for "My Dashboard - Test Chart" - 5 meets or exceeds 1"`, + `"Alert for "My Dashboard - Test Chart" - 5 meets or exceeds 1"`, ); // Inline alerts default to the chart config's name expect( @@ -1502,41 +1502,7 @@ describe('checkAlerts', () => { view: defaultInlineAlertView, }), ).toMatchInlineSnapshot( - `"🚨 Alert for "Chart Alert Query" - 5 meets or exceeds 1"`, - ); - }); - - it('buildAlertMessageTemplateTitle with state parameter', () => { - // Test ALERT state (should have 🚨 emoji) - expect( - buildAlertMessageTemplateTitle({ - view: defaultSearchView, - state: AlertState.ALERT, - }), - ).toMatchInlineSnapshot(`"🚨 Alert for "My Search" - 10 lines found"`); - expect( - buildAlertMessageTemplateTitle({ - view: defaultChartView, - state: AlertState.ALERT, - }), - ).toMatchInlineSnapshot( - `"🚨 Alert for "My Dashboard - Test Chart" - 5 meets or exceeds 1"`, - ); - - // Test OK state (should have ✅ emoji) - expect( - buildAlertMessageTemplateTitle({ - view: defaultSearchView, - state: AlertState.OK, - }), - ).toMatchInlineSnapshot(`"✅ Alert for "My Search" - 10 lines found"`); - expect( - buildAlertMessageTemplateTitle({ - view: defaultChartView, - state: AlertState.OK, - }), - ).toMatchInlineSnapshot( - `"✅ Alert for "My Dashboard - Test Chart" - 5 meets or exceeds 1"`, + `"Alert for "Chart Alert Query" - 5 meets or exceeds 1"`, ); }); @@ -1556,7 +1522,7 @@ describe('checkAlerts', () => { view: decimalChartView, }), ).toMatchInlineSnapshot( - `"🚨 Alert for "My Dashboard - Test Chart" - 1111.1 meets or exceeds 1.5"`, + `"Alert for "My Dashboard - Test Chart" - 1111.1 meets or exceeds 1.5"`, ); // Test with multiple decimal places @@ -1574,7 +1540,7 @@ describe('checkAlerts', () => { view: multiDecimalChartView, }), ).toMatchInlineSnapshot( - `"🚨 Alert for "My Dashboard - Test Chart" - 1.1235 meets or exceeds 0.1234"`, + `"Alert for "My Dashboard - Test Chart" - 1.1235 meets or exceeds 0.1234"`, ); // Test with integer value and decimal threshold @@ -1592,7 +1558,7 @@ describe('checkAlerts', () => { view: integerValueView, }), ).toMatchInlineSnapshot( - `"🚨 Alert for "My Dashboard - Test Chart" - 10.00 meets or exceeds 0.12"`, + `"Alert for "My Dashboard - Test Chart" - 10.00 meets or exceeds 0.12"`, ); }); @@ -1728,7 +1694,7 @@ describe('checkAlerts', () => { }, }, }, - title: '🚨 Alert for "My Search" - 10 lines found', + title: 'Alert for "My Search" - 10 lines found', teamId: team._id.toString(), teamWebhooksById: new Map([ [webhook._id.toString(), webhook], @@ -1789,7 +1755,7 @@ describe('checkAlerts', () => { webhookName: 'My_Webhook', }, }, - title: '🚨 Alert for "My Search" - 10 lines found', + title: 'Alert for "My Search" - 10 lines found', teamId: team._id.toString(), teamWebhooksById: new Map([ [webhook._id.toString(), webhook], @@ -1875,7 +1841,7 @@ describe('checkAlerts', () => { }, }, }, - title: '🚨 Alert for "My Search" - 10 lines found', + title: 'Alert for "My Search" - 10 lines found', teamId: team._id.toString(), teamWebhooksById, }); @@ -1900,7 +1866,7 @@ describe('checkAlerts', () => { host: 'web2', }, }, - title: '🚨 Alert for "My Search" - 10 lines found', + title: 'Alert for "My Search" - 10 lines found', teamId: team._id.toString(), teamWebhooksById, }); @@ -1990,7 +1956,7 @@ describe('checkAlerts', () => { }, }, }, - title: '✅ Alert for "My Search" - 10 lines found', + title: 'Alert for "My Search" - 10 lines found', teamId: team._id.toString(), teamWebhooksById: new Map([ [webhook._id.toString(), webhook], @@ -2477,6 +2443,103 @@ describe('checkAlerts', () => { ); }); + it('SAVED_SEARCH alert - titleEmoji is applied per webhook on fired and resolved titles', async () => { + const { + team, + webhook, + connection, + source, + savedSearch, + clickhouseClient, + } = await setupSavedSearchAlertTest(); + webhook.titleEmoji = false; + await webhook.save(); + const emojiWebhook = await new Webhook({ + team: team._id, + service: 'slack', + url: 'https://hooks.slack.com/services/456', + name: 'Emoji_Webhook', + }).save(); + const teamWebhooksById = new Map([ + [webhook._id.toString(), webhook], + [emojiWebhook._id.toString(), emojiWebhook], + ]); + + const details = await createAlertDetails( + team, + source, + { + source: AlertSource.SAVED_SEARCH, + channel: { + type: 'webhook', + webhookId: webhook._id.toString(), + }, + interval: '5m', + thresholdType: AlertThresholdType.ABOVE, + threshold: 1, + savedSearchId: savedSearch.id, + message: '@webhook-Emoji_Webhook', + }, + { + taskType: AlertTaskType.SAVED_SEARCH, + savedSearch, + }, + ); + + await bulkInsertLogs([ + { + ServiceName: 'api', + Timestamp: new Date('2023-11-16T22:05:00.000Z'), + SeverityText: 'error', + Body: 'Oh no! Something went wrong!', + }, + { + ServiceName: 'api', + Timestamp: new Date('2023-11-16T22:05:00.000Z'), + SeverityText: 'error', + Body: 'Oh no! Something went wrong!', + }, + ]); + + await processAlertAtTime( + new Date('2023-11-16T22:12:00.000Z'), + details, + clickhouseClient, + connection.id, + alertProvider, + teamWebhooksById, + ); + expect((await Alert.findById(details.alert.id))!.state).toBe('ALERT'); + + await processAlertAtTime( + new Date('2023-11-16T22:20:00.000Z'), + details, + clickhouseClient, + connection.id, + alertProvider, + teamWebhooksById, + ); + expect((await Alert.findById(details.alert.id))!.state).toBe('OK'); + + const textsFor = (url: string) => + jest + .mocked(slack.postMessageToWebhook) + .mock.calls.filter(([calledUrl]) => calledUrl === url) + .map(([, payload]) => payload.text); + + const [plainFired, plainResolved] = textsFor( + 'https://hooks.slack.com/services/123', + ); + expect(plainFired).toBe('Alert for "My Search" - 2 lines found'); + expect(plainResolved).toMatch(/^Alert for "My Search"/); + + const [emojiFired, emojiResolved] = textsFor( + 'https://hooks.slack.com/services/456', + ); + expect(emojiFired).toBe('🚨 Alert for "My Search" - 2 lines found'); + expect(emojiResolved).toMatch(/^✅ Alert for "My Search"/); + }); + // The scheduled alert task and the app search page both go through // `buildSearchChartConfig`, which prepends the Log source's // `tableFilterExpression` (when set) as a SQL filter. This regression diff --git a/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts b/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts index c3e09091bc..c9d6f5ecca 100644 --- a/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts +++ b/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts @@ -773,7 +773,6 @@ describe('buildAlertMessageTemplateTitle', () => { threshold, value: alertValue, }), - state: AlertState.ALERT, }); expect(result).toMatchSnapshot(); }, @@ -786,7 +785,6 @@ describe('buildAlertMessageTemplateTitle', () => { ({ thresholdType, threshold, okValue }) => { const result = buildAlertMessageTemplateTitle({ view: makeSearchView({ thresholdType, threshold, value: okValue }), - state: AlertState.OK, }); expect(result).toMatchSnapshot(); }, @@ -806,7 +804,6 @@ describe('buildAlertMessageTemplateTitle', () => { thresholdMax, value: alertValue, }), - state: AlertState.ALERT, }); expect(result).toMatchSnapshot(); }, @@ -819,7 +816,6 @@ describe('buildAlertMessageTemplateTitle', () => { threshold: 1.5, value: 10.123, }), - state: AlertState.ALERT, }); expect(result).toMatchSnapshot(); }); @@ -831,7 +827,6 @@ describe('buildAlertMessageTemplateTitle', () => { threshold: 5, value: 10.789, }), - state: AlertState.ALERT, }); expect(result).toMatchSnapshot(); }); @@ -848,7 +843,6 @@ describe('buildAlertMessageTemplateTitle', () => { thresholdMax, value: okValue, }), - state: AlertState.OK, }); expect(result).toMatchSnapshot(); }, @@ -864,10 +858,9 @@ describe('buildAlertMessageTemplateTitle', () => { const result = buildAlertMessageTemplateTitle({ view: { ...view, alert: { ...view.alert, name: 'Custom title' } }, - state: AlertState.ALERT, }); - expect(result).toBe('🚨 Custom title'); + expect(result).toBe('Custom title'); }); it('renders Handlebars against the view', () => { @@ -878,10 +871,9 @@ describe('buildAlertMessageTemplateTitle', () => { ...view, alert: { ...view.alert, name: '{{value}} over {{alert.threshold}}' }, }, - state: AlertState.ALERT, }); - expect(result).toBe('🚨 10 over 5'); + expect(result).toBe('10 over 5'); }); it('uses a malformed template verbatim instead of failing', () => { @@ -889,10 +881,9 @@ describe('buildAlertMessageTemplateTitle', () => { const result = buildAlertMessageTemplateTitle({ view: { ...view, alert: { ...view.alert, name: 'Errors {{spike' } }, - state: AlertState.ALERT, }); - expect(result).toBe('🚨 Errors {{spike'); + expect(result).toBe('Errors {{spike'); }); }); @@ -905,10 +896,9 @@ describe('buildAlertMessageTemplateTitle', () => { ...view, alert: { ...view.alert, displayName: 'Checkout errors' }, }, - state: AlertState.ALERT, }); - expect(result).toBe('🚨 Alert for "Checkout errors" - 10 lines found'); + expect(result).toBe('Alert for "Checkout errors" - 10 lines found'); }); it('names a tile alert', () => { @@ -919,7 +909,6 @@ describe('buildAlertMessageTemplateTitle', () => { ...view, alert: { ...view.alert, displayName: 'Error rate' }, }, - state: AlertState.ALERT, }); expect(result).toContain('Alert for "Error rate" -'); @@ -931,7 +920,6 @@ describe('buildAlertMessageTemplateTitle', () => { const result = buildAlertMessageTemplateTitle({ view: { ...view, alert: { ...view.alert, displayName: 'p99 latency' } }, - state: AlertState.ALERT, }); expect(result).toContain('Alert for "p99 latency"'); @@ -948,12 +936,9 @@ describe('buildAlertMessageTemplateTitle', () => { where: 'level:error', chartName: 'Inline Chart', }), - state: AlertState.ALERT, }); - expect(result).toBe( - '🚨 Alert for "Inline Chart" - 10 meets or exceeds 5', - ); + expect(result).toBe('Alert for "Inline Chart" - 10 meets or exceeds 5'); }); it('falls back when an inline chart config has no name', () => { @@ -967,10 +952,9 @@ describe('buildAlertMessageTemplateTitle', () => { chartConfig: { ...view.alert.chartConfig!, name: undefined }, }, }, - state: AlertState.ALERT, }); - expect(result).toBe('🚨 Alert for "Alert" - 10 meets or exceeds 5'); + expect(result).toBe('Alert for "Alert" - 10 meets or exceeds 5'); }); }); }); diff --git a/packages/api/src/tasks/checkAlerts/index.ts b/packages/api/src/tasks/checkAlerts/index.ts index 17a6b66c35..4ae9d167f6 100644 --- a/packages/api/src/tasks/checkAlerts/index.ts +++ b/packages/api/src/tasks/checkAlerts/index.ts @@ -553,10 +553,7 @@ const fireChannelEvent = async ({ clickhouseClient, metadata, state, - title: buildAlertMessageTemplateTitle({ - view: templateView, - state, - }), + title: buildAlertMessageTemplateTitle({ view: templateView }), template: alert.message, view: templateView, teamId, diff --git a/packages/api/src/tasks/checkAlerts/template.ts b/packages/api/src/tasks/checkAlerts/template.ts index 11335c5a1d..94e96d1dd3 100644 --- a/packages/api/src/tasks/checkAlerts/template.ts +++ b/packages/api/src/tasks/checkAlerts/template.ts @@ -265,6 +265,9 @@ export const isAlertResolved = (state?: AlertState): boolean => { return state === AlertState.OK; }; +const stateTitleEmoji = (state?: AlertState): string => + isAlertResolved(state) ? '✅ ' : '🚨 '; + /** * Formats the value to match the decimal precision of the threshold. * This ensures consistent display of numbers in alert messages. @@ -342,10 +345,8 @@ export const buildAlertMessageTemplateHdxLink = ( export const buildAlertMessageTemplateTitle = ({ view, - state, }: { view: AlertMessageTemplateDefaultView; - state?: AlertState; }) => { const { alert, dashboard, savedSearch, value } = view; const handlebars = createHandlebarsWithHelpers(); @@ -367,17 +368,14 @@ export const buildAlertMessageTemplateTitle = ({ dashboard, }); - // Add emoji prefix based on alert state - const emoji = isAlertResolved(state) ? '✅ ' : '🚨 '; - if (alert.source === AlertSource.SAVED_SEARCH) { if (savedSearch == null) { throw new Error(`Source is ${alert.source} but savedSearch is null`); } // TODO: using template engine to render the title - const baseTitle = - renderedTemplate ?? `Alert for "${displayName}" - ${value} lines found`; - return `${emoji}${baseTitle}`; + return ( + renderedTemplate ?? `Alert for "${displayName}" - ${value} lines found` + ); } else if (alert.source === AlertSource.TILE) { if (dashboard == null) { throw new Error(`Source is ${alert.source} but dashboard is null`); @@ -389,27 +387,27 @@ export const buildAlertMessageTemplateTitle = ({ ); } const formattedValue = formatValueToMatchThreshold(value, alert.threshold); - const baseTitle = + return ( renderedTemplate ?? `Alert for "${displayName}" - ${formattedValue} ${ doesExceedThreshold(alert, value) ? describeThresholdViolation(alert.thresholdType) : describeThresholdResolution(alert.thresholdType) - } ${describeThreshold(alert)}`; - return `${emoji}${baseTitle}`; + } ${describeThreshold(alert)}` + ); } else if (alert.source === AlertSource.INLINE) { const formattedValue = formatValueToMatchThreshold(value, alert.threshold); // Inline alerts have no saved search/tile to name them; the alert's `name` // doubles as the title template, so the default falls back to the resolved // display name (itself derived from the chart config's name). - const baseTitle = + return ( renderedTemplate ?? `Alert for "${displayName}" - ${formattedValue} ${ doesExceedThreshold(alert, value) ? describeThresholdViolation(alert.thresholdType) : describeThresholdResolution(alert.thresholdType) - } ${describeThreshold(alert)}`; - return `${emoji}${baseTitle}`; + } ${describeThreshold(alert)}` + ); } throw new Error(`Unsupported alert source: ${alert.source}`); @@ -739,7 +737,11 @@ export const renderAlertTemplate = async ({ populatedChannel: channel, message: { hdxLink: buildAlertMessageTemplateHdxLink(alertProvider, view), - title, + // The state emoji is added per channel; a webhook can opt out. + title: + channel.channel.titleEmoji === false + ? title + : `${stateTitleEmoji(state)}${title}`, body: renderedBody, state, startTime: view.startTime.getTime(), diff --git a/packages/api/src/utils/zod.ts b/packages/api/src/utils/zod.ts index 8ec394afdf..f4510fb74e 100644 --- a/packages/api/src/utils/zod.ts +++ b/packages/api/src/utils/zod.ts @@ -1276,6 +1276,7 @@ const baseWebhookSchema = { name: z.string(), url: z.string().optional(), description: z.string().optional(), + titleEmoji: z.boolean().optional(), updatedAt: z.string(), createdAt: z.string(), }; @@ -1379,6 +1380,7 @@ export const externalWebhookCreateSchema = z service: z.nativeEnum(WebhookService), url: z.string().url().max(MAX_WEBHOOK_URL_LENGTH), description: z.string().max(MAX_WEBHOOK_DESCRIPTION_LENGTH).optional(), + titleEmoji: z.boolean().optional(), queryParams: z .record(webhookQueryParamKeySchema, webhookQueryParamValueSchema) .refine(m => Object.keys(m).length <= MAX_WEBHOOK_QUERY_PARAMS, { diff --git a/packages/app/src/api.ts b/packages/app/src/api.ts index 34a49630c2..5271dcfdb2 100644 --- a/packages/app/src/api.ts +++ b/packages/app/src/api.ts @@ -628,6 +628,7 @@ const api = { url: string; name: string; description: string; + titleEmoji?: boolean; queryParams?: Record; headers?: Record; body?: string; @@ -638,6 +639,7 @@ const api = { url, name, description, + titleEmoji, queryParams, headers, body, @@ -649,6 +651,7 @@ const api = { service, url, description, + titleEmoji, queryParams: queryParams || {}, headers: headers || {}, body, @@ -670,6 +673,7 @@ const api = { url: string; name: string; description: string; + titleEmoji?: boolean; queryParams?: Record; headers?: Record; body?: string; @@ -681,6 +685,7 @@ const api = { url, name, description, + titleEmoji, queryParams, headers, body, @@ -692,6 +697,7 @@ const api = { service, url, description, + titleEmoji, queryParams: queryParams || {}, headers: headers || {}, body, diff --git a/packages/app/src/components/TeamSettings/WebhookForm.tsx b/packages/app/src/components/TeamSettings/WebhookForm.tsx index 6cf1720e5d..63d10c22f7 100644 --- a/packages/app/src/components/TeamSettings/WebhookForm.tsx +++ b/packages/app/src/components/TeamSettings/WebhookForm.tsx @@ -16,6 +16,7 @@ import { isValidSlackUrl } from '@hyperdx/common-utils/dist/validation'; import { Alert, Button, + Checkbox, Code, Group, Radio, @@ -90,6 +91,7 @@ type WebhookForm = { url: string; service: WebhookService; description?: string; + titleEmoji: boolean; body?: string; headers?: string; }; @@ -115,6 +117,7 @@ export function WebhookForm({ name: webhook?.name || '', url: webhook?.url || '', description: webhook?.description || '', + titleEmoji: webhook?.titleEmoji !== false, body: webhook?.body || '', headers: webhook?.headers ? JSON.stringify(webhook.headers, null, 2) : '', }, @@ -128,6 +131,7 @@ export function WebhookForm({ name: webhook.name, url: webhook.url, description: webhook.description, + titleEmoji: webhook.titleEmoji !== false, body: webhook.body, headers: webhook.headers ? JSON.stringify(webhook.headers, null, 2) @@ -215,7 +219,8 @@ export function WebhookForm({ }; const onSubmit: SubmitHandler = async values => { - const { service, name, url, description, body, headers } = values; + const { service, name, url, description, titleEmoji, body, headers } = + values; try { // Parse headers JSON if provided (API will validate the content) @@ -247,6 +252,7 @@ export function WebhookForm({ name, url, description: description || '', + titleEmoji, body: defaultBody, headers: parsedHeaders, }; @@ -380,6 +386,11 @@ export function WebhookForm({ error={form.formState.errors.description?.message} {...form.register('description')} /> + {service === WebhookService.Generic && [