Skip to content

feat(alerts): alert definitions validate what changed, keep hand-written rules and watch several sources - #33969

Merged
manerow merged 21 commits into
feat/alerting-redesign-2-alert-catalogfrom
feat/alerting-redesign-3-alert-definitions
Oct 6, 2026
Merged

manerow merged 21 commits into
feat/alerting-redesign-2-alert-catalogfrom
feat/alerting-redesign-3-alert-definitions

Conversation

@manerow

@manerow manerow commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #20504

What this pull request implements

  • A definition is validated only when it changed. An unchanged definition is kept as stored; a new or changed one is checked strictly.
  • Rules and triggers written by hand survive. A save that carries none keeps them, as a REST save or the form does. A save that carries rules (server code saving the whole alert, or a PATCH) replaces them, checked like any new rule.
  • An alert can watch several sources of one kind, for example tables, topics and containers together.
  • A new endpoint, POST /v1/events/subscriptions/capabilities, tells a client which filters and triggers a selection of sources supports, and why a source cannot join it.

What was wrong before

Every save rebuilt the alert's rules from the form's selections and checked the whole definition. An alert stored under older rules failed every later save, even a rename, and conditions written by hand were replaced. The save also accepted only one source. The 2.0 upgrade makes mention alerts watch conversations and tasks, so they could no longer be edited.

Design

  • AlertDefinition holds what an alert watches and when it fires, as the user chose it, plus the stored rules compiled from those choices. It compares the incoming definition with the stored one and validates only what changed.
  • AlertDefinitionPolicy records where an alert's rules come from. Rules compiled from form selections are compiled again on every save. Rules or triggers written by hand, by the system or by another product have no selections behind them, so only rules a save carries replace them; a request has no place for rules, so the mapper leaves them absent. An alert keeps its kind until a save brings selections.
  • SeveralSources holds the rules for combining sources: the sources are "any of", the filters "all of", and a trigger applies only to the sources that support it. Anything else is refused with a message that names the rule. StoredRules checks the stored rules, whoever wrote them.
  • SourceCapabilities works out what a selection supports with the same code the save uses, so a client cannot offer what the save would reject; the new endpoint serves it. UnreachableSource explains, from the catalog alone, a selected source that can never match with what has been chosen so far; it never looks a chosen name up. Such an alert still saves, and the client can show the reason as a warning.

What users notice

  • Alerts upgraded to watch conversations and tasks, and other alerts saved under older rules, can be edited and switched back on.
  • Editing an alert whose conditions were written by hand keeps those conditions.
  • Through the API, one alert can watch several asset types.

How it was tested

The alerting unit tests (54 classes, 457 tests), the new AlertDefinitionIT and CapabilitiesIT (21 tests) and the existing alert integration tests (565 tests) pass on MySQL and on PostgreSQL.

@manerow manerow added the safe to test Add this label to run secure Github workflows on PRs label Sep 24, 2026
@manerow
manerow requested a review from a team as a code owner September 24, 2026 15:14
@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

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 75%
75.74% (117309/154872) 61.5% (72158/117320) 62.89% (24089/38299)

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

looks good

Comment on lines 1309 to +1316
assertThrows(
Exception.class,
() -> createEntity(request),
"Multiple resources are not supported - only one resource can be specified");
() -> createEntity(entityPlusActivity),
"Entity and activity sources share no filters and cannot be combined");
assertThrows(
Exception.class,
() -> createEntity(wildcardPlusOne),
"The wildcard already watches everything and stands alone");

@gitar-bot gitar-bot Bot Oct 5, 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.

💡 Quality: Rejection test passes on any failure, not the combining rule

Both assertThrows(Exception.class, ...) calls pass for any exception. The third argument is only the message JUnit shows when nothing is thrown; it is never compared to the server's error. SeveralSources checks several things in turn (not empty, every name known, the wildcard alone, one kind), so this test would also pass if conversation were rejected as an unknown name, or for an unrelated reason such as a destination or auth error. In that case the 'different kinds' and 'all stands alone' rules would not actually be tested. Catch the exception and check that its message contains the text SeveralSources uses, for example 'Sources of different kinds cannot be combined' and "The source 'all' already watches everything".

Check the server's rejection reason:

Exception mixed = assertThrows(Exception.class, () -> createEntity(entityPlusActivity));
assertTrue(mixed.getMessage().contains("Sources of different kinds cannot be combined"));
Exception wildcard = assertThrows(Exception.class, () -> createEntity(wildcardPlusOne));
assertTrue(wildcard.getMessage().contains("already watches everything"));

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)

No failing check on merge-queue commit 6111543 — invalidated by an entry ahead in the queue, or a required check timed out.

@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)

No failing check on merge-queue commit 303c770 — invalidated by an entry ahead in the queue, or a required check timed out.

manerow added 21 commits October 6, 2026 15:51
@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 👍 Approved with suggestions 2 closed / 3 findings

🟡 Medium risk · Alert validation and multi-source matching change backend alert evaluation and delivery

