Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(alerts): tolerate a null channels field when editing an existing alert rule (#12510)

Ashwin Bhatkal62d382b3ccbf
diff --git a/frontend/src/container/CreateAlertV2/Footer/__tests__/utils.test.ts b/frontend/src/container/CreateAlertV2/Footer/__tests__/utils.test.ts
index 1363aa4df0..5f5b715250 100644
--- a/frontend/src/container/CreateAlertV2/Footer/__tests__/utils.test.ts
+++ b/frontend/src/container/CreateAlertV2/Footer/__tests__/utils.test.ts
@@ -130,6 +130,28 @@ describe('Footer utils', () => {
};
expect(validateCreateAlertState(currentArgs)).toBeNull();
});
+
+ it('when threshold channels are null', () => {
+ const currentArgs: BuildCreateAlertRulePayloadArgs = {
+ ...args,
+ basicAlertState: {
+ ...args.basicAlertState,
+ name: 'test name',
+ },
+ thresholdState: {
+ ...args.thresholdState,
+ thresholds: [
+ {
+ ...args.thresholdState.thresholds[0],
+ channels: null as unknown as string[],
+ },
+ ],
+ },
+ };
+ expect(validateCreateAlertState(currentArgs)).toBe(
+ 'Please select at least one channel for each threshold or enable routing policies',
+ );
+ });
});
describe('getNotificationSettingsProps', () => {
diff --git a/frontend/src/container/CreateAlertV2/Footer/utils.tsx b/frontend/src/container/CreateAlertV2/Footer/utils.tsx
index 9e92e90e85..09038efbf1 100644
--- a/frontend/src/container/CreateAlertV2/Footer/utils.tsx
+++ b/frontend/src/container/CreateAlertV2/Footer/utils.tsx
@@ -44,7 +44,8 @@ export function validateCreateAlertState(
if (!threshold.label) {
return 'Please enter a label for each threshold';
}
- if (!notificationSettings.routingPolicies && !threshold.channels.length) {
+ // this runs during render, so a throw here takes down the whole page
+ if (!notificationSettings.routingPolicies && !threshold.channels?.length) {
return 'Please select at least one channel for each threshold or enable routing policies';
}
}
diff --git a/frontend/src/container/CreateAlertV2/__tests__/utils.test.tsx b/frontend/src/container/CreateAlertV2/__tests__/utils.test.tsx
index de81a1e43e..15a9a4dc17 100644
--- a/frontend/src/container/CreateAlertV2/__tests__/utils.test.tsx
+++ b/frontend/src/container/CreateAlertV2/__tests__/utils.test.tsx
@@ -316,6 +316,34 @@ describe('CreateAlertV2 utils', () => {
});
});
+ describe('getThresholdStateFromAlertDef null channels', () => {
+ it('falls back to an empty array so downstream consumers never see null', () => {
+ const def: PostableAlertRuleV2 = {
+ ...defaultPostableAlertRuleV2,
+ condition: {
+ ...defaultPostableAlertRuleV2.condition,
+ thresholds: {
+ kind: 'basic',
+ spec: [
+ {
+ name: 'critical',
+ target: 1,
+ targetUnit: UniversalYAxisUnit.MINUTES,
+ channels: null as unknown as string[],
+ matchType: AlertThresholdMatchType.AT_LEAST_ONCE,
+ op: AlertThresholdOperator.IS_ABOVE,
+ },
+ ],
+ },
+ },
+ };
+
+ expect(
+ getThresholdStateFromAlertDef(def).thresholds[0].channels,
+ ).toStrictEqual([]);
+ });
+ });
+
describe('normalizeOperator', () => {
it.each([
['1', AlertThresholdOperator.IS_ABOVE],
diff --git a/frontend/src/container/CreateAlertV2/utils.tsx b/frontend/src/container/CreateAlertV2/utils.tsx
index a558fc5654..3101403830 100644
--- a/frontend/src/container/CreateAlertV2/utils.tsx
+++ b/frontend/src/container/CreateAlertV2/utils.tsx
@@ -258,7 +258,9 @@ export function getThresholdStateFromAlertDef(
recoveryThresholdValue: null,
unit: threshold.targetUnit,
color: getColorForThreshold(threshold.name),
- channels: threshold.channels,
+ // rules created outside the UI can come back with a null channels
+ // field; drop the guard once the API enforces the schema
+ channels: threshold.channels ?? [],
})) || [],
selectedQuery: alertDef.condition.selectedQueryName || '',
operator: