Skip to content

refactor(alertmanager): move API handlers to signozapiserver#10941

Merged
therealpandey merged 10 commits into
mainfrom
platform-pod/issues/2087
Apr 15, 2026
Merged

refactor(alertmanager): move API handlers to signozapiserver#10941
therealpandey merged 10 commits into
mainfrom
platform-pod/issues/2087

Conversation

@therealpandey

@therealpandey therealpandey commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

  • Extract Handler interface in pkg/alertmanager/handler.go and move implementation to pkg/alertmanager/signozalertmanager/handler.go
  • Register all alertmanager routes (channels, route policies, alerts) in signozapiserver via handler.New() with OpenAPIDef
  • Remove AlertmanagerAPI injection from http_handler.go and server.go
  • Add required/nullable/Enum() tags to alertmanager types for accurate OpenAPI schemas
  • Add /api/v1/channels/test endpoint, mark /api/v1/testChannel as deprecated
  • Regenerate OpenAPI spec and frontend API clients

Why?

  • Deprecate legacy API docs: moves alertmanager routes out of http_handler.go into the typed signozapiserver with full OpenAPIDef, bringing us closer to fully deprecating https://signoz.io/api-reference/#/ — only rules and dashboards remain on the legacy path
  • Unblock Terraform provider: with typed OpenAPI definitions and proper schemas (required, nullable, Enum()), the Terraform provider can start generating resources for channels and route policies from the spec
  • Unblock audit logs epic: routes registered via handler.New() support WithAuditDef() injection — this is a prerequisite for instrumenting notification channel and route policy mutations with audit events (SigNoz/platform-pod#1938)

Test plan

  • go build ./cmd/... ./pkg/... ./ee/... passes
  • All alertmanager routes respond correctly (channels CRUD, route policies CRUD, alerts GET, channel test)
  • Auth levels preserved (ViewAccess/EditAccess/AdminAccess per route)
  • /api/v1/channels/test works, /api/v1/testChannel still works (deprecated)
  • OpenAPI spec includes alertmanager route definitions with accurate schemas

closes SigNoz/platform-pod#2087

Extract Handler interface in pkg/alertmanager/handler.go and move
the implementation from api.go to signozalertmanager/handler.go.

Register all alertmanager routes (channels, route policies, alerts)
in signozapiserver via handler.New() with OpenAPIDef. Remove
AlertmanagerAPI injection from http_handler.go.

This enables future AuditDef instrumentation on these routes.
Comment thread pkg/signoz/handler.go Outdated
Comment thread pkg/apiserver/signozapiserver/alertmanager.go Outdated
Comment thread pkg/apiserver/signozapiserver/alertmanager.go Outdated
Comment thread pkg/apiserver/signozapiserver/alertmanager.go Outdated
- Rename `am` to `alertmanagerService` in NewHandlers
- Add /api/v1/channels/test as the canonical test endpoint
- Mark /api/v1/testChannel as deprecated
- Regenerate OpenAPI spec
Comment thread docs/api/openapi.yml Outdated
@therealpandey therealpandey requested a review from a team as a code owner April 15, 2026 12:44
- PostableRoutePolicy: mark expression, name, channels as required
- GettableRoutePolicy: change CreatedAt/UpdatedAt from pointer to value
- Channel: mark name, type, data, orgId as required
- ExpressionKind: add Enum() for rule/policy values
- Regenerate OpenAPI spec and frontend clients
@therealpandey therealpandey added the safe-to-integrate Run integration tests label Apr 15, 2026
CreateChannel, UpdateChannelByID, TestChannel, and TestChannelDeprecated
all read req.Body as a Receiver config. The OpenAPIDef must declare
the request type so the generated SDK includes the body parameter.
@therealpandey therealpandey added safe-to-integrate Run integration tests and removed safe-to-integrate Run integration tests labels Apr 15, 2026

@srikanthccv srikanthccv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, one role change. Shouldn't be a problem for backwards compatibility because channels was never accessible frontend. If someone had used API, then it would have been admin, under the assumption that create from API would also want to edit/delete so If they didn't run into that problem, they must have been an admin.

Comment thread pkg/apiserver/signozapiserver/alertmanager.go Outdated
Comment thread pkg/apiserver/signozapiserver/alertmanager.go
Comment thread frontend/src/api/generated/services/sigNoz.schemas.ts
Aligns CreateChannel endpoint with the rest of the channel mutation
endpoints (update/delete) which all require admin access. This is
consistent with the frontend where notifications are not accessible
to editors.
@therealpandey therealpandey added safe-to-integrate Run integration tests and removed safe-to-integrate Run integration tests labels Apr 15, 2026
@therealpandey therealpandey added this pull request to the merge queue Apr 15, 2026
Merged via the queue into main with commit b3da6fb Apr 15, 2026
150 of 153 checks passed
@therealpandey therealpandey deleted the platform-pod/issues/2087 branch April 15, 2026 18:03
AndersonFirmino added a commit to AndersonFirmino/signoz that referenced this pull request Apr 18, 2026
The Edit Notification Channel page rendered Discord channels as Slack and
the Test button sent slack_configs with an empty api_url instead of
discord_configs with the webhook_url. Discord was missing end-to-end from
the UI even though the backend already supports discord_configs.

Bug 1 — Discord shown as Slack on Edit
  prepChannelConfig in pages/ChannelsEdit only matched slack/msteams/pager/
  opsgenie/email/webhook. discord_configs fell through to the default branch
  which returned ChannelType.Slack, so the type selector (disabled in edit
  mode) was stuck on Slack and the Slack settings form rendered.

Bug 2 — Test sent slack_configs with empty api_url
  EditAlertChannels.performChannelTest had no Discord case. Combined with
  Bug 1 the test fell through to testSlackApi, which posted slack_configs
  with api_url="" (Discord payload uses webhook_url, not api_url) and the
  alertmanager rejected it with "unsupported scheme".

Changes
  * Extract prepChannelConfig as a pure, exported function for direct
    testing (was a closure-bound function inside the component).
  * Detect discord_configs first in prepChannelConfig and return
    ChannelType.Discord.
  * Add ChannelType.Discord and DiscordChannel interface to the channel
    config types.
  * Add api/channels/{create,edit,test}Discord.ts and matching request type
    files. Test endpoint stays on /testChannel (the new
    /api/v1/channels/test wired by PR SigNoz#10941 lands in v0.120).
  * Add FormAlertChannels/Settings/Discord.tsx with webhook_url, title and
    message fields, register it in renderSettings, and add the Discord
    option to the type dropdown.
  * Wire prepareDiscordRequest, onDiscordEditHandler, onDiscordHandler and
    the Discord case in performChannelTest in both EditAlertChannels and
    CreateAlertChannels.

Tests
  * frontend/src/pages/ChannelsEdit/__tests__/prepChannelConfig.test.ts —
    6 cases covering Discord detection, Slack/Webhook/MsTeams precedence,
    legacy Slack fallback for unknown payloads, and discord-over-slack
    determinism when both keys are present.
  * frontend/src/api/channels/__tests__/testDiscord.test.ts — 2 cases
    asserting the payload shape (discord_configs with webhook_url, no
    slack_configs, no api_url leak).
  * Verified red without the fix (2 failing assertions) and green with the
    fix (8/8 passing). Existing 122 channel tests still pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe-to-integrate Run integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants