Skip to content

fix(alerts): bound the work of each alert request and tick - #36279

Merged
manerow merged 17 commits into
mainfrom
fix/alerts-bounded-status
Oct 28, 2026
Merged

manerow merged 17 commits into
mainfrom
fix/alerts-bounded-status

Conversation

@manerow

@manerow manerow commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What was wrong

Alerting work grew without limit with what an alert held, a request asked for, or a user wrote, so one request or tick could fill the heap or hold threads forever:

  • Chat rendering. Slack, Teams and Google Chat messages had no size limit.
  • Event reads and listings. A stored batchSize went straight to SQL, every change event embeds its whole entity, and the eight alert event listings had no row limit.
  • Alert page counts. eventsRecord and diagnosticInfo evaluated every unread event on each view.
  • Alert settings. batchSize, destinations and receivers had no upper bound; saving compared destinations in quadratic time.
  • The alert loop. A tick that died of an Error (for example OutOfMemoryError) was retried forever instead of being set aside.
  • Sends and mail. Sends had no total deadline, test sends ran one at a time, and mail used an unbounded queue.

What this changes

Each path gets one fixed bound, recorded in ADR:2026-10-26-alerting-bounds-the-work-of-each-request-and-tick:

What Bound
batchSize 1 to 1000
Destinations per alert or test send 50
Receivers per destination 100 entries: typed addresses, or user and team names (a team still reaches all its members)
Alert event listings 1000 rows, no embedded entity
One change-event read 1000 rows and 8 MB, at least one event
Pending count 500 events evaluated, then "500+"; 4 running and 16 waiting, then 429
Test sends 30 s per request, 8 at once, then 429
One HTTP exchange connect plus read timeout in total, 1 MB response body
Chat rendering 200,000 HTML characters, depth 48, 50,000 characters and table cells
Mail a bounded queue each for alert and account mail; a full queue makes the caller send

Also:

  • A save may refuse only a value that grows past a bound, so an alert already stored past one stays editable, through PATCH and PUT.
  • Receivers are judged for the whole alert: a save is refused when the sum of receivers past the limit grows. Old lists can be kept or trimmed, never grown or copied.
  • A tick that ends in an Error keeps its "in progress" note, so the existing set-aside after six attempts applies.
  • The audit log consumer decides it has caught up from offsets, not from a short read.
  • Code fences follow CommonMark and link targets are percent-encoded, so content cannot break out of Markdown.

What users see

  • Normal alerts: nothing changes.
  • Large backlogs: the page shows "500+".
  • Past a bound: a 400; under load, a 429.
  • Silent destinations: a test send answers within 30 s.
  • API clients: listed events no longer carry entity.

Before merging

Please check the bounds against real data: no stored alert should be near 1000 for batchSize, 50 destinations or 100 receivers.

Tests

Every new test failed on main first: for example, 500 nested quotes rendered 8,007,000 characters, three 5 MB events were read in one tick, and a test send to 51 destinations was accepted.

The decision record's Guard line lists the tests.

Passing: all 16 alert integration test classes on MySQL and Postgres (584 each) before the final receiver changes; after them, 614 unit tests and the affected integration tests (283) on MySQL.

This PR replaces PR #36258, PR #36261 and PR #36268. The 2.1 backport is PR #36343.

RetriggerView in GreptileConfidence Score: 4/5

The changed preview caches need size caps before merging to satisfy the repository requirement.

Findings

  1. P2 Preview caches have no cap ▶

Summary

This PR caps alert reads, listings, rendering, counts, test sends, HTTP exchanges, and mail queues. It also preserves edits to oversized stored alerts and keeps interrupted ticks eligible for recovery.

  • Alert settings can be saved only within bounded growth.
  • Alert event pages and ticks do bounded work and show when counts are capped.
  • Chat messages stop growing past fixed rendering limits.
  • Test sends and outbound HTTP calls finish within fixed limits.
  • Alert ticks keep their place after interruption, and consumers track work by offsets.
  • Alert and account mail use separate bounded queues.
  • Generated marketplace types are refreshed without changing behavior.

