Skip to content

fix(alerts): bound the pending count on the alert page (2.0) - #38094

Merged
manerow merged 1 commit into
2.0from
fix-alert-pending-count-2.0
Nov 18, 2026
Merged

manerow merged 1 commit into
2.0from
fix-alert-pending-count-2.0

Conversation

@manerow

@manerow manerow commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Opening an alert's page could run the server out of memory. Its "pending" count (eventsRecord) loaded every change event on the platform after the alert's position in one query, then checked each against the alert's rules.

Every change event carries the full JSON of the entity that changed. An alert created from the UI reads at most 10 events every 10 seconds, so during heavy ingestion its backlog keeps growing. On a 2.0.8 server with a 1 GB heap, one page view with about 3,300 unread table events (622 MB) failed with OutOfMemoryError, and other threads failed with it.

Why it happened

The count was added with the alert details page redesign in PR #18448 (1.6). It was exact, but nothing bounded how many events it read. Main and 2.1 fixed this in PR #36279 (2.1 backport PR #36343), on top of the alerting redesign. 2.0 does not have that redesign, so this PR brings only the same bound, written for 2.0's code.

What this PR changes

  • The pending count reads at most the first 500 unread events, in offset order. It also stops once their JSON passes 8 MB, but always reads at least one event. It reads the sizes first and loads only the events that fit.
  • Events written after the request started are not counted, so a count that stops at them is still exact.
  • eventsRecord gets an optional countsAreLowerBound field. It is true when unread events remain past what was read.
  • When it is true, the alert page shows the total and pending counts as "500+" (or "N+"). Failed counts stay exact.
  • The unbounded DAO method is deleted.

The limits and the field name match main and 2.1. The decision record explains them.

What users will notice

  • Normal alerts: nothing changes.
  • Alerts with a large backlog: the counts show "500+" (or fewer with very large events) instead of risking a crash.

How it was tested

  • New unit tests for the count (exact, capped, cut by the byte budget, events written after the request) and for the byte budget.
  • New AlertPendingCountIT: 600 unread events show 500 with countsAreLowerBound, four 3 MB events stop at the 8 MB budget, and a small backlog stays exact.
  • New UI tests for the "+" in the alert header.

Results on this branch:

Check Result
Unit tests: EventSubscriptionPendingCountTest, ChangeEventReadBudgetTest, EventSubscriptionSchedulerTest, AlertUtilTest 65 passed
AlertPendingCountIT, MySQL + Elasticsearch 3 passed
AlertPendingCountIT, Postgres + OpenSearch 3 passed
AlertsUtil.test.tsx, AlertsUtilPure.test.ts 121 passed
ESLint and Prettier on the changed UI files clean

End to end, on the 2.0.8 image with a 1 GB heap and the same 622 MB backlog: before, eventsRecord answered 500 Java heap space. With this patch it answers 200 in 0.2 s, the heap does not grow, and the response sets countsAreLowerBound.

Not in this PR

Main also bounds the consumer's tick read, batchSize, the event listings and diagnosticInfo's limit, and limits how many counts run at once. None of these caused this crash, so they stay as they are on 2.0.

RetriggerView in GreptileConfidence Score: 4/5

The behavior looks safe, but the repository's Java convention must be satisfied before merging.

Findings

  1. P2 New locals omit `final` ▶

Summary

The alert page now counts a bounded prefix of unread events and marks incomplete totals with “+”.

  • Alert pages count a bounded slice of unread events.
  • Alert pages mark capped counts with a plus.

One repository-required Java convention needs attention before merging.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Alert page] --> B[Read alert position and latest offset]
  B --> C[Read sizes of up to 500 events]
  C --> D[Choose prefix within 8 MB]
  D --> E[Load chosen events and apply alert rules]
  E --> F[Return count and lower-bound flag]
  F --> G[Show total and pending with + when incomplete]
Loading

Reviews (1) · Last reviewed commit: "fix(alerts): bound the pending count on ..." · Reviewed by Greptile

@manerow
manerow requested review from a team as code owners November 18, 2026 08:00
@manerow
manerow requested review from mohityadav766 and removed request for a team November 18, 2026 08:00
@manerow manerow added backend skip-pr-checks Bypass PR metadata validation check labels Nov 18, 2026
@manerow
manerow requested review from chirag-madlani and removed request for a team November 18, 2026 08:00
@gitar-bot

gitar-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Bounding alert-page event reads to 500/8 MB could reduce heap-exhaustion risk, while large backlogs now display lower-bound rather than exact counts.

Bounds the alert pending count to the first 500 unread change events (or 8 MB of event JSON, reading at least one), preventing OutOfMemoryError on alert pages with large backlogs. Counts are shown as "500+" when more events remain; the unbounded DAO method is removed. No issues found.

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

Comment on lines +392 to +395
Optional<EventSubscriptionOffset> storedOffset = getEventSubscriptionOffset(subscriptionId);
ChangeEventDAO changeEventDAO = Entity.getCollectionDAO().changeEventDAO();
long latestOffset = changeEventDAO.getLatestOffset();
long offset = storedOffset.map(EventSubscriptionOffset::getCurrentOffset).orElse(latestOffset);

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 New locals omit final. The Java guide requires final on local variables and parameters that do not change. The new storedOffset, changeEventDAO, latestOffset, and offset values are never reassigned but omit it. Apply final here and to unchanged values in the new DAO helpers and tests.

Context Used: CLAUDE.md (source)

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!

@manerow
manerow merged commit 8c547b7 into 2.0 Nov 18, 2026
79 of 85 checks passed
@manerow
manerow deleted the fix-alert-pending-count-2.0 branch November 18, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant