Skip to content

refactor(alerts): give alerting code one home - #35032

Merged
manerow merged 18 commits into
mainfrom
refactor/alerting-regroup
Oct 15, 2026
Merged

manerow merged 18 commits into
mainfrom
refactor/alerting-regroup

Conversation

@manerow

@manerow manerow commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What this pull request does

Alerting code sat in about 40 packages under 11 roots, and about 20 package pairs imported each other. This pull request gives it two homes and lets the build hold the boundaries:

  • events.consumer is the runtime every change-event consumer runs on: the tick, the consumer kinds, scheduling and the ledger. It knows nothing of alerting.
  • alerting holds alerts and notifications in layers. Matching is at the bottom, then definition, audience and content, the channel SPI, one package per channel, delivery, and the alert's consumer on top.

How to review it

Commit by commit. The first seven commits delete dead code and cut the dependencies that kept the code tangled; each compiles on its own. The eighth commit is the move itself, done by the OpenRewrite recipe committed in .github/rewrite/alerting-packages.yml. It is rename-only apart from two path strings in guard tests. The commits after it ship the consumer id migration in 2.1.0 and keep its tests passing, merge main, and add the schema descriptions and the decision record.

Changes in behaviour (release note)

  • An alert names its consumer by a registered id (alert for alerts) instead of a Java class name. The 2.1.0 migration converts stored alerts and their scheduled jobs. A class name a consumer was stored under is still accepted and saved as its id; an unknown consumer is refused with a 400, as before.
  • A consumer added by a plugin must be registered by a ConsumerProvider listed in META-INF/services, with the class name its alerts stored as an alias. Until it is, the migration leaves those alerts as they are, their ticks send nothing (nothing is lost), and saving one is refused with a 400.
  • Logger categories under org.openmetadata.service.events.* and apps.bundles.changeEvent moved to events.consumer and alerting.
  • The classes generated from typedEvent.json and handlebarsHelpers.json moved Java package; the JSON is unchanged.

Boundaries

AlertingArchitectureTest fails the build when:

  • a layer uses one above it;
  • alerting packages import each other in a circle;
  • one channel uses another (only the built-in list may, and the chat channels may use the webhook channel's HTTP sending);
  • the consumer runtime uses alerting;
  • core code reaches alerting other than through the channel SPI or a short list of adapters.

How it was tested

  • The rename-only check compared 284 Java files (196 renamed) with package, import and blank lines removed. Only the two listed path strings differ.
  • No file under a released migration folder changed.
  • The 1,214 alerting unit tests, and all 24 alert integration test classes (686 tests) on MySQL and PostgreSQL.
  • A fix made after the move was cherry-picked onto the old layout with git cherry-pick -X find-renames. It landed in the old paths, built and passed.

Fixes #35030

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 9, 2026
@manerow
manerow marked this pull request as ready for review October 9, 2026 14:08
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

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

@manerow
manerow force-pushed the refactor/alerting-regroup branch from c75dff8 to f557c6f Compare October 10, 2026 09:16
@manerow
manerow requested a review from a team as a code owner October 10, 2026 09:16
@manerow
manerow requested review from akashverma0786 and removed request for a team October 10, 2026 09:16
@manerow
manerow changed the base branch from refactor/alerting-p0-frozen-v210-reads to main October 10, 2026 09:16
@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: 922 → 923
- 1 added, 0 removed, 1 changed spec-list

New source→spec entries:
  openmetadata-ui/src/main/resources/ui/src/components/DataQuality/AddDataQualityTest/components/TestCaseFormDrawer.tsx

Entries whose spec list changed:
  openmetadata-ui/src/main/resources/ui/src/components/Explore/EntitySummaryPanel/EntitySummaryPanel.component.tsx

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

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 77%
77.34% (124429/160865) 63.62% (77517/121829) 65.03% (25948/39900)

A consumer class can move, be renamed or stop being a Quartz job without a data migration, and
the API never loads a class a client names. The field keeps the name `className` so the wire shape
does not change; renaming it is a wire change for a later release. `AbstractEventConsumer` keeps a
deprecated `execute` that runs `ConsumerJob` until 2.3, so a job that a server of a release before

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think the deprecated execute helps the default consumer here. It only kicks in if the old class still loads under its old name, but AlertPublisher moved out of apps.bundles.changeEvent, and in AlertConsumers that name is only an alias string. So a job that a 2.0 pod stores under org.openmetadata.service.apps.bundles.changeEvent.AlertPublisher won't load on a 2.1 pod either, and Quartz puts the trigger in ERROR. What actually rescues it is AlertJobView.job() treating the unreadable job as missing so the reconciler re-stores it.

Also, "at most one reconcile round" is per incident. With the helm chart, migrations run in the new pod's init container while the old pod is still up, and a 2.0 pod has no reconciler. Every time it grabs a ConsumerJob trigger it knocks it back into ERROR, so the real bound is however long the rollout takes plus up to one 10 min round. The ledger means nothing gets lost, only delayed, so I'm fine with the behaviour. I'd just word the ADR that way so nobody reads it as a hard bound.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. The deprecated execute only helps a consumer whose class kept its name, which today means Collate's reverse metadata and credit usage consumers. The default consumer's class moved, so a job a 2.0 pod stores under the old AlertPublisher name never loads on 2.1, and it's the reconciler treating that job as missing that brings it back. The bound is per incident too: the old pod keeps knocking ConsumerJob triggers into error until it stops, so it's the rollout plus one 10 minute round. The ADR now says exactly that in f22e351.

/** The consumer of an alert that names none: it sends the alert's notifications. */
public static final String DEFAULT = "alert";

private static final Map<String, ConsumerProvider> REGISTERED = load();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nothing touches Consumers during startup (AlertConsumers.ID is a compile-time constant, so it gets inlined), so this only loads the first time a tick, a create/PUT or a diagnostics call reaches it. If two providers answer to one name, or a services entry is broken (say a plugin jar that ships a duplicate id), the server comes up fine. The first touch then throws ExceptionInInitializerError, and every tick and request after that gets NoClassDefFoundError until restart, including the default alert consumer. That's not the "stop the server" behaviour the ADR describes.

Could we force the load in EventSubscriptionResource.initialize, next to EventsSubscriptionRegistry.initialize(...) and outside the try, the same way the catalog is handled there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, confirmed: nothing loads it before the first tick, save or diagnostics call, and a duplicate id would then break every alert until a restart. EventSubscriptionResource.initialize now loads the consumers right after the catalog, outside the try, so a duplicate fails once at startup with the name in the log (f22e351). While there I fixed the wording: neither this nor the catalog stops the server, because CollectionRegistry catches what initialize throws and logs it. So the server comes up with alerting off, and the ADR and the comment above that line now say so.

@@ -0,0 +1,2 @@
org.openmetadata.service.alerting.channel.builtin.BuiltInChannels

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could the release note mention the SPI renames as well? Anyone shipping their own channel or attachment provider has to rename their services file (ChannelProvider and AttachmentProvider both changed package), and if they only fix the imports it still compiles, but ServiceLoader quietly finds nothing and their channels just disappear. Same for a custom consumer: it now needs a ConsumerProvider with its old class name as an alias, otherwise its stored alerts get a 400 on save and the migration leaves them alone. One line in the release note would save someone a confusing afternoon.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The consumer part is real, so the release note now has a line for it: a plugin consumer needs a ConsumerProvider that lists its old class name as an alias, or its alerts are left unmigrated, their ticks send nothing and saves get a 400. The channel and attachment ones don't need a note. ChannelProvider and AttachmentProvider first ship in 2.1.0 with this PR (they're not on 2.0.5), so no released plugin has a services file under the old names. The only thing built against them in between is Collate, and PR #7259 updates it.

