Repository navigation
feat(api): evaluate SLO burn alerts and notify - #3798
alex-fedotyev wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Duplicate code analysis1 new clone introduced by this PR.
If one of these duplicates a helper that already exists, import it instead jscpd compared this branch against |
E2E Test Results✅ All tests passed • 478 passed • 1 skipped • 1132s
Tests ran across 4 shards in parallel. |
Adds a built-in evaluator for SLO alerts. Each check runs one query that
counts eligible and good events in 5-minute buckets over the last 6 hours,
from a materialized view when one covers it, and computes both burn rules
from it. Fast burn fires when 2% of the error budget is spent within an
hour, slow burn when 5% is spent within six hours, and each also needs its
last 5 or 30 minutes to burn as fast, so it resolves soon after a burn
stops. Fast burn is checked every 5 minutes, slow burn every 15.
Each alert notifies once when it starts firing (or on the first check after
a silence ends) and once when it resolves. The title and message name the
rule and state the numbers, and link to the SLO page with the bad events of
the window. A title reads like this:
SLO "Checkout" (ServiceName:frontend): slow burn, 17.2% of the 7-day
budget spent in the last 6 hours
A grouped SLO's
alerts fire and resolve for each group with at least 100 events in the
window, and resolve groups the SLO no longer tracks.
Each check also stores its burn numbers on the SLO, so the SLO list shows
the alerts' own verdict. SLO alerts only run while SLOs are enabled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fc822e4 to
8cca8b2
Compare
🦋 Changeset detectedLatest commit: 8cca8b2 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 |
🔴 Tier 4 — CriticalTouches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI. Why this tier:
Review process: Deep review from a domain expert. Synchronous walkthrough may be required. Stats
|
| ? deriveGroupedSloState(overall, groups) | ||
| : deriveSloState(overall), | ||
| }; | ||
| await Slo.updateOne( |
There was a problem hiding this comment.
🟡 P2 — Alert's burn write-back can overwrite a newer refresh snapshot with stale window numbers
CheckAlertTask.execute (tasks/checkAlerts/index.ts:2458) starts refreshDueSloStatuses() at the same time as getAlertTasks(), so each alert holds a copy of slo.status read before the refresh wrote. recordSloAlertBurn then writes {...previous, burn} through $set: { status }. The only guard is updatedAt, which status writes never change (timestamps: false). The result is that a refresh's new window, groups, windowEvaluatedAt, or a just-cleared error gets reverted to the older copy. Fix: guard the update on the snapshot the alert read, e.g. add 'status.windowEvaluatedAt': previous.windowEvaluatedAt and 'status.state': previous.state to the filter. Better still, $set only status.burn, status.evaluatedAt, status.state and the per-group burn/state fields, so the window part is never rewritten.
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
| const { slo, source } = details; | ||
| // A grouped SLO's alert checks the groups its status tracks; until the | ||
| // status refresh has picked them, there is nothing to check. | ||
| if (getSloGroupBy(slo) != null && !slo.status?.groups?.length) return; |
There was a problem hiding this comment.
🔴 P1 — Firing groups never resolve once a grouped SLO's status has zero groups
The early return treats 'refresh has not run yet' and 'refresh ran and found no groups' as the same case. computeSloWindow (controllers/sloStatusQueries.ts:118) stores groups = [] when the window has no eligible events, for example after a service stops sending data or an edit to the eligible filter matches nothing. From then on the evaluator returns before resolveUnchecked, so groups that were ALERT stay ALERT and never send a resolve. Fix: return early only when slo.status?.windowEvaluatedAt == null, and let an empty tracked list fall through so resolveUnchecked resolves the old groups. Add a test that starts with status.groups = [] and a previously alerting group.
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
| ...(groups != null ? { groups } : {}), | ||
| // A failing window query keeps its error until the refresh clears it. | ||
| state: | ||
| previous.state === 'error' |
There was a problem hiding this comment.
🟡 P2 — Error state outlives a successful burn check because the alert keeps evaluatedAt fresh
An ungrouped SLO's fast burn alert sets evaluatedAt to now every 5 minutes, but keeps state: 'error' when it is already error. The refresh only reruns when evaluatedAt is 5 minutes old or the window is 30 minutes old (SLO_WINDOW_MAX_AGE_MS). So a passing burn error keeps the SLO showing 'error' for up to 30 minutes, even though each alert check's burn query against the same source succeeds. Fix: when the burn numbers are fresh, re-derive the state, or clear the error if it came from the burn query, or skip updating evaluatedAt while state is 'error' so the refresh stays due.
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
| const config = | ||
| isBuilderChartConfig(ctx.chartConfig) && | ||
| mvSource?.materializedViews?.length | ||
| ? await tryOptimizeConfigWithMaterializedView( |
There was a problem hiding this comment.
🟡 P2 — Materialized-view optimization runs twice per SLO alert check
processAlert already calls tryOptimizeConfigWithMaterializedView on this same config (tasks/checkAlerts/index.ts:1311-1320) before handing it to the evaluator, and drops the result. queryBurnRows repeats the call, which repeats the metadata queries. The SLO evaluator does not change the date range or granularity, so the first result is valid. Fix: add optimizedChartConfig to AlertEvaluationContext and use it here, or skip the up-front optimization when an evaluator is present.
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
| * unoptimized. A failure is recorded as a query error or timeout, as for | ||
| * threshold alerts, and returns null. | ||
| */ | ||
| async function queryBurnRows(ctx: AlertEvaluationContext, source: ISource) { |
There was a problem hiding this comment.
🟡 P2 — SLO alert queries are not counted in the alerts.query operation outcome
The threshold path calls recordOperationOutcome({ operation: 'alerts.query', ... }) on success and on failure (tasks/checkAlerts/index.ts:1613-1628). queryBurnRows records only queryDurationMs, so failing or slow SLO burn queries never show up in the alert-query SLI. Fix: call recordOperationOutcome in the try and catch blocks of queryBurnRows, with alert_source: 'slo'.
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
| * longer tracks, or the whole SLO's state once it is grouped (and each | ||
| * group's once it is not). | ||
| */ | ||
| async function resolveUnchecked( |
There was a problem hiding this comment.
🟡 P2 — Ungrouping an SLO resolves at most one of its firing groups
The doc comment says resolveUnchecked resolves 'each group's [state] once it is not [grouped]'. But for a non-grouped alert, loadAlerts (providers/default.ts:532-540) seeds previousMap from the single latest history row, without groupValues. Only that one group can be resolved, and its resolve message has no attributes. Every other group that was ALERT is never resolved. Fix: when getSloGroupBy(slo) is null, also fetch the latest per-group rows. Alternatively, correct the comment and document this limitation.
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
| logger.error({ message: 'SLO not found for SLO alert', alertId: alert.id }); | ||
| return []; | ||
| } | ||
| const source = await Source.findOne({ |
There was a problem hiding this comment.
🟡 P2 — Third copy of the source + connection populate-and-check block
getSloAlertDetails repeats the Source.findOne(...).populate<Omit<ISource,'connection'> & { connection: IConnection }>({ path: 'connection', match: { team }, select: '+password' }) lookup, the missing-connection check and the { ...source.toObject(), connection: connection.id } reshaping. The same code is at default.ts:227 and default.ts:322. Fix: move it into one helper, e.g. findSourceWithConnection(sourceId, team), and call it from all three.
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
PR Review
8 finding(s): 🔴 1 P0/P1 · 🟡 6 P2 · 🔵 1 P3 7 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 Review✅ No critical issues found. The core evaluator logic — bucket summation, fast/slow thresholds, notify-once via 🟡 P2 — recommended
🔵 P3 nitpicks (10)
Reviewers (11): correctness, adversarial, reliability, performance, kieran-typescript, testing, maintainability, project-standards, api-contract, agent-native, learnings-researcher. 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 |
Summary
Adds a built-in evaluator for SLO alerts. Each check runs one query that
counts eligible and good events in 5-minute buckets over the last 6 hours,
from a materialized view when one covers it, and computes both burn rules
from it. Fast burn fires when 2% of the error budget is spent within an
hour, slow burn when 5% is spent within six hours, and each also needs its
last 5 or 30 minutes to burn as fast, so it resolves soon after a burn
stops. Fast burn is checked every 5 minutes, slow burn every 15.
Each alert notifies once when it starts firing (or on the first check after
a silence ends) and once when it resolves. The title and message name the
rule and state the numbers, and link to the SLO page with the bad events of
the window. A title reads like this:
A grouped SLO's
alerts fire and resolve for each group with at least 100 events in the
window, and resolve groups the SLO no longer tracks.
Each check also stores its burn numbers on the SLO, so the SLO list shows
the alerts' own verdict. SLO alerts only run while SLOs are enabled.
Stack
Part 11 of 27 PRs in a GitHub stack (stack #3815). The header says this PR merges into the branch below it, but the stack's base is
main: merging a PR lands it and every PR below it onmain, one squashed commit each. Each diff is only its own change, and CI runs as if each PR targetsmain.Parts 1 to 6 are shared code, 7 to 13 the API and its MCP tools, and 14 to 27 the app. Everything ships behind
ENABLE_SLOS(API) andNEXT_PUBLIC_ENABLE_SLOS(app), both off by default.Rules
The thresholds are fixed for now; making them editable is one of the follow-ups listed on the ticket.
How to reproduce
Starting point: a checkout of this branch with Docker (
make dev-intstarts ClickHouse and Mongo for the integration tests).On
main: nothing to compare; this is new code.On this branch:
cd packages/api && npx jest src/tasks/checkAlerts/__tests__/sloEvaluator.test.ts: each alert fires on its own rule, notifies once per episode (and on the first check after a silence ends), resolves when the short window stops burning, alerts per group, and resolves groups the SLO stops tracking.make dev-int FILE=renderAlertTemplate: titles and messages per rule and per group, and links to the SLO page with the window's bad events.yarn dev: give an SLO on a source with errors a fast burn alert to a webhook (webhook.site works). The webhook gets one message when the burn starts and one when it resolves, not one every 5 minutes.Test plan
tasks/checkAlerts/__tests__/sloEvaluator.test.tsrenderAlertTemplate.int.test.ts, the check-alerts suites,slos.int.test.ts(write-back)How to test on Vercel preview
N/A, non-UI change.
References
[as-cast: allow] The cast check matches the word "as" in comments and strings here; the diff has no
ascasts.