Skip to content

fix: apps no longer create alerts from their marketplace definition - #36236

Closed
manerow wants to merge 4 commits into
mainfrom
fix/qr7d-remove-app-event-subscriptions
Closed

manerow wants to merge 4 commits into
mainfrom
fix/qr7d-remove-app-event-subscriptions

Conversation

@manerow

@manerow manerow commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

An app's marketplace definition could list alerts (eventSubscriptions). Every install created them without checking that the caller may create alerts: schedule, deploy, restore, a PATCH of the app, and the install at startup.

Anyone who can edit a definition, including a user who becomes the owner of one that has none, could add an alert with a webhook of their choice. The next install created it, and the server sent every later change event to that URL, although POST /v1/events/subscriptions refuses that user.

No app we ship (OpenMetadata or Collate) has ever listed alerts in its definition, and nothing else reads the field. So this PR removes the feature instead of adding a permission check to each install path:

  • eventSubscriptions is removed from app.json, appMarketPlaceDefinition.json and createAppMarketPlaceDefinitionReq.json, plus the install and cleanup code that used it. A request that still sends the field gets a 400.
  • The cleanup that hard-deleted every alert listed on a deleted app goes too: an app owner could list someone else's alert there.
  • className on alerts (custom consumers), from the same original change, is used and stays.

Removing the field moved three shared generated enums, so they are now pinned to org.openmetadata.schema.entity.events.{AlertType,Effect,PrefixCondition}. Most files only change an import.

Migration (2.0.7)

Plain SQL in the 2.0.7 postDataMigrationSQLScript.sql, with fixed names, so later code cannot change it. SQL in 2.0.7 also runs on a database already at a 2.1.0 build, which skips 2.0.7 Java steps:

  • alerts an app created are disabled, not deleted, for an admin to review;
  • the app-to-alert links are removed (only links from app);
  • eventSubscriptions leaves stored apps, definitions, versions and change events.

Not possible in SQL: logging the alerts it disables. AppCreatedAlerts, the only Java, logs their names first.

Type of change:

  • Bug fix

Tests:

Unit tests

  • None for the migration, which is SQL; see the real-data check below.

Backend integration tests

  • AppEventSubscriptionRemovalIT:
    • a user who owns an app and its definition cannot add an alert to it, and no alert exists after a reinstall;
    • an app owner cannot attach another user's alert, and deleting the app leaves that alert in place.
  • Both tests fail on main and pass here, on MySQL and Postgres.

Also checked by upgrading a real 2.0.6 database (MySQL and Postgres) through migrate: the same result as the earlier Java version, row for row; a second run changes nothing; a database already at 2.1.0 is cleaned too.

Ingestion integration tests

  • Not applicable.

Playwright (UI) tests

  • Not applicable.

UI screen recording / screenshots:

Not applicable. Only generated UI types change.

Checklist:

  • I have read the CONTRIBUTING document.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests (unit / integration) and listed them above.
  • I have added a test that covers the exact scenario we are fixing.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with the earlier non-blocking request for database migration tests still open.

Findings

  1. P2 Migration lacks database tests ▶

Summary

Removes alerts from app definitions and stops app installs and deletions from creating or deleting alerts.

  • App definitions no longer create alerts, and app deletion leaves alerts alone.
  • The 2.0.7 upgrade disables app-linked alerts and clears their old links.
  • Alert filters use shared event types without changing alert behavior.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Run 2.0.7 migration] --> B[Log app-created alert names]
  B --> C[Disable linked alerts]
  C --> D[Remove app-to-alert links]
  D --> E[Remove eventSubscriptions from stored apps and events]
Loading

Reviews (4) · Last reviewed commit: "fix: run the app alert cleanup as plain ..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner October 26, 2026 10:33
@manerow manerow added the safe to test Add this label to run secure Github workflows on PRs label Oct 26, 2026
@manerow
manerow requested a review from TeddyCr October 26, 2026 10:33
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

