Repository navigation
fix(alerts): bound the pending count on the alert page (2.0) - #38094
Conversation
Code Review ✅ Approved 🟡 Medium riskBounding 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. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
| Optional<EventSubscriptionOffset> storedOffset = getEventSubscriptionOffset(subscriptionId); | ||
| ChangeEventDAO changeEventDAO = Entity.getCollectionDAO().changeEventDAO(); | ||
| long latestOffset = changeEventDAO.getLatestOffset(); | ||
| long offset = storedOffset.map(EventSubscriptionOffset::getCurrentOffset).orElse(latestOffset); |
There was a problem hiding this comment.
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!
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
eventsRecordgets an optionalcountsAreLowerBoundfield. It is true when unread events remain past what was read.The limits and the field name match main and 2.1. The decision record explains them.
What users will notice
How it was tested
AlertPendingCountIT: 600 unread events show 500 withcountsAreLowerBound, four 3 MB events stop at the 8 MB budget, and a small backlog stays exact.Results on this branch:
EventSubscriptionPendingCountTest,ChangeEventReadBudgetTest,EventSubscriptionSchedulerTest,AlertUtilTestAlertPendingCountIT, MySQL + ElasticsearchAlertPendingCountIT, Postgres + OpenSearchAlertsUtil.test.tsx,AlertsUtilPure.test.tsEnd to end, on the 2.0.8 image with a 1 GB heap and the same 622 MB backlog: before,
eventsRecordanswered 500Java heap space. With this patch it answers 200 in 0.2 s, the heap does not grow, and the response setscountsAreLowerBound.Not in this PR
Main also bounds the consumer's tick read,
batchSize, the event listings anddiagnosticInfo'slimit, and limits how many counts run at once. None of these caused this crash, so they stay as they are on 2.0.The behavior looks safe, but the repository's Java convention must be satisfied before merging.
Findings
Summary
The alert page now counts a bounded prefix of unread events and marks incomplete totals with “+”.
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]Reviews (1) · Last reviewed commit: "fix(alerts): bound the pending count on ..." · Reviewed by Greptile