Skip to content

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

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

manerow merged 17 commits into
2.1from
fix/alerts-bounded-status-2.1

Conversation

@manerow

@manerow manerow commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Backport of PR #36279 to the 2.1 release branch. The branch was cut from main with no other changes, so the commits apply unchanged.

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.

RetriggerView in GreptileConfidence Score: 3/5

The PR should not merge until diagnostic reads are bounded, count overload preserves 429 responses, and preview caches meet the required size cap.

Findings

  1. P1 Diagnostics still loads huge events ▶
  2. P1 Count overload returns 500 ▶
  3. P2 Preview caches have no cap ▶

Summary

This backport adds fixed limits to alert reads, counts, rendering, test sends, HTTP exchanges, and mail queues.

Since the previous review:

  • Alert settings stop growing past limits while oversized saved alerts stay editable.
  • Alert event listings stop at 1,000 rows and leave out embedded entities.
  • Change-event readers cap each batch and keep alert ticks moving through the backlog.
  • Alert pages show capped pending counts as lower bounds instead of counting every unread event.
  • Chat messages stop rendering when their size or structure passes fixed limits.
  • Test sends finish within 30 seconds and run several destinations together.
  • Outbound HTTP calls now have a total deadline and a 1 MB response limit.
  • Alert and account mail use separate bounded queues.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Request[Alert request] --> Limits[Check configured limits]
  Limits --> Counts[Bounded pending count]
  Limits --> Sends[Concurrent test sends]
  Sends --> Render[Chat render budget]
  Render --> HTTP[HTTP deadline and response cap]
  Tick[Alert tick] --> Read[Row and byte bounded read]
  Read --> Deliver[Evaluate and deliver]
  Deliver --> Commit[Save progress and outcomes]
Loading

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

@manerow
manerow requested review from a team as code owners October 27, 2026 11:58
@manerow manerow added UI UI specific issues safe to test Add this label to run secure Github workflows on PRs labels Oct 27, 2026
@manerow
manerow removed the request for review from a team October 27, 2026 11:58
@manerow
manerow requested review from TeddyCr and shrabantipaul-collate and removed request for a team October 27, 2026 11:58
@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 77 to 80
.withRelevantUnprocessedEventsList(
listCountOnly ? null : relevantUnread(progress, limit, paginationOffset))
.withTotalUnprocessedEventsList(
listCountOnly ? null : progress.allUnread(limit, paginationOffset));

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.

P1 Diagnostics still loads huge events

diagnosticInfo still loads and returns each unread event's full entity. Both lists use listUnprocessedEvents, which has neither the new byte budget nor entity removal. A request with limit=1000 over 5 MB events can therefore load gigabytes twice, despite this PR's listing bounds.

Use a byte-bounded read for rule evaluation, then remove entity before returning either list. Extend the no-entity test to both diagnostics routes.

Comment on lines +78 to +82
} catch (RejectedExecutionException e) {
throw new WebApplicationException(
"Too many alert counts are running; try again shortly",
e,
Response.Status.TOO_MANY_REQUESTS);

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.

P1 Count overload returns 500

When the count workers and queue are full, PendingCounts throws a 429. All four eventsRecord and diagnosticInfo routes catch it as Exception and return 500 instead. API clients never receive the new response telling them to try later.

Preserve WebApplicationException before the generic catch in these routes.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 80%
80.12% (132322/165150) 66.69% (46867/70266) 69.75% (26570/38092)

Comment on lines +68 to +69
private final Map<String, EntityFixtureBuilder> builders = new ConcurrentHashMap<>();
private final Map<Scenario, EntityFixtureEventApplier> appliers = new ConcurrentHashMap<>();

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 Preview caches have no cap

builders and appliers still have no size cap after the switch to ConcurrentHashMap. Both retain entries through computeIfAbsent, including entries for arbitrary resource names. This violates the repository directive that all caches must have an explicit size cap.

Use bounded caches, such as Caffeine with maximumSize, while keeping concurrent access safe. This repository requirement must be satisfied before merging.

Context Used: CLAUDE.md (source)

@gitar-bot

gitar-bot Bot commented Oct 28, 2026

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

🔴 High risk · Removing embedded entity data from alert event listings could break API clients that depend on those response fields.

Bounds alert request and tick work with fixed limits on batch size, destinations, receivers, event reads, pending counts, test sends, HTTP exchanges, chat rendering, and mail queues, addressing the unbounded template preview fixture cache. No open issues remain.

✅ 1 closed
✅ Bug: Fixture registry caches grow without bound on user-chosen resource names

📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/preview/MockChangeEventRegistry.java:67-69 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/preview/MockChangeEventRegistry.java:85-88 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/preview/MockChangeEventRegistry.java:99-113 📄 openmetadata-service/src/test/java/org/openmetadata/service/alerting/content/preview/MockChangeEventRegistryTest.java:19 📄 openmetadata-service/src/test/java/org/openmetadata/service/alerting/content/preview/MockChangeEventRegistryTest.java:51-55
builders and appliers in MockChangeEventRegistry are keyed by renderRequest.getResource(). Per notificationTemplateRenderRequest.json, that is any string of 1–128 characters, and MockChangeEventFactory.create passes it through after only trim(). Every distinct name a caller of /render or /send sends adds a permanent entry to both maps. The new test shows this: 20,000 made-up names all get cached. That breaks the repo rule that every cache must be bounded, and it goes against this PR's goal of bounding the work of each request. Caching also buys nothing here. The stored values are lambdas that call fixtures.loadBaseFixture / loadScenarioFixture again each time they run, so building them per call costs about the same as looking them up.

Fix: drop both maps and build the lambda on each call. If you want to keep a cache, cap it with Caffeine maximumSize(...). The new test then needs to be reworked so it no longer depends on 20,000 cached entries.

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 merged commit 133c0f2 into 2.1 Oct 28, 2026
59 of 62 checks passed
@manerow
manerow deleted the fix/alerts-bounded-status-2.1 branch October 28, 2026 17:29
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

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