Reviews (11) · Last reviewed commit: "fix(alerts): make the template preview f..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner October 26, 2026 16:26
@manerow manerow added UI UI specific issues safe to test Add this label to run secure Github workflows on PRs backend labels Oct 26, 2026
@manerow
manerow requested a review from a team as a code owner October 26, 2026 16:26
@manerow
manerow requested a review from pmbrull October 26, 2026 16:26
@manerow manerow added UI UI specific issues safe to test Add this label to run secure Github workflows on PRs backend labels Oct 26, 2026
@manerow
manerow requested a review from Rohit0301 October 26, 2026 16:26
@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.

@manerow manerow changed the title fix(alerts): bound the work of alert status, settings, sends and mail fix(alerts): bound the work of each alert request and tick Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ UI Checkstyle passed — lint findings in changed files

🔍 ESLint findings in this PR's files — 0 error(s), 1 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), 1 warning(s) across 1 changed file(s).

Count Rule
1 openmetadata-imports/no-lower-layer-page-imports
All findings
Location Rule Message
🟡 src/utils/Alerts/AlertsUtilPure.ts:41: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

@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 26, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 80%
79.95% (131620/164610) 66.45% (46426/69866) 69.5% (26377/37950)

…atus

# Conflicts:
#	openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/notification/NotificationAlertDetail.tsx
@gitar-bot

gitar-bot Bot commented Oct 28, 2026

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

🔴 High risk · Removing embedded entities from alert event-listing responses changes the public API contract, so clients relying on those fields could break.

Bounds alert reads, listings, chat rendering, pending counts, test sends, HTTP exchanges and mail queues to fixed limits, so one request or tick can no longer exhaust the heap or hold threads indefinitely. Resolved this session: receiver limits now cover user and team names, pending-count requests are queued behind the thread pool, timed-out test sends no longer alter the returned destination, PUT that removes receivers from an over-limit list is accepted, poll errors no longer advance the position past an unread batch, and fixture registry caches are bounded. No issues found.

✅ 7 closed
✅ Quality: New alert limits and lower-bound fields are recorded in no decision record

📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/AlertLimits.java:12-26 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/consumer/ledger/UnprocessedEvents.java:19-29 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/TestSends.java:27-28 📄 openmetadata-service/src/main/java/org/openmetadata/service/util/email/MailQueues.java:17-31
This PR adds a contract other components must follow: countsAreLowerBound in eventsRecord.json and relevantUnprocessedEventsCountIsLowerBound in eventSubscriptionDiagnosticInfo.json, which the UI reads to show 500+. It also sets several limits that were judgment calls: batchSize at most 1000, 50 destinations, 100 receivers per destination, 500 events evaluated per count, 8 test sends at once with a 30 s deadline, a 1 MB response cap, a 2 KB reason cap, and mail queues of 1000 and 500 that fall back to the caller's thread. No record in docs/decisions states these rules. The description's constraints, such as 'A save may not grow an alert past the limits ... An alert already stored past a limit stays editable', exist only in prose, and the repo squash-merges, so that prose never reaches git history. Add a record that states: a save may not grow batchSize past 1000, destinations past 50, or receivers per destination past 100, while an alert already stored past a limit stays editable; pending counts evaluate at most 500 unread events, and the API flags the result as a lower bound when more are unread.

✅ Bug: Pending-count requests can wait without limit behind a 4-thread pool

📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/PendingCounts.java:29-43
PendingCounts runs counts on Executors.newFixedThreadPool(4), whose queue has no size limit, and get() calls join() with no timeout on the HTTP request thread. Only requests with the same key share a count. With many alert pages open for different alerts, or as an alert's offsets move, counts pile up in the queue and each waiting request holds a Jetty thread until the counts ahead of it finish. So the PR limits the work running at once but not the waiting, and a busy alerts page can use up request threads. Fix: wait with a timeout (orTimeout) and return a lower-bound result, or give the executor a bounded queue that rejects with a 429.

✅ Bug: A timed-out test send still changes the destination being returned

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/events/subscription/EventSubscriptionResource.java:1481-1495 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/TestSends.java:59-62
When the deadline passes, timedOutTestSend sets status details on the request's SubscriptionDestination and clears its config. The interrupted send thread is not awaited (shutdownNow). When it fails, sendTestMessageToDestination writes setStatusDetails(reason) and withConfig(null) to the same object, possibly while the response is being serialized. The returned status can then switch between 'Timed out' and the send's own error. Fix: give the send a copy of the destination, or build a new SubscriptionDestination in timedOutTestSend.

