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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix(channels): reset previous type's template values on type switch (#13374)
ashu891274d35ebafa35
diff --git a/frontend/public/locales/en-GB/channels.json b/frontend/public/locales/en-GB/channels.jsonindex 317c11c481..0dbda18cdc 100644--- a/frontend/public/locales/en-GB/channels.json+++ b/frontend/public/locales/en-GB/channels.json@@ -103,7 +103,7 @@"placeholder_slack_description": "Description","placeholder_pager_description": "Description","help_pager_client": "Shows up as event source in Pagerduty",- "help_pager_client_url": "Shows up as event source link in Pagerduty",+ "help_pager_client_url": "Shows up as event source link in Pagerduty. Leave empty to link to this SigNoz instance","help_pager_class": "The class/type of the event","help_pager_details": "Specify a key-value format (must be a valid json)","help_pager_group": "A cluster or grouping of sources",diff --git a/frontend/public/locales/en/channels.json b/frontend/public/locales/en/channels.jsonindex 204176bd78..1a6812c41a 100644--- a/frontend/public/locales/en/channels.json+++ b/frontend/public/locales/en/channels.json@@ -169,7 +169,7 @@"placeholder_opsgenie_message": "Message","placeholder_opsgenie_priority": "Priority","help_pager_client": "Shows up as event source in Pagerduty",- "help_pager_client_url": "Shows up as event source link in Pagerduty",+ "help_pager_client_url": "Shows up as event source link in Pagerduty. Leave empty to link to this SigNoz instance","help_pager_class": "The class/type of the event","help_pager_details": "Specify a key-value format (must be a valid json)","help_pager_group": "A cluster or grouping of sources",diff --git a/frontend/src/container/CreateAlertChannels/defaults.ts b/frontend/src/container/CreateAlertChannels/defaults.tsindex 0a9e76b242..34f157adcb 100644--- a/frontend/src/container/CreateAlertChannels/defaults.ts+++ b/frontend/src/container/CreateAlertChannels/defaults.ts@@ -85,7 +85,6 @@ export const PagerInitialConfig: Partial<AlertmanagertypesChannelPagerdutyConfig{{- end }}`,severity: '{{ (index .Alerts 0).Labels.severity }}',client: 'SigNoz Alert Manager',- clientUrl: 'https://enter-signoz-host-n-port-here/alerts',details: {firing: `{{ .Alerts.Firing | toJson }}`,resolved: `{{ .Alerts.Resolved | toJson }}`,diff --git a/frontend/src/pages/AlertList/NotificationChannels/__tests__/ChannelFormSave.test.tsx b/frontend/src/pages/AlertList/NotificationChannels/__tests__/ChannelFormSave.test.tsxindex f3bab1e391..b7d3d781ad 100644--- a/frontend/src/pages/AlertList/NotificationChannels/__tests__/ChannelFormSave.test.tsx+++ b/frontend/src/pages/AlertList/NotificationChannels/__tests__/ChannelFormSave.test.tsx@@ -486,4 +486,66 @@ describe('ChannelForm save', () => {},TEST_TIMEOUT,);++ it(+ "drops the previous type's templates when switching type",+ async () => {+ let body: Record<string, unknown> | undefined;+ server.use(+ rest.post(+ 'http://localhost/api/v2/notification_channels',+ async (req, res, ctx) => {+ body = await req.json();+ return res(ctx.status(201), ctx.json({ status: 'success', data: {} }));+ },+ ),+ );++ render(<ChannelForm onDone={jest.fn()} />);++ const user = userEvent.setup({ delay: null, pointerEventsCheck: 0 });+ await user.click(await screen.findByTestId('channel-type-select', {}, FIND));+ await user.click(await screen.findByRole('option', { name: /^Telegram$/ }));++ expect(screen.getByTestId('telegram-title-textarea')).toHaveValue('');++ await user.type(+ screen.getByTestId('channel-name-textbox'),+ 'telegram alerts',+ );+ await user.type(screen.getByTestId('telegram-bot-token-textbox'), '123:abc');+ await user.type(screen.getByTestId('telegram-chat-id-textbox'), '-100123');++ const save = screen.getByTestId('save-channel-button');+ await waitFor(+ () => expect(save).toHaveAttribute('aria-disabled', 'false'),+ FIND,+ );+ await user.click(save);++ await waitFor(() => expect(body).toBeDefined(), FIND);+ expect(+ (body as { config: { spec: Record<string, unknown> } }).config.spec,+ ).toStrictEqual({+ botToken: '123:abc',+ chatId: -100123,+ sendResolved: true,+ });+ },+ TEST_TIMEOUT,+ );++ it(+ 'leaves the pagerduty client url empty so the backend links to this instance',+ async () => {+ render(<ChannelForm onDone={jest.fn()} />);++ const user = userEvent.setup({ delay: null, pointerEventsCheck: 0 });+ await user.click(await screen.findByTestId('channel-type-select', {}, FIND));+ await user.click(await screen.findByRole('option', { name: /^Pagerduty$/ }));++ expect(screen.getByTestId('pager-client-url-textarea')).toHaveValue('');+ },+ TEST_TIMEOUT,+ );});diff --git a/frontend/src/pages/AlertList/NotificationChannels/components/ChannelForm/useChannelFormState.ts b/frontend/src/pages/AlertList/NotificationChannels/components/ChannelForm/useChannelFormState.tsindex 4370e7acbd..9d6e45fb7a 100644--- a/frontend/src/pages/AlertList/NotificationChannels/components/ChannelForm/useChannelFormState.ts+++ b/frontend/src/pages/AlertList/NotificationChannels/components/ChannelForm/useChannelFormState.ts@@ -86,9 +86,25 @@ export function useChannelFormState({setTypeState(nextType);+ const nextDefaults = ChannelInitialConfig[nextType];++ // the previous type's templates would otherwise be sent as the new+ // type's values; sendResolved is a general setting and is kept.+ // '' not undefined: a field mounting on undefined falls back to the+ // draft's defaults, and blanks are dropped on save anyway+ Object.keys(ChannelInitialConfig[type])+ .filter((field) => field !== 'sendResolved' && !(field in nextDefaults))+ .forEach((field) => {+ form.setValue(+ field as keyof ChannelFormValues,+ '' as ChannelFormValues[keyof ChannelFormValues],+ { shouldDirty: true },+ );+ });+// shouldDirty, because the type lives outside the form: without it// picking a different type leaves the form pristine and unsavable.- Object.entries(ChannelInitialConfig[nextType]).forEach(([field, value]) => {+ Object.entries(nextDefaults).forEach(([field, value]) => {form.setValue(field as keyof ChannelFormValues,value as ChannelFormValues[keyof ChannelFormValues],