Skip to content

refactor(alerts): channels are registered and validate their own destinations - #33973

Merged
manerow merged 11 commits into
feat/alerting-redesign-6-alert-jobsfrom
feat/alerting-redesign-7-channels
Oct 6, 2026
Merged

manerow merged 11 commits into
feat/alerting-redesign-6-alert-jobsfrom
feat/alerting-redesign-7-channels

Conversation

@manerow

@manerow manerow commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #33118.

What this pull request implements

  • Channels are registered. Each channel is one registered object, and can come from outside the service module.
  • Destinations are validated when new or changed, on every save path, including PATCH, by the rules of their channel.
  • A destination can name the channel that serves it in an optional channel field; without it, the channel of its type serves it. Naming a channel the server has not registered is refused.
  • A stored destination is sent as configured. A new or changed configuration is read strictly; a stored one ignores fields its type does not define.

What was wrong before

Adding a channel meant editing more than twenty places that switched on the destination type. Validation ran only on POST and PUT through the REST resource, so a PATCH could store a destination nothing can deliver to.

Design

  • Channel is registered under an id and made of four parts: a formatter, built once and shared by every caller, an AddressDirectory (where a user, a team or a destination is reached), ConfigRules and a Transport.
  • Channels holds every channel by id, filled from each ChannelProvider the service loader finds on the classpath. BuiltInChannels registers the channels OpenMetadata ships, each under its destination type, and is the only place that names a destination type. HttpWebhookTransport owns the HTTP clients: one per pair of timeouts, shared, bounded and closed at shutdown.
  • ChannelResolution picks the channel: the one the channel field names, otherwise the one registered for the type. A named channel that is not registered is never replaced by the type's. Every lookup of a destination's channel goes through it.
  • DestinationConfig is the one reader of a destination's configuration: strict when submitted (a 400 names the field), as saved when stored. Built-in channels read once and hand the typed configuration to their publishers.
  • UnservedDestination stands in for a destination whose channel is not registered, or whose stored configuration the channel cannot use. It never joins its channel's other destinations and costs the alert nothing else; an event only such destinations had counts as failed, with the reason it was not attempted.
  • AlertBacklogMigration (2.1.0) skips, once, the backlog of every enabled alert the previous release could not build.
  • DestinationValidation checks a new or changed destination with its channel's rules on every path that saves an alert, and leaves a stored one alone.

What users notice

  • Saving an alert rejects a new or changed destination its channel cannot deliver to, on every save path.
  • An alert that stopped sending because one destination could not be used as stored sends again from the upgrade on; changes from before the upgrade are not sent.

How it was tested

The alerting unit tests (73 classes, 532 tests), the alert integration tests (10 classes, 82 tests, including AlertBacklogMigrationIT) and the existing alert integration tests (565 tests) pass on MySQL and on PostgreSQL.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Playwright impact map auto-refreshed

This PR touched specs or UI source that changed the source→spec routing map. I regenerated .github/playwright/impact-map.generated.json and pushed the diff to this branch.

- source entries: 826 → 806
- 0 added, 20 removed, 37 changed spec-list

Removed source→spec entries:
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/activity.ts
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/alerts.ts
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/api.ts
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/collate.ts
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/db.ts
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/env.ts
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/form.ts
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/formAlerts.ts
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/ledger.ts
  openmetadata-ui/src/main/resources/ui/playwright/e2e/AlertsE2E/support/mail.ts
  … and 10 more

Entries whose spec list changed:
  openmetadata-ui/src/main/resources/ui/playwright/constant/sidebar.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/domain/Domain.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/entity/Entity.interface.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/entity/TableClass.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/user/UserClass.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/alert.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/common.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/domain.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/entity.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/notificationAlert.ts
  … and 27 more

What is this file? It is the auto-generated half of Playwright's PR planner. It routes "if source X changes, run specs Y" by walking spec imports and cross-referencing getByTestId strings. Hand-authored routing in impact-map.json always wins on conflict.

What if I want to regenerate locally instead? Run this before pushing your next change to skip the bot commit:

python3 .github/scripts/generate_playwright_impact_map.py
git add .github/playwright/impact-map.generated.json
git commit --amend --no-edit  # or a separate commit

@github-actions

Copy link
Copy Markdown
Contributor

✅ Generated Sources Auto-Updated

The generated TypeScript types (src/generated/) and dereferenced JSON
schemas (src/jsons/, public/jsons/) have been automatically updated
based on JSON schema changes in this PR.

@mohityadav766 mohityadav766 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.

lgtm for backend