✅ Bug: PUT that removes a receiver from a stored over-limit list is refused

📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/StoredReceivers.java:84-89 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/StoredReceivers.java:99-106 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/AlertLimits.java:58-65
The PR says a save may refuse only a value that grows past a bound. A PUT carries no destination ids, and each destination it sends gets a new id. In heldBy, that destination therefore misses keepsItsOwn. heldUnderAnotherId then credits the stored size only when claim(receivers) finds a stored set exactly equal to the one sent. If the PUT also shrinks the list (for example 150 stored receivers become 149), no stored set matches, and byId has no entry for the new id. held becomes 0, so requireNoGrowthPast("receivers", 0, 149, 100) throws. An alert stored past the limit can then only be edited by PUT if it keeps exactly the same receivers, and an admin cannot even trim it toward the limit. The unit and IT tests cover a PUT with the same receivers and a PATCH with one fewer, but not a PUT with one fewer. Suggested fix: when no exact match exists, claim the largest unclaimed stored list that contains every receiver sent, and credit its size. Add a test for a PUT that sends one fewer receiver.

✅ Bug: USERS/TEAMS name lists escape the receiver limit, so sends do unbounded work

📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/StoredReceivers.java:53-62 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/AlertLimits.java:33 📄 openmetadata-service/src/test/java/org/openmetadata/service/alerting/AlertLimitsTest.java:94-108 📄 docs/decisions/2026-10-26-alerting-bounds-the-work-of-each-request-and-tick.md:25 📄 docs/decisions/2026-10-26-alerting-bounds-the-work-of-each-request-and-tick.md:45
After this commit, StoredReceivers.of returns no receivers for any destination whose category is not EXTERNAL or null. That means AlertLimits.requireWithin and requireTestSendWithin no longer limit USERS or TEAMS destinations at all, and the new test checks that 150 names are accepted. These names are still a list the user types in, and each send resolves them one at a time: UserRecipientResolver.byName makes one Entity.getEntityByName DB read per name, for every event, on every tick. So a USERS destination with 100,000 names makes 100,000 lookups per event, which is the per-tick growth driven by input that this PR exists to remove.

It also goes against the Accepted record docs/decisions/2026-10-26-alerting-bounds-the-work-of-each-request-and-tick.md. That record states "Receivers per destination | 100" with no exception for any category, and says "No input can make one request or one tick unbounded". The record is not changed in this PR. The comment "however many people that is" is right that a team's members are not limited. But that is no reason to leave the number of names unlimited, since each name costs its own lookup.

Fix: keep counting the typed names of USERS and TEAMS destinations against the limit (or give them their own name limit). Only the people a team expands to should go uncounted. If exempting these categories is really intended, add a superseding record that states the rule "the receiver limit applies only to addresses typed into EXTERNAL destinations; USERS/TEAMS name lists are unbounded", and give a reason why that per-event lookup cost is acceptable.

...and 2 more closed from earlier reviews

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

@manerow

manerow commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@sonarqubecloud

Copy link
Copy Markdown

@manerow
manerow enabled auto-merge October 28, 2026 13:26
@manerow
manerow added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit 41cd42a Oct 28, 2026
93 of 94 checks passed
@manerow
manerow deleted the fix/alerts-bounded-status branch October 28, 2026 17:14
manerow added a commit that referenced this pull request Oct 28, 2026
…2.1 #36279) (#36343)

* fix(alerts): bound the work of alert status, settings, sends and mail

* fix(alerts): bound the size of chat notifications while they are rendered

* fix(alerts): bound alert event listings and leave the entity out of their rows

* fix(alerts): read change events up to a byte budget, not only a row count

* fix(alerts): address review of the bounded alert work

* Update generated TypeScript types and dereferenced schemas

* fix(alerts): forget a failed pending count before answering it

* fix(alerts): let a destination keep the receivers it stored past the limit

* fix(alerts): count only typed receivers against the receiver limit

* fix(alerts): hold the receivers past the limit for the whole alert, not per destination

* fix(alerts): keep the position when an Error ends a tick while its batch is read

* fix(alerts): answer a template test send too large for its channel as a body error

* fix(alerts): make the template preview fixture registry safe for concurrent requests

* fix(alerts): keep no template preview fixture for a resource that has none

* fix(alerts): bound the diagnostics page of unread events and answer typed errors from alert status routes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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 UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants