Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(alerts): guard alert check preview against missing checks (#73310)

posthog[bot]1438ae308496
diff --git a/products/alerts/frontend/logic/trendsAlertPreview.test.ts b/products/alerts/frontend/logic/trendsAlertPreview.test.ts
index 96dd7f658e69..d4b3d384decf 100644
--- a/products/alerts/frontend/logic/trendsAlertPreview.test.ts
+++ b/products/alerts/frontend/logic/trendsAlertPreview.test.ts
@@ -17,6 +17,16 @@ describe('deriveTrendsAlertPreviewSeries', () => {
})
})
+ it('returns an empty series when checks is undefined', () => {
+ expect(
+ deriveAlertCheckPreviewSeries(undefined, AlertConditionType.ABSOLUTE_VALUE, InsightThresholdType.ABSOLUTE)
+ ).toEqual({
+ values: [],
+ labels: [],
+ relative: false,
+ })
+ })
+
it('builds a chronological percentage preview from completed alert checks', () => {
expect(
deriveAlertCheckPreviewSeries(
diff --git a/products/alerts/frontend/logic/trendsAlertPreview.ts b/products/alerts/frontend/logic/trendsAlertPreview.ts
index b1860918fd23..efb4ce72fe08 100644
--- a/products/alerts/frontend/logic/trendsAlertPreview.ts
+++ b/products/alerts/frontend/logic/trendsAlertPreview.ts
@@ -12,13 +12,13 @@ interface AlertCheckPreviewInput {
}
export function deriveAlertCheckPreviewSeries(
- checks: AlertCheckPreviewInput[],
+ checks: AlertCheckPreviewInput[] | undefined,
conditionType: AlertConditionType,
thresholdType: InsightThresholdType
): TrendsAlertPreviewSeries {
const percentageChange =
conditionType !== AlertConditionType.ABSOLUTE_VALUE && thresholdType === InsightThresholdType.PERCENTAGE
- const points = checks
+ const points = (checks ?? [])
.filter(
(check): check is AlertCheckPreviewInput & { calculated_value: number } =>
check.calculated_value != null && Number.isFinite(check.calculated_value)
diff --git a/products/alerts/frontend/types.ts b/products/alerts/frontend/types.ts
index fc40d4c3a69a..15c636264ee0 100644
--- a/products/alerts/frontend/types.ts
+++ b/products/alerts/frontend/types.ts
@@ -154,7 +154,7 @@ export interface AlertType extends AlertTypeBase {
last_checked_at: string
next_check_at?: string | null
checks_total?: number
- checks: AlertCheck[]
+ checks?: AlertCheck[]
calculation_interval: AlertCalculationInterval
snoozed_until?: string
last_value?: number
diff --git a/products/alerts/frontend/views/EditAlertModalV2.tsx b/products/alerts/frontend/views/EditAlertModalV2.tsx
index b1991126e568..7a99d288efe4 100644
--- a/products/alerts/frontend/views/EditAlertModalV2.tsx
+++ b/products/alerts/frontend/views/EditAlertModalV2.tsx
@@ -246,7 +246,7 @@ export function EditAlertModalV2({
return undefined
}
const preview = deriveAlertCheckPreviewSeries(
- alert.checks,
+ alert.checks ?? [],
alertForm.condition?.type ?? AlertConditionType.ABSOLUTE_VALUE,
alertForm.threshold?.configuration?.type ?? InsightThresholdType.ABSOLUTE
)