Adds validation of alert definitions only when they change, preserves hand-written rules and triggers, and enables watching multiple sources of one kind through a new capabilities endpoint. The test for combining-rule rejection passes on any exception rather than checking the specific error message, so it should verify that the server's message contains the expected text like 'Sources of different kinds cannot be combined' or 'The source 'all' already watches everything'.

💡 Quality: Rejection test passes on any failure, not the combining rule

📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/EventSubscriptionResourceIT.java:1309-1316

Both assertThrows(Exception.class, ...) calls pass for any exception. The third argument is only the message JUnit shows when nothing is thrown; it is never compared to the server's error. SeveralSources checks several things in turn (not empty, every name known, the wildcard alone, one kind), so this test would also pass if conversation were rejected as an unknown name, or for an unrelated reason such as a destination or auth error. In that case the 'different kinds' and 'all stands alone' rules would not actually be tested. Catch the exception and check that its message contains the text SeveralSources uses, for example 'Sources of different kinds cannot be combined' and "The source 'all' already watches everything".

Check the server's rejection reason
Exception mixed = assertThrows(Exception.class, () -> createEntity(entityPlusActivity));
assertTrue(mixed.getMessage().contains("Sources of different kinds cannot be combined"));
Exception wildcard = assertThrows(Exception.class, () -> createEntity(wildcardPlusOne));
assertTrue(wildcard.getMessage().contains("already watches everything"));
✅ 2 closed
✅ Security: Capabilities warning reveals which service names exist, ignoring authz

📄 openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/UnreachableSource.java:68-82 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/events/subscription/EventSubscriptionResource.java:960-966
UnreachableSource.everyChosenNameIsElsewhere looks up the first part of each filterByFqn value with Entity.getEntityByName for every *Service entity type, and no per-entity authorization is checked. The endpoint only needs VIEW_BASIC on event subscriptions, so the text of the returned warning tells a caller whether a service with a given name exists and what kind it is, even when the caller cannot see that service. Each request can also make up to (names × service types) database lookups, and the form may call it on every change. Suggested fix: run the lookups through the caller's authorization, or build the warning only from the catalog (the container entity types) so it no longer depends on which entities exist. At minimum, cap how many names are looked up.

✅ Edge Case: Hand-written triggers (filteringRules.actions) are not treated as hand-written

📄 openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/AlertDefinitionPolicy.java:48-54 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/AlertDefinitionPolicy.java:80-91
of() decides an alert is hand-written only when rules.getRules() is non-empty and never looks at rules.getActions(). Take an OBSERVABILITY/NOTIFICATION alert whose stored filteringRules.actions were written by the system, another product or an older release, with empty rules and no input. It is classified FromSelections. On the next rename or enable PATCH, isSameDefinition is true, so compileOrKeep rebuilds from the empty input and returns empty actions. The stored triggers are silently erased, which goes against the policy's own promise that nothing replaces rules without selections behind them. Fix: also count non-empty stored actions when detecting hand-written rules.

🤖 Prompt for agents
Code Review: Adds validation of alert definitions only when they change, preserves hand-written rules and triggers, and enables watching multiple sources of one kind through a new capabilities endpoint. The test for combining-rule rejection passes on any exception rather than checking the specific error message, so it should verify that the server's message contains the expected text like 'Sources of different kinds cannot be combined' or 'The source \'all\' already watches everything'.