@gitar-bot

gitar-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🔴 High risk · The 2.1.0 migration rewrites stored alert consumer IDs and scheduled jobs; incorrect mappings could prevent alerts from running.

Refactors alerting code into two homes: events.consumer for the change-event runtime and alerting for layered alert and notification logic, with build-enforced package boundaries. Alerts now name consumers by registered id, migrated in 2.1.0. Resolved an unintended literal undefined CSS class in ServiceDocPanel and recorded the consumer id contract in the decision docs. No open issues remain.

✅ 2 closed
✅ Quality: ServiceDocPanel adds a literal undefined CSS class outside focused mode

📄 openmetadata-ui/src/main/resources/ui/src/components/common/ServiceDocPanel/ServiceDocPanel.tsx:968-971
The template literal puts ${focusedMode ? 'service-doc-panel-focused' : undefined} straight into the class string. When focusedMode is false, the rendered class becomes layout-row layout-grid undefined. The old Row was given undefined as the whole className, so this extra class is new. Build the string with classNames (already used across the UI) or fall back to ''.

✅ Quality: Consumer-id contract and ConsumerJob rule are not recorded in docs/decisions

📄 openmetadata-service/src/main/java/org/openmetadata/service/events/consumer/Consumers.java:30 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/consumer/Consumers.java:37-44 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/consumer/ConsumerProvider.java 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/consumer/ConsumerJob.java:23-29 📄 bootstrap/sql/migrations/native/2.2.0/mysql/schemaChanges.sql:1-6 📄 bootstrap/sql/migrations/native/2.2.0/postgres/schemaChanges.sql:1-6 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v220/ConsumerIdMigration.java:25-39
This PR adds a stored contract that other components and repositories have to agree with. EventSubscription.className used to hold a Java class name and now holds a registered consumer id (Consumers.DEFAULT = "alert"). Consumers are found only through the ConsumerProvider ServiceLoader SPI, by id or alias. Every alert's Quartz job is stored as org.openmetadata.service.events.consumer.ConsumerJob, and the 2.2.0 schemaChanges.sql rewrites existing rows to that class. Downstream consumers such as Collate subclasses, SDK clients that set className, and the UI all depend on this. It is a durable decision, but no record in docs/decisions/ states it. The rule exists only in the PR description: "An alert names its consumer by a registered id (alert for alerts) instead of a Java class name … A class name a consumer was stored under is still accepted and saved as its id; an unknown consumer is refused with a 400". This repo squash-merges, so that text never reaches git log. The schema still describes the field as a class name too: eventSubscription.json says "Java class for the Event Subscription." and createEventSubscription.json says "Will use 'AlertPublisher' if not provided." Clients reading the spec will keep sending class names.

The record should assert: "An alert names its consumer by the id its ConsumerProvider registers, never by a Java class. Old class names are accepted only as registered aliases and are stored as the id. Every alert's Quartz job is stored with ConsumerJob, so a stored job never names a consumer class."

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@manerow
manerow requested a review from yan-3005 October 14, 2026 13:22
@manerow
manerow added this pull request to the merge queue Oct 14, 2026
@manerow
manerow removed this pull request from the merge queue due to a manual request Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-10-14T21:42:05Z)

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

@manerow
manerow added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 4c91104 Oct 15, 2026
101 of 104 checks passed
@manerow
manerow deleted the refactor/alerting-regroup branch October 15, 2026 07:28
yan-3005 added a commit that referenced this pull request Oct 15, 2026
Resolves import conflicts in EntityCsv, TaskWorkflowHandler and EntityCsvTest:
FormatterUtil moved to events.ChangeEvents (#35032).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

Give alerting code one home, with boundaries the build enforces

5 participants