Skip to content

refactor(alerts): alert rows own the state and consumers declare their kind - #33971

Merged
manerow merged 16 commits into
feat/alerting-redesign-4-alert-form-sourcesfrom
feat/alerting-redesign-5-alert-state
Oct 6, 2026
Merged

manerow merged 16 commits into
feat/alerting-redesign-4-alert-form-sourcesfrom
feat/alerting-redesign-5-alert-state

Conversation

@manerow

@manerow manerow commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #34265

What this pull request implements

An alert's running state moves out of the scheduler's job data into rows of its own: its position in the change log, its wait for a gap, its counters, each destination's health, the events it delivered and its failures. Every tick reads the alert's stored row first. Each consumer declares its kind.

What was wrong before

The state lived in the Quartz job data, and when a tick ended the scheduler wrote the job data it started with back over the job. An edit made while the alert was running, a switch-off or a skipped backlog was undone, and destination health was reset on every edit and restart. Nothing recorded which event a tick was working on, so a change that stopped the server every time an alert processed it was read again after every restart.

Design

flowchart TD
    subgraph CALLERS["Callers"]
        direction LR
        SCHED["EventSubscriptionScheduler"]
        REPO["EventSubscriptionRepository"]
        TICK["AlertTick: reads the stored alert first"]
        CONSUMER["Consumer of kind EVENT, BATCH or SELF_DRIVEN"]
    end
    subgraph PLANE["Ledger package: creates, opens and writes the rows"]
        direction LR
        RECORD["AlertRecord"]
        LEDGER["AlertLedger, one per tick"]
    end
    subgraph ROWS["The alert's rows: what it has done"]
        direction LR
        STATE["change_event_consumers: position, counters, gap wait, health, event in progress"]
        SENT["successful_sent_change_events: delivered"]
        DLQ["consumers_dlq: failed"]
    end
    TICK -->|runs the one the alert names| CONSUMER
    SCHED -->|creates rows, reads health and position| RECORD
    REPO -->|skips the backlog| RECORD
    TICK -->|opens the ledger| RECORD
    RECORD -->|creates| LEDGER
    CONSUMER -->|reports to| LEDGER
    RECORD -->|creates, skips the backlog| STATE
    LEDGER -->|position by compare-and-set, then the rest| STATE
    LEDGER --> SENT
    LEDGER --> DLQ
Loading
  • AlertTick starts every tick. The stored alert is the authority: the tick reads its row, does nothing for an alert that is gone or switched off, then opens the ledger and runs the consumer the row names.
  • AlertLedger collects what one tick leaves behind and writes once, at commit: the position first, by compare-and-set against the document it opened with, then the counters, then the rest as best effort. A position someone else moved in the meantime is never overwritten.
  • AlertRecord creates an alert's rows and opens them for a tick. AlertRows is the one way to read the stored alert: its own row, uncached, then its notification template. Only the alert's own row says whether it is gone.
  • A consumer declares its kind by implementing BatchConsumer or SelfDrivenConsumer; one that implements neither handles events one by one. ConsumerKind.of reads it from the class without building the consumer. A consumer that makes its own work is counted by what it reported and has no backlog of change events.
  • A tick notes the position it opens at and clears the note however it ends; six ticks in a row that never come back from there set that event aside as failed.
  • The health row holds only what ticks report. Disabled is decided when a status is read, and never stored. HealthStreak counts each destination's failed ticks in a row.

What users notice

  • Editing an alert, switching it off, or skipping its backlog takes effect even while it runs.
  • Destination status keeps its last value across edits and restarts, and a disabled destination reports Disabled.
  • An alert that has never run starts from the moment it is first enabled.

For code built on OpenMetadata

A subclass of AbstractEventConsumer that takes whole batches implements BatchConsumer; one that makes its own work implements SelfDrivenConsumer.

How it was tested

The alerting unit tests (60 classes, 472 tests), the alert integration tests (6 classes, 48 tests, including AlertLedgerIT, AlertStateIT and AlertTickOutcomesIT) and the existing alert integration tests (565 tests) pass on MySQL and on PostgreSQL.

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

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

@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 8f128d7 — 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)

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

manerow added 16 commits October 6, 2026 15:54
@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 2 closed / 2 findings

🟡 Medium risk · Alert delivery, cursor persistence, and destination health now use a new ledger.

Refactors alert state out of the scheduler's job data into dedicated ledger rows, with each consumer declaring its kind. Fixes stale destination health by reading from stored state only and ensures opening notes survive failed commits to properly track failed events. No issues found.

✅ 2 closed
✅ Bug: Stored health overrides destination enabled flag (stale Disabled/Active)

📄 openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/EventSubscriptionScheduler.java:501-511 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/ledger/AlertRecord.java:44 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/ledger/AlertRecord.java:102-116
AlertRecord.start writes the health row only once, when the row is absent, and initialHealth records DISABLED or ACTIVE depending on each destination's enabled flag at that moment. destinationsWithHealth then shows the stored entry whenever there is one, and only falls back to healthWithoutHistory (the one place that checks destination.getEnabled()) when nothing is stored. Disabled destinations are filtered out in groupDestinationsByType, so no tick ever reports on them. The result:

  • A destination that is disabled after the first schedule keeps showing its last ACTIVE or FAILED status indefinitely.
  • A destination that was disabled at the first schedule and is re-enabled later keeps showing DISABLED until it sends something.

This contradicts the PR's claim that "a disabled destination reports Disabled".

Fix: work out DISABLED when the status is read, and don't persist it. Either store only ACTIVE or no entry in initialHealth, or ignore a stored DISABLED entry when the destination is now enabled.

✅ Edge Case: Opening note survives a failed commit, so the next event can be set aside

📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/changeEvent/AbstractEventConsumer.java 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/ledger/AlertLedger.java:136-142 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/ledger/AlertLedger.java:182-193
finishTick calls commit(context) and then ledger.clearOpeningNote() with no try/finally around them. commitPosition and commitCounters are not wrapped in attempt, so a DB error there (for example a transient connection failure) escapes before the note is deleted. That leaves the IN_PROGRESS row at the same position, and the next tick counts this tick as interrupted even though it ended normally. After six such failures readAndPublish sends the first event to the failed-event table as "Interrupted repeatedly" without delivering it. This goes against the note's own contract: "A tick that ends, however it ends, was not interrupted." Fix: put clearOpeningNote() in a finally block.

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.

An alert's state lives in the scheduler's job data: a running tick undoes edits, health resets, and jobs drift from their alert

3 participants