Skip to content

refactor(alerts): alert jobs carry no data and have one writer - #33972

Merged
manerow merged 13 commits into
feat/alerting-redesign-5-alert-statefrom
feat/alerting-redesign-6-alert-jobs
Oct 6, 2026
Merged

manerow merged 13 commits into
feat/alerting-redesign-5-alert-statefrom
feat/alerting-redesign-6-alert-jobs

Conversation

@manerow

@manerow manerow commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #34265

What this pull request implements

  • Jobs carry no data. An alert's job holds nothing but the alert id; everything else is read from the stored alert and its rows.
  • One writer for jobs, after commit. The repository brings an alert's job in step after every save commits, on every path: REST, repository calls, bulk create, delete and a cascade delete from a parent. A save that rolls back schedules nothing.
  • A reconciler repairs a missing or broken job and removes leftovers.
  • GET /v1/events/subscriptions/id/{id}/scheduling shows an alert's job, trigger state, position, lag and what the last reconcile found.

What was wrong before

Jobs were scheduled from several places, each storing its own copy of the alert in the job data, and only the REST resource kept them in step. An alert saved another way could run with an old copy of itself, or not run at all. A job whose scheduler call failed stayed broken until the alert was saved again or the server restarted.

Design

flowchart LR
    subgraph CALLERS["Ask for an alert's job to match its stored row"]
        BOOT["Server start"]
        TICK["AlertTick: alert gone or off"]
        REPO["Repository: after each commit"]
        REC["AlertReconciler: each round"]
    end
    JOBS["AlertJobs: the only writer of alert jobs"]
    ALERT["Stored alert"]
    AJOB["Quartz job per enabled alert: named by its id, runs AlertPublisher, no data"]
    RECORD["AlertRecord"]
    BOOT --> JOBS
    TICK --> JOBS
    REPO --> JOBS
    REC --> JOBS
    JOBS -->|decides from| ALERT
    JOBS -->|schedules or removes| AJOB
    JOBS -->|rows first| RECORD
    REPO -->|forget deleted rows| RECORD
    REC -->|forget leftovers| RECORD
Loading
  • AlertJobs is the only class that creates, updates or removes an alert's job. It decides from the stored row, never from a copy a caller holds: two saves can commit in one order and arrive in the other, and a disable arriving last must not delete the job an enable just wrote. A lock per alert orders this server's callers, and the row is read again after applying, so a save another server committed in between is caught too. Every job is stored with AlertPublisher, a class every server can load, and is named by the alert's id.
  • AlertJobView is the read-only view of the job store.
  • AlertReconciler runs inside each server rather than as a scheduled job, so there is no job class another release could fail to load. It repairs a save whose scheduler call failed, a trigger stuck in error or frozen in the past, and a job or rows left behind by a deleted alert. It acts only on keys that name an alert; any other key is reported and left alone.
  • ReconcileRound records what one round did, and ReconcilerMetrics counts rounds by outcome, so a round that fails or stops coming is visible.
  • AuditLogSchedule gives the audit log consumer, which is not an alert, its own job: it reads change events and writes the audit log on a fixed interval, one instance at a time across the cluster.

What users notice

Nothing new in normal use; alerts saved through any path now run as saved.

For code built on OpenMetadata

The scheduler's publisher methods are removed. Saving or deleting the alert through its repository schedules or removes its job.

How it was tested

The alerting unit tests (65 classes, 488 tests), the alert integration tests (7 classes, 69 tests, including AlertStateIT's save, rollback and cascade delete paths and AlertReconcilerIT) 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

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 6b26f0c — 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.

@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 1 closed / 1 findings

🟡 Medium risk · Alert job lifecycle, reconciliation, and repository hooks change execution across alert save paths.

Refactors alert job scheduling so jobs carry only the alert ID and are written exclusively by AlertJobs, ensuring consistency across all save paths (REST, repository, bulk create, delete, cascade delete). Includes a reconciler to repair missed or broken jobs and an endpoint to inspect job state. Resolved issue where reconciler counted failed repairs as repaired rather than failures. No open issues found.

✅ 1 closed
✅ Bug: Reconciler counts failed repairs as repaired, never as failures

📄 openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/AlertReconciler.java:140-147 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/AlertReconciler.java:161-175 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/AlertReconciler.java:237-241 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/AlertJobs.java:89-98
The reconciler repairs by calling AlertJobs.converge(id), and converge catches every SchedulerException/RuntimeException and only logs it. The reconciler then calls count(...) without checking whether anything changed. If the job store is failing (for example the Quartz pool is exhausted or a trigger write fails), every broken alert is logged and added to ReconcilerMetrics.repaired each round. failuresThisRound stays at 0 and the round reports COMPLETED. reconcileQuietly's failure path and the PARTIAL outcome can never trigger for scheduler errors, so the thing the class doc promises to make visible, a round that fails, stays hidden. Fix: give the reconciler a converge variant that throws, such as a package-private AlertJobs.convergeOrThrow that calls settle directly. reconcileQuietly would then count those errors as failures, and a repair would only be counted after it succeeds.

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