1. 💡 Quality: Rejection test passes on any failure, not the combining rule
   Files: openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/EventSubscriptionResourceIT.java:1309-1316

   Both `assertThrows(Exception.class, ...)` calls pass for any exception. The third argument is only the message JUnit shows when nothing is thrown; it is never compared to the server's error. `SeveralSources` checks several things in turn (not empty, every name known, the wildcard alone, one kind), so this test would also pass if `conversation` were rejected as an unknown name, or for an unrelated reason such as a destination or auth error. In that case the 'different kinds' and 'all stands alone' rules would not actually be tested. Catch the exception and check that its message contains the text `SeveralSources` uses, for example 'Sources of different kinds cannot be combined' and "The source 'all' already watches everything".

   Fix (Check the server's rejection reason):
   Exception mixed = assertThrows(Exception.class, () -> createEntity(entityPlusActivity));
   assertTrue(mixed.getMessage().contains("Sources of different kinds cannot be combined"));
   Exception wildcard = assertThrows(Exception.class, () -> createEntity(wildcardPlusOne));
   assertTrue(wildcard.getMessage().contains("already watches everything"));

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

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ UI Checkstyle passed — lint findings in changed files

🔍 ESLint findings in this PR's files — 0 error(s), 28 warning(s)

Errors block the build. Warnings do not yet — they are rules whose backlog is still
being worked down, listed so this PR does not add to it. See docs/ui-code-quality-gate.md.

0 error(s), 28 warning(s) across 16 changed file(s).

Count Rule
14 react-hooks/exhaustive-deps
13 openmetadata-imports/no-lower-layer-page-imports
1 openmetadata-imports/no-cross-page-imports
All findings
Location Rule Message
🟡 src/components/Alerts/AlertDetails/AlertConfigDetails/AlertConfigDetails.tsx:34:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/Alerts/AlertDetails/AlertConfigDetails/AlertConfigDetails.tsx:108:6 react-hooks/exhaustive-deps React Hook useCallback has a missing dependency: 't'. Either include it or remove the dependency array.
🟡 src/components/Alerts/AlertDetails/AlertConfigDetails/AlertConfigDetails.tsx:139:6 react-hooks/exhaustive-deps React Hook useCallback has missing dependencies: 'getResourcePermission' and 't'. Either include them or remove the dependency array.
🟡 src/components/Alerts/AlertDetails/AlertConfigDetails/AlertConfigDetails.tsx:145:6 react-hooks/exhaustive-deps React Hook useEffect has a missing dependency: 'fetchTemplates'. Either include it or remove the dependency array.
🟡 src/components/Alerts/AlertDetails/AlertConfigDetails/AlertConfigDetails.tsx:149:6 react-hooks/exhaustive-deps React Hook useEffect has a missing dependency: 'fetchFunctions'. Either include it or remove the dependency array. Outer scope values like 'Fqn' aren't valid de
🟡 src/components/Alerts/AlertFormSourceItem/AlertFormSourceItem.tsx:114:5 react-hooks/exhaustive-deps React Hook useCallback has a missing dependency: 'form'. Either include it or remove the dependency array.
🟡 src/components/Alerts/DestinationFormItem/DestinationFormItem.component.tsx:36:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/Alerts/DestinationFormItem/DestinationFormItem.component.tsx:72:9 react-hooks/exhaustive-deps The 'destinations' logical expression could make the dependencies of useMemo Hook (at line 86) change on every render. To fix this, wrap the initialization of '
🟡 src/components/Alerts/DestinationFormItem/DestinationFormItem.component.tsx:72:9 react-hooks/exhaustive-deps The 'destinations' logical expression could make the dependencies of useCallback Hook (at line 146) change on every render. To fix this, wrap the initialization
🟡 src/components/Alerts/DestinationFormItem/DestinationFormItemFormBridge.tsx:19:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/Alerts/DestinationFormItem/DestinationSelectItem/DestinationSelectItem.tsx:60:9 react-hooks/exhaustive-deps The 'destinationItem' logical expression could make the dependencies of useMemo Hook (at line 105) change on every render. To fix this, wrap the initialization
🟡 src/components/observability/Alerts/AlertAiDestinationSection.component.tsx:60:9 react-hooks/exhaustive-deps The 'destinations' logical expression could make the dependencies of useCallback Hook (at line 107) change on every render. To fix this, wrap the initialization
🟡 src/components/observability/Alerts/AlertAiFormFields.component.test.tsx:47:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/observability/Alerts/AlertAiFormFields.interface.ts:24:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/observability/Alerts/AlertAiFormFieldsSearchUtils.ts:20:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/observability/Alerts/AlertDetailsPage.test.tsx:29:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/observability/Alerts/AlertDetailsPage.tsx:46:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/observability/Alerts/AlertEditModal.component.test.tsx:30:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/observability/Alerts/AlertEditModal.component.tsx:25:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/observability/Alerts/AlertEditModal.component.tsx:29:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/pages/AddNotificationPage/AddNotificationPage.tsx:85:1 openmetadata-imports/no-cross-page-imports Page features must not import another page feature. Move shared code to components, hooks, interfaces, or pure utilities.
🟡 src/pages/AddNotificationPage/AddNotificationPage.tsx:148:5 react-hooks/exhaustive-deps React Hook useMemo has a missing dependency: 't'. Either include it or remove the dependency array.
🟡 src/pages/AddNotificationPage/AddNotificationPage.tsx:193:6 react-hooks/exhaustive-deps React Hook useEffect has missing dependencies: 'fetchAlert' and 'fetchFunctions'. Either include them or remove the dependency array.
🟡 src/pages/AddNotificationPage/AddNotificationPage.tsx:221:5 react-hooks/exhaustive-deps React Hook useCallback has missing dependencies: 'getResourceLimit' and 'setInlineAlertDetails'. Either include them or remove the dependency array.
🟡 src/pages/AddNotificationPage/AddNotificationPage.tsx:282:6 react-hooks/exhaustive-deps React Hook useCallback has missing dependencies: 'getResourcePermission' and 't'. Either include them or remove the dependency array.
🟡 src/pages/AddNotificationPage/AddNotificationPage.tsx:288:6 react-hooks/exhaustive-deps React Hook useEffect has a missing dependency: 'fetchTemplates'. Either include it or remove the dependency array.
🟡 src/utils/Alerts/AlertsUtil.test.tsx:36:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/utils/Alerts/AlertsUtilPure.ts:42:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.

Fix locally (fast - only checks files changed in this branch):

make ui-checkstyle-changed

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

Support Multi-Select in Notification Source

2 participants