Comment on lines +51 to +64
public static void removeAppEventSubscriptions(
Handle handle, ConnectionType connectionType, CollectionDAO dao) {
List<String> appAlerts =
bindLinks(handle.createQuery("SELECT DISTINCT toId" + APP_ALERT_LINKS))
.mapTo(String.class)
.list();
appAlerts.forEach(id -> disable(dao.eventSubscriptionDAO(), UUID.fromString(id)));
bindLinks(handle.createUpdate("DELETE" + APP_ALERT_LINKS)).execute();
removeFieldSql(connectionType).forEach(sql -> handle.createUpdate(sql).execute());
StoredChangeEventCleanup.removeEntityFields(
handle,
connectionType,
Set.of(Entity.APPLICATION, Entity.APP_MARKET_PLACE_DEF),
Set.of(FIELD));

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.

P2 Migration lacks database tests

No automated test runs this migration. StoredChangeEventCleanupTest only checks JSON rewriting, and AppEventSubscriptionRemovalIT checks API behavior after the upgrade. Neither covers alert disabling, relationship removal, database-specific SQL, or paging through stored events.

Add MySQL and Postgres tests that seed linked and unrelated alerts, app versions, and more than 500 stored events. Run the migration twice and check the saved rows. The manual upgrade check described in the PR cannot catch later regressions.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@github-actions

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 79%
79.66% (130539/163864) 66.2% (45989/69466) 69.09% (26083/37750)

Comment on lines +30 to +31
// The 2.0.7 post-data SQL disables these alerts; their names go to the log first.
AppCreatedAlerts.logForReview(handle);

@gitar-bot gitar-bot Bot Oct 26, 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: Alerts disabled without being logged when 2.0.7 is reprocessed

MigrationWorkflow.shouldRunDataMigration (MigrationWorkflow.java:508-514) skips the Java data migration for a reprocessed version from an earlier release train. postDataMigrationSQLScript.sql still runs as appended SQL, because hasPendingWork counts it as new statements. On a database already at 2.1.0 (the 2.1.0 migration dir exists), upgrading reprocesses 2.0.7, so the SQL disables every app-created alert and deletes its entity_relationship rows, but AppCreatedAlerts.logForReview never runs. No names get logged, and once the relations are gone the alerts can no longer be identified. That breaks the stated guarantee that disabled alerts are logged by name so an admin can review them. One fix is to have the SQL leave a durable marker on each alert it disables (for example $.disabledByAppRemoval = true, or a row in a review table) and have the log query read that marker. The marker query can then also run from the 2.1.0 migration or another step that always runs. Another option is to move the disable/untie into the same Java step as the log, so the two always run or skip together.

Mark the disabled alerts in SQL so the log query can still find them after the relations are deleted (MySQL shown; Postgres uses jsonb_set with '{disabledByAppRemoval}').:

UPDATE event_subscription_entity
SET json = JSON_SET(json, '$.enabled', CAST('false' AS JSON), '$.disabledByAppRemoval', CAST('true' AS JSON))
WHERE id IN (SELECT toId FROM entity_relationship WHERE fromEntity = 'app' AND toEntity = 'eventsubscription' AND relation = 0);

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 2 closed / 3 findings

🔴 High risk · The 2.0.7 migration disables app-linked alerts and removes stored links and fields, so an error could disrupt alert configuration or historical records.

Removes the marketplace eventSubscriptions field and its install and cleanup code so apps no longer create alerts, with a 2.0.7 migration that disables app-created alerts and unlinks them. Changes requested: the disable/unlink SQL can run without the Java step that logs disabled alerts by name when 2.0.7 is reprocessed, leaving no admin review record and making those alerts hard to identify later.

Resolved this session: event cleanup now pages by matching rows instead of ids across whole tables, and the removal of the eventSubscriptions contract now has a decision record.

⚠️ Bug: Alerts disabled without being logged when 2.0.7 is reprocessed

📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v207/Migration.java:30-31 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/postgres/v207/Migration.java:30-31 📄 bootstrap/sql/migrations/native/2.0.7/mysql/postDataMigrationSQLScript.sql:6-11 📄 bootstrap/sql/migrations/native/2.0.7/postgres/postDataMigrationSQLScript.sql:6-11 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v207/AppCreatedAlerts.java:28-42

MigrationWorkflow.shouldRunDataMigration (MigrationWorkflow.java:508-514) skips the Java data migration for a reprocessed version from an earlier release train. postDataMigrationSQLScript.sql still runs as appended SQL, because hasPendingWork counts it as new statements. On a database already at 2.1.0 (the 2.1.0 migration dir exists), upgrading reprocesses 2.0.7, so the SQL disables every app-created alert and deletes its entity_relationship rows, but AppCreatedAlerts.logForReview never runs. No names get logged, and once the relations are gone the alerts can no longer be identified. That breaks the stated guarantee that disabled alerts are logged by name so an admin can review them. One fix is to have the SQL leave a durable marker on each alert it disables (for example $.disabledByAppRemoval = true, or a row in a review table) and have the log query read that marker. The marker query can then also run from the 2.1.0 migration or another step that always runs. Another option is to move the disable/untie into the same Java step as the log, so the two always run or skip together.

Mark the disabled alerts in SQL so the log query can still find them after the relations are deleted (MySQL shown; Postgres uses jsonb_set with '{disabledByAppRemoval}').
UPDATE event_subscription_entity
SET json = JSON_SET(json, '$.enabled', CAST('false' AS JSON), '$.disabledByAppRemoval', CAST('true' AS JSON))
WHERE id IN (SELECT toId FROM entity_relationship WHERE fromEntity = 'app' AND toEntity = 'eventsubscription' AND relation = 0);
✅ 2 closed
✅ Performance: Event cleanup pages by matching rows, not ids, scanning whole tables

📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/StoredChangeEventCleanup.java:55-69 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/StoredChangeEventCleanup.java:145-159
StoredChangeEventCleanup.nextBatch runs SELECT … WHERE <entityType> IN (…) AND (keys) > (…) ORDER BY keys LIMIT 500. For successful_sent_change_events and consumers_dlq, the entity-type test is a JSON expression (t.json ->> '$.entityType', t.json -> 'changeEvent' ->> 'entityType') that no index covers. App and definition events are rare, so a single SELECT keeps walking the primary key until it finds 500 matches. In practice that means one statement scans the whole table, so its run time grows with the tenant.

This goes against the Accepted record docs/decisions/2026-10-09-data-migration-backfills-walk-ids-in-batches.md: "A data migration that backfills rows of a table it does not bound by an indexed predicate walks that table's ids through IdBatches.fold: keyset pages of 500 ids … restricted to the page's ids." That record exists because a long single statement gets killed by the database's long-query reaper, and then the step fails the same way on every retry.

Fix: for the tables whose entity-type predicate isn't indexed, walk primary-key pages first ((keys) > (…) ORDER BY keys LIMIT 500, with no JSON filter in the page query), then filter the page's rows in Java or with IN (<page keys>). The alternative is a new record that supersedes this one.

✅ Quality: Removing app eventSubscriptions contract has no decision record

📄 openmetadata-spec/src/main/resources/json/schema/entity/applications/marketplace/createAppMarketPlaceDefinitionReq.json 📄 openmetadata-spec/src/main/resources/json/schema/entity/applications/app.json 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/AppEventSubscriptionRemoval.java:31-45 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v210/Migration.java
This PR removes a contract field that other components depend on. eventSubscriptions is gone from app.json, appMarketPlaceDefinition.json and createAppMarketPlaceDefinitionReq.json, along with the generated TS types. With additionalProperties: false, clients and app packages that still send the field now get a 400. Nothing in docs/decisions/ records this, and the description states rules that exist nowhere in the tree. The repo squash-merges, so those rules would be lost.

The record would say: "An app never creates, owns or deletes alerts. App and marketplace definitions carry no eventSubscriptions, and a request that sends it is rejected with 400. On upgrade, alerts an app created are disabled and unlinked from the app, not deleted, and their names are logged for an admin to review. className on alerts stays because custom consumers use it." These come from the description: "A request that still sends eventSubscriptions gets a 400", "className on alerts stays because custom consumers use it", and "disables alerts that apps created rather than deleting them".

The migration also relies on an ordering across files: the comment says it runs "Next, so no later step reads an app, a definition or one of their change events that still lists them". That ordering is a rule worth stating in the same record.

🤖 Prompt for agents
Code Review: Removes the marketplace `eventSubscriptions` field and its install and cleanup code so apps no longer create alerts, with a 2.0.7 migration that disables app-created alerts and unlinks them. Changes requested: the disable/unlink SQL can run without the Java step that logs disabled alerts by name when 2.0.7 is reprocessed, leaving no admin review record and making those alerts hard to identify later.
  
  Resolved this session: event cleanup now pages by matching rows instead of ids across whole tables, and the removal of the `eventSubscriptions` contract now has a decision record.

1. ⚠️ Bug: Alerts disabled without being logged when 2.0.7 is reprocessed
   Files: openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v207/Migration.java:30-31, openmetadata-service/src/main/java/org/openmetadata/service/migration/postgres/v207/Migration.java:30-31, bootstrap/sql/migrations/native/2.0.7/mysql/postDataMigrationSQLScript.sql:6-11, bootstrap/sql/migrations/native/2.0.7/postgres/postDataMigrationSQLScript.sql:6-11, openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v207/AppCreatedAlerts.java:28-42

   `MigrationWorkflow.shouldRunDataMigration` (MigrationWorkflow.java:508-514) skips the Java data migration for a reprocessed version from an earlier release train. `postDataMigrationSQLScript.sql` still runs as appended SQL, because `hasPendingWork` counts it as new statements. On a database already at 2.1.0 (the `2.1.0` migration dir exists), upgrading reprocesses 2.0.7, so the SQL disables every app-created alert and deletes its `entity_relationship` rows, but `AppCreatedAlerts.logForReview` never runs. No names get logged, and once the relations are gone the alerts can no longer be identified. That breaks the stated guarantee that disabled alerts are logged by name so an admin can review them. One fix is to have the SQL leave a durable marker on each alert it disables (for example `$.disabledByAppRemoval = true`, or a row in a review table) and have the log query read that marker. The marker query can then also run from the 2.1.0 migration or another step that always runs. Another option is to move the disable/untie into the same Java step as the log, so the two always run or skip together.

   Fix (Mark the disabled alerts in SQL so the log query can still find them after the relations are deleted (MySQL shown; Postgres uses jsonb_set with '{disabledByAppRemoval}').):
   UPDATE event_subscription_entity
   SET json = JSON_SET(json, '$.enabled', CAST('false' AS JSON), '$.disabledByAppRemoval', CAST('true' AS JSON))
   WHERE id IN (SELECT toId FROM entity_relationship WHERE fromEntity = 'app' AND toEntity = 'eventsubscription' AND relation = 0);

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

@manerow

manerow commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Replaced by PR #36251, which combines this change with its companion fix in one PR.

@manerow manerow closed this Oct 26, 2026
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

This branch was previously deployed

1 inactive deployment
test — fe52b30f Deployed Oct 26, 2026 by manerow via RDF Playwright execution #39276
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.

1 participant