Repository navigation
Conversation
|
@bcanvural is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 65b2c7e The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
PR Review
2 finding(s): 🔴 1 P0/P1 · 🟡 0 P2 · 🔵 1 P3 1 posted as inline comment(s) on the changed lines. 1 P3 folded at the bottom. 🔵 1 P3 — no action needed before merge
Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep ReviewThe optimization is well-reasoned: performance confirmed the equality read hits the existing 🔴 P0/P1 — must fix
🟡 P2 — recommended
🔵 P3 nitpicks (3)
Reviewers (8): correctness, adversarial, performance, reliability, testing, maintainability, kieran-typescript, previous-comments. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
|
On the deep review:
|
|
On the deep review, round 2:
|
| // the lookback. A registered evaluator does not run that loop, and an | ||
| // evaluator lookup or threshold check that throws is left for processAlert | ||
| // to report, so these keep the scan. | ||
| const needsLookbackScan = (alert: IAlert) => { |
There was a problem hiding this comment.
🔴 P1 — needsLookbackScan checks the alert's current threshold, but the invariant it relies on was built under the old threshold or evaluator. Editing an alert can leave ALERT groups that never resolve
The shortcut assumes every ALERT/PENDING group has a row in the last evaluation. That only holds if earlier evaluations ran the missing-group loop, i.e. if 0 did not breach the threshold back then and no evaluator handled the alert. Example: an alert with BELOW 1 has group G in ALERT, and G stops reporting. The missing-group loop is skipped because 0 breaches, so G gets no new rows. The user then edits the threshold to ABOVE 100. Alert updates in controllers/alerts.ts do not clear AlertHistory. Now needsLookbackScan is false, the last-evaluation read finds no row for G, and G drops out of previousMap. So the missing-group loop at index.ts:1819-1842 never writes its OK row and no resolve notification is ever sent. Before this PR, the scan found G's ALERT row and resolved it. The same happens when an evaluator stops applying to an alert, since evaluators also skip that loop. Fix: also take the scan path when the alert changed after its last evaluation's createdAt (alert.updatedAt > latest.createdAt, or a stored hash of threshold, thresholdType and evaluator). Add a test that flips the threshold from 0-breaching to non-breaching while a silent group is in ALERT.
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
There was a problem hiding this comment.
This is the same issue as the two threads above. Checking alert.updatedAt doesn't work here: every alert check updates updatedAt, so it is always newer than the last evaluation. Changing that would also change what the UI and the API show. I'm leaving this for a maintainer to decide.
|
@wrn14897 the bots have done two review rounds. One point is still open (raised in three threads):
Fixing this needs extra information that we don't store today: either a mark on the alert when it's edited, or the alert settings saved with each check. Both mean changes outside this PR's file. Should I handle it here, or is this edge case acceptable? |
|
@wrn14897 a reminder about my question above (#3728 (comment)). The PR still merges cleanly. I suggest we accept the edge case. It only happens in a rare mix: a threshold that 0 breaches, a group that went quiet, and a later edit to the threshold. If you want it fixed, I can do that in a follow-up PR. |
|
@karl-power would you have time to review this, or know who could? It has been waiting for an alerts review since 19-Nov and still merges cleanly. The one open question is in the comment above; I suggest accepting that edge case and fixing it in a follow-up PR if wanted. |
|
@pulpdrew a gentle nudge on this one when you have time. It's the follow-up to #3702: for grouped alerts that a value of 0 doesn't breach, each check reads only the last evaluation instead of every history row in the lookback (about 1.9M rows per check for a 1m alert with ~1,300 groups). It still merges cleanly. |
…lue of 0 does not breach Every group whose last row is ALERT or PENDING has a row in the last evaluation, because processAlert writes an OK row for each such group missing from the data. Previous OK rows only matter for their createdAt. So these alerts read one row per group instead of every row in the lookback. Refs ClickHouse#3508
…hat cannot be checked
…heck in the history gate
57a355f to
65b2c7e
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| // the lookback. A registered evaluator does not run that loop, and an | ||
| // evaluator lookup or threshold check that throws is left for processAlert | ||
| // to report, so these keep the scan. | ||
| const needsLookbackScan = (alert: IAlert) => { |
There was a problem hiding this comment.
🔴 P1 — Groups stay in ALERT for good when the threshold is edited so that 0 stops breaching
The new path relies on the missing-group loop having run in earlier evaluations, but that loop only runs when !doesExceedThreshold(alert, 0) (index.ts:1850). updateAlert (controllers/alerts.ts:377) keeps the history when the threshold changes. Example: a grouped BELOW 1 alert has group x in ALERT. x stops reporting, so the loop writes nothing for it and its ALERT row ages out of the last evaluation. The user then changes the alert to ABOVE 100. From then on needsLookbackScan is false, so only the last evaluation is read. x never enters previousMap, never gets an OK row and never sends a resolve notification. The old scan would have found it and resolved it. The same gap appears when an evaluator stops applying to an alert. Fix: fall back to the scan for the first evaluation after a threshold or evaluator change. For example, compare alert.updatedAt with latest.createdAt, or store the 0-breaches flag on the history row and scan when it differs. Add an integration test for an edit from BELOW to ABOVE.
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
Summary
Follow-up to #3702, for the part of #3508 it leaves. After #3702, a due grouped alert scans every history row in its lookback, at least 1 day. For a 1m alert with ~1,300 groups that is ~1.9M rows on every check.
When a value of 0 does not breach the alert's threshold, that scan reads more than the evaluation uses:
processAlertwrites an OK row for every group that was ALERT or PENDING and is missing from the data (the missing-group loop). So every group whose latest row is ALERT or PENDING has a row in the alert's last evaluation.createdAt(window start and skip check). Itsstateandfiredchange nothing, and the last evaluation has the latestcreatedAt.This PR:
getPreviousAlertHistories. The others go to the read perf(api): bound check-alerts history lookup by alert interval #3702 added for catch-up: the rows of the last evaluation ({alert, createdAt: <last>}), one per group;No new index and no
DISTINCT_SCAN: the read is an equality match on{alert: 1, createdAt: -1}, so it should behave the same on DocumentDB.Known difference: if a partial write left out some rows of the last evaluation, those groups lose their previous state. The scan would have found older rows for them.
Numbers (MongoDB 5.0, one day of history for a 1m alert with 1,300 groups, 1.87M rows,
findwith the provider's filter and projection):How to reproduce
Starting point:
make dev-int.On
main:packages/api/src/tasks/checkAlerts/providers/__tests__/default.int.test.ts.make dev-int FILE="providers/default.int.test --testNamePattern=value.of.0":reads only the last evaluation…fails, because the scan returns the staleoldgroup and runs a secondfind.On this branch:
make dev-int FILE=checkAlertspasses (361 tests).How to test on Vercel preview
N/A — non-UI change.
References
getPreviousAlertHistoriesreads every history row of the last 7 days, so check-alerts slows down and runs out of memory as history grows #3508 (closed with perf(api): bound check-alerts history lookup by alert interval #3702; this is the remaining scan cost it reports)DISTINCT_SCANapproach does not help on DocumentDBNote
Medium Risk
Changes alert evaluation state seeding for high-volume grouped alerts; optimized path can drop stale group state if the last evaluation write was partial, while exceptions still use the full scan.
Overview
Perf improvement for grouped alert history loading: due grouped alerts that use the standard threshold path and where 0 does not breach no longer run the full lookback
getPreviousAlertHistoriesscan. They rely on the existing last-evaluation fetch (AlertHistory.findon the latest row’screatedAt), one document per group.The default alert provider adds
needsLookbackScan, which keeps the lookback when a custom evaluator applies, whendoesExceedThreshold(alert, 0)is true (e.g. BELOW thresholds where zero breaches), when the threshold cannot be checked, or when evaluator/threshold checks throw (safe fallback). Other grouped alerts still get last-evaluation rows for catch-up when the scan returns nothing.Integration tests cover the single last-evaluation query, preserved lookback for the exception cases, and
clearAlertEvaluatorsin teardown. Trade-off: groups missing from a partial last evaluation may lose prior state that the old scan would have recovered.Reviewed by Cursor Bugbot for commit 65b2c7e. Bugbot is set up for automated code reviews on this repo. Configure here.