Comment on lines +93 to +95
// Alerts the previous release stopped sending, because it could not build one of their
// destinations, send again from this release; they start from the upgrade, not their backlog.
skipBacklogOfAlertsThePreviousReleaseCouldNotSend(collectionDAO);

@gitar-bot gitar-bot Bot Oct 6, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Bug: Backlog skip isn't wrapped in runOnce, so a rerun drops events again

Nothing stops skipBacklogOfAlertsThePreviousReleaseCouldNotSend from running more than once. DataMigrationStep's javadoc says a v210 data migration runs again whenever its fingerprint changes, and any later change to a helper in utils.v210 changes it. A stored destination never changes, so on a rerun whyThePreviousReleaseCouldNotSend flags the same alerts again. By then the new release has been delivering those alerts, so AlertRecord.skipBacklog would silently drop every event they had not sent yet. The PR description says the backlog is skipped "once", but nothing here enforces it. Give the step a STEP_NAME and call it through runOnce, as the two steps just above it already do.

Run the backlog skip once per version (do the same in the MySQL Migration, and add public static final String STEP_NAME = "alert-backlog-skip"; to AlertBacklogMigration).:

runOnce(
    migrationDAO,
    getVersion(),
    AlertBacklogMigration.STEP_NAME,
    () -> skipBacklogOfAlertsThePreviousReleaseCouldNotSend(collectionDAO));

Was this helpful? React with 👍 / 👎

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — stack_invalidated (2026-10-06T10:43:07Z)

The entry left the queue before it was built, so no checks ran against it.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — stack_invalidated (2026-10-06T13:07:12Z)

The entry left the queue before it was built, so no checks ran against it.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-10-06T14:09:57Z)

The entry left the queue before it was built, so no checks ran against it.

@gitar-bot

gitar-bot Bot commented Oct 6, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 4 closed / 5 findings

🔴 High risk · Migration advances offsets for affected alerts, discarding retained event backlogs.

Refactors alert channels to be self-registering and validate their own destinations on every save path. The backlog skip during migration is not wrapped in runOnce, so a rerun would drop events that the new release has already sent; use STEP_NAME and call through runOnce as the adjacent migration steps do.

⚠️ Bug: Backlog skip isn't wrapped in runOnce, so a rerun drops events again

📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/postgres/v210/Migration.java:93-95 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v210/Migration.java:95-97 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/AlertBacklogMigration.java:41-55

Nothing stops skipBacklogOfAlertsThePreviousReleaseCouldNotSend from running more than once. DataMigrationStep's javadoc says a v210 data migration runs again whenever its fingerprint changes, and any later change to a helper in utils.v210 changes it. A stored destination never changes, so on a rerun whyThePreviousReleaseCouldNotSend flags the same alerts again. By then the new release has been delivering those alerts, so AlertRecord.skipBacklog would silently drop every event they had not sent yet. The PR description says the backlog is skipped "once", but nothing here enforces it. Give the step a STEP_NAME and call it through runOnce, as the two steps just above it already do.

Run the backlog skip once per version (do the same in the MySQL Migration, and add `public static final String STEP_NAME = "alert-backlog-skip";` to AlertBacklogMigration).
runOnce(
    migrationDAO,
    getVersion(),
    AlertBacklogMigration.STEP_NAME,
    () -> skipBacklogOfAlertsThePreviousReleaseCouldNotSend(collectionDAO));
✅ 4 closed
✅ Bug: Named channel ignored for rendering, recipients and secret encryption

📄 openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/channels/Channels.java:38-49 📄 openmetadata-service/src/main/java/org/openmetadata/service/notifications/HandlebarsNotificationMessageEngine.java:89 📄 openmetadata-service/src/main/java/org/openmetadata/service/notifications/recipients/context/Recipient.java:32-39 📄 openmetadata-service/src/main/java/org/openmetadata/service/notifications/recipients/RecipientResolver.java:180 📄 openmetadata-service/src/main/java/org/openmetadata/service/notifications/recipients/strategy/impl/ExternalRecipientResolver.java:55 📄 openmetadata-service/src/main/java/org/openmetadata/service/fernet/Fernet.java:140-141 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/NotificationTemplateRepository.java:453
AlertFactory, DestinationValidation and the consumer grouping pick the channel with ChannelResolution.of, which uses the channel field when it is set. Rendering (Channels.required in HandlebarsNotificationMessageEngine.rendererOf), user/team recipients (Recipient.fromUser/fromTeam), external receivers (ExternalRecipientResolver, RecipientResolver), template test sends and secret encryption (Fernet via Channels.ofTypeOf) all look the channel up by type instead. So a destination such as {type: Slack, channel: "acme.slack"} is validated and published by acme.slack, but its message is rendered and its recipients chosen by the built-in Slack channel, and its secrets are encrypted by Slack's rules. This contradicts the stated rule that a named channel is never replaced by the type's channel. Resolve the channel with ChannelResolution everywhere, for example by making Channels.required go through ChannelResolution.of(destination).

✅ Bug: Renderer cache is a plain HashMap mutated concurrently

📄 openmetadata-service/src/main/java/org/openmetadata/service/notifications/HandlebarsNotificationMessageEngine.java:45 📄 openmetadata-service/src/main/java/org/openmetadata/service/notifications/HandlebarsNotificationMessageEngine.java:88-99 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/NotificationTemplateRepository.java:321 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/NotificationTemplateRepository.java:451
channelRenderers used to be filled once in the constructor and only read afterwards. It is now a HashMap filled lazily through computeIfAbsent. NotificationTemplateRepository keeps a single HandlebarsNotificationMessageEngine (line 87) and uses it for concurrent REST render and send requests (lines 339, 451). Two first calls for channels that are not yet cached can then modify the HashMap at the same time. That can lose entries, corrupt the table, or throw ConcurrentModificationException. Use a ConcurrentHashMap.

✅ Bug: Channel of only unserved destinations counts as a successful delivery

📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/changeEvent/AbstractEventConsumer.java:184-192
servedAmong drops UnservedDestinations, and a channel whose destinations are all unserved is skipped. But successCount is still destinationsByChannel.size() - failures.size(), so that skipped channel counts as a success. Take an alert whose only destination names an unregistered channel, or has a config its channel can't build. Nothing is sent, yet delivered is true: the event is recorded as successfully sent and counts toward the success metrics. The same happens when an unserved channel sits next to a channel that failed. The result says the event was delivered when no destination got it. Fix: count only the channels that were actually attempted.

✅ Quality: Order loop in test never controls the order that grouping sees

📄 openmetadata-service/src/test/java/org/openmetadata/service/apps/bundles/changeEvent/AbstractEventConsumerTest.java:706-720 📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/changeEvent/AbstractEventConsumer.java:261-269
aDestinationWithNoPublisherCostsItsChannelNothing runs twice so the unserved destination is first in one run and second in the other, and it sets that order through destinationMap insertion. But groupDestinationsByChannel streams destinationIds, which is Set.of(unusableId, usableId). Set.of has randomized iteration order, so each group's list order comes from the Set, not the map. Both runs therefore test the same random order, and the case where the unserved destination comes first (the regression servedAmong guards against) is only covered by chance. To fix this, pass an ordered set such as new LinkedHashSet<>(unusableFirst ? List.of(unusableId, usableId) : List.of(usableId, unusableId)) as the event's destination ids.

🤖 Prompt for agents
Code Review: Refactors alert channels to be self-registering and validate their own destinations on every save path. The backlog skip during migration is not wrapped in `runOnce`, so a rerun would drop events that the new release has already sent; use `STEP_NAME` and call through `runOnce` as the adjacent migration steps do.

1. ⚠️ Bug: Backlog skip isn't wrapped in runOnce, so a rerun drops events again
   Files: openmetadata-service/src/main/java/org/openmetadata/service/migration/postgres/v210/Migration.java:93-95, openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v210/Migration.java:95-97, openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/AlertBacklogMigration.java:41-55

   Nothing stops `skipBacklogOfAlertsThePreviousReleaseCouldNotSend` from running more than once. `DataMigrationStep`'s javadoc says a v210 data migration runs again whenever its fingerprint changes, and any later change to a helper in `utils.v210` changes it. A stored destination never changes, so on a rerun `whyThePreviousReleaseCouldNotSend` flags the same alerts again. By then the new release has been delivering those alerts, so `AlertRecord.skipBacklog` would silently drop every event they had not sent yet. The PR description says the backlog is skipped "once", but nothing here enforces it. Give the step a `STEP_NAME` and call it through `runOnce`, as the two steps just above it already do.

   Fix (Run the backlog skip once per version (do the same in the MySQL Migration, and add `public static final String STEP_NAME = "alert-backlog-skip";` to AlertBacklogMigration).):
   runOnce(
       migrationDAO,
       getVersion(),
       AlertBacklogMigration.STEP_NAME,
       () -> skipBacklogOfAlertsThePreviousReleaseCouldNotSend(collectionDAO));

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Destination dispatchers are not pluggable: AlertFactory's closed switch forces per-feature notification workarounds

3 participants