Repository navigation
feat(alerts): add an opt-in re-notify interval for firing alerts - #3863
Conversation
An alert can set renotifyIntervalMinutes: while it keeps firing, it notifies at most once every that many minutes. Unset keeps notifying on every evaluation. Each history record carries lastNotifiedAt forward, so the check in trySendNotification only reads the previous evaluation. Closes ClickHouse#2464 Co-authored-by: Niladri Adhikary <niladrix719@gmail.com>
|
@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: 481b2ba The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 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): 🔴 0 P0/P1 · 🟡 1 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. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit ba6f7de. Configure here.
Deep Review✅ No critical issues found. This is a tightly-scoped, well-tested opt-in feature. The prior Cursor Bugbot "silence resets the interval" concern is verifiably fixed (carry-forward runs before the silence early-return, asserted by a dedicated test), the field is wired consistently across common-utils → model → both OpenAPI specs → internal/external routers → MCP, and agent-native parity holds (the MCP tool and external API can set, read, and clear the value with the same semantics and guidance as the UI). The two P2 items below are the same underlying behavior — worth a decision, not a merge blocker. 🟡 P2 -- recommended
🔵 P3 nitpicks (2)
Reviewers (12): correctness, testing, maintainability, project-standards, agent-native, learnings-researcher, api-contract, reliability, security, adversarial, previous-comments, kieran-typescript. 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 |
Ungrouped alerts and stale grouped alerts get their previous state from getLatestAlertHistories and the last-evaluation fallback, not from getPreviousAlertHistories, so the re-notify interval never applied to them. Also tests a grouped alert's per-group interval and the MCP save rules, and documents the new false return for evaluators.
|
Round 1, fixed in 29fc30b:
No change for these:
|
A silenced evaluation returned before the re-notify check and wrote no lastNotifiedAt, so a silence shorter than the interval made the alert notify again as soon as it ended. The time is now carried forward first. The MCP schema reuses alertRenotifyIntervalMinutesSchema.
| state === AlertState.ALERT ? alert.renotifyIntervalMinutes : undefined; | ||
| if (renotifyMinutes) { | ||
| const previous = previousMap.get(computeHistoryMapKey(alert.id, group)); | ||
| getOrCreateHistory(group).lastNotifiedAt = |
There was a problem hiding this comment.
🟡 P2 — lastNotifiedAt is lost when a still-breaching evaluation lands in PENDING, so the next ALERT notifies before the interval ends
Carry lastNotifiedAt forward wherever fired is carried for PENDING (the history.fired = previous?.fired === true branches at ~1687, ~1765, ~1825), and accept previous.state === PENDING && previous.fired in the check here. Today trySendNotification only runs for ALERT, and only reads the value back when previous.state === ALERT. With numConsecutiveWindows > 1, an evaluation that comes after a runner delay longer than (M-1) windows finds fewer than M-1 rows in getRecentAlertHistories. That row is written as PENDING without lastNotifiedAt, so the next ALERT evaluation notifies straight away even when, say, a 24h interval has not passed.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Leaving this one. It needs numConsecutiveWindows > 1 and a runner delay longer than the windows it counts, and the effect is one early repeat after that delay. Covering it means carrying the time through the PENDING branches too, which I'd rather do in a follow-up if wanted.
|
Rounds 2 and 3. Fixed in c563d7c:
No change for these:
From here I'll only fix P0/P1 bot findings. |
| control={control} | ||
| name={renotifyIntervalName} | ||
| render={({ field }) => ( | ||
| <NumberInput |
There was a problem hiding this comment.
Could we show a warning or error here if the renotifyInterval is less than the alert interval, to make it clear that the alert will not renotify every eg. 1 minute if the alert is only evaluated every 5 minutes?
If the various MCP/API/Tooltip descriptions could indicate this where a warning can't, that would also be good.
There was a problem hiding this comment.
Done in 8fa9bd0. The field now shows a warning when the value is below the alert interval, for example "This alert is evaluated every 5 minutes, so it can't re-notify more often than that." The tooltip, MCP and external API descriptions now say that a value below the alert interval has no effect.
I made it a warning rather than an error because a shorter value is harmless: it behaves the same as leaving the field blank. Happy to make it a validation error if you'd prefer.
pulpdrew
left a comment
There was a problem hiding this comment.
LGTM, with one ask for validation/warning on renotif interval < alert interval
…erval The alert only notifies when it is evaluated, so a shorter re-notify interval has no effect. Show a warning under the field and say so in the tooltip, MCP and external API descriptions.
| {renotifyIntervalName && | ||
| renotifyIntervalMinutes != null && | ||
| alertIntervalMinutes != null && | ||
| renotifyIntervalMinutes < alertIntervalMinutes && ( |
There was a problem hiding this comment.
🟡 P2 — Warning only covers values below the interval; values that aren't a multiple of it are silently rounded up
trySendNotification (packages/api/src/tasks/checkAlerts/index.ts:1390-1398) only runs on window-aligned evaluations. So on a 15m alert, a 20-minute interval actually re-notifies every 30 minutes, with no warning. Either extend the warning to renotifyIntervalMinutes % alertIntervalMinutes !== 0 and state the effective interval (Math.ceil(r / i) * i), or step the NumberInput by the alert interval.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| if (renotifyMinutes) { | ||
| const previous = previousMap.get(computeHistoryMapKey(alert.id, group)); | ||
| getOrCreateHistory(group).lastNotifiedAt = | ||
| previous?.state === AlertState.ALERT |
There was a problem hiding this comment.
🟡 P2 — lastNotifiedAt is dropped whenever a firing incident passes through a PENDING row, so the next ALERT notifies inside the interval
The carry-forward only runs when trySendNotification(ALERT) is called and the previous row is ALERT. PENDING rows (index.ts:1685, 1763, 1823) never get lastNotifiedAt. A firing alert can drop to PENDING: with numConsecutiveWindows > 1, getConsecutiveWindowHistories (index.ts:2283) skips ERROR rows, so a single failed query mid-incident leaves too few lookback rows. That gives ALERT → PENDING (fired=true carried) → ALERT, and the new ALERT sees a PENDING previous row, clears lastNotifiedAt, and re-notifies at once. Fix: copy previous.lastNotifiedAt onto PENDING rows when fired is carried forward, and on the ALERT path accept a previous row whose state is ALERT or PENDING with fired === true. Add a checkAlerts test with numConsecutiveWindows + renotifyIntervalMinutes that crosses a PENDING row.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Closes #2464. Builds on #2754 by @niladrix719, which has been idle since July and now conflicts with main.
What
An alert can set
renotifyIntervalMinutes. While it keeps firing, it notifies at most once every that many minutes. A new breach after a resolve notifies at once, and resolve notifications are unchanged.It is opt-in: unset keeps today's behaviour of notifying on every evaluation. This is the difference from #2754, which changed the default to "notify once". The setting is in the UI under the alert's advanced schedule settings, in the internal and external APIs, and in
clickstack_save_alert. As with the note and the window count, an MCP update that omits it keeps the stored value.How
Each alert history record stores
lastNotifiedAt. A suppressed evaluation copies it forward, so the check only needs the previous evaluation's record, whichgetPreviousAlertHistoriesalready returns. The check is intrySendNotification, so threshold, grouped and evaluator alerts all go through it, and each group of a grouped alert keeps its own time.Two things work the same way as today's
firedflag and resolve notification:Tests
checkAlerts.int.test.ts: unset notifies on every evaluation; a 10 minute interval with 5 minute windows notifies, skips, notifies, skips, withlastNotifiedAtcarried forward; a new breach after a resolve notifies inside the interval.Note
Medium Risk
Changes firing notification cadence in the alert evaluation pipeline (opt-in), which can affect paging noise if misconfigured; resolve paths and default behavior stay the same.
Overview
Alerts gain an opt-in
renotifyIntervalMinutessetting end-to-end (shared Zod schema, Mongo model, internal/external OpenAPI, MCPclickstack_save_alert, and alert modals). When set, sustained ALERT state still evaluates every window but webhook repeats are capped to at most once per N minutes; null/unset preserves today’s notify-on-every-evaluation behavior, and resolve notifications are unchanged.The checker persists
lastNotifiedAton alert history (per group for grouped alerts), copies it from the previous firing row when still in ALERT, andtrySendNotificationskips dispatch inside the interval (with askipped_renotifymetric). A new breach after OK still notifies immediately, and the UI adds the control under advanced schedule settings with a warning when N is shorter than the evaluation interval.Reviewed by Cursor Bugbot for commit 481b2ba. Bugbot is set up for automated code reviews on this repo. Configure here.