Repository navigation
feat(api): refresh SLO statuses in the check-alerts task - #3795
alex-fedotyev wants to merge 2 commits into
Conversation
Each SLO stores a status snapshot so lists read it without querying. The check-alerts task refreshes the snapshots beside the alert evaluation: burn rates every 5 minutes from a 6-hour query in 5-minute buckets, and the SLI and error budget every 30 minutes, since that query reads the whole 7 or 30 day window. A grouped SLO also stores the numbers of its 100 busiest groups and how many groups there are, and takes the state of its worst group. Queries use a materialized view of the source when one covers them, and every query is bounded by a 40 second deadline, so a slow SLO never holds up alerts; what is left waits for the next run. A failed refresh keeps the last numbers and marks the SLO as an error. Changing what an SLO measures drops its snapshot, and a refresh never changes updatedAt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 03dd230 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 |
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
E2E Test Results✅ All tests passed • 479 passed • 1 skipped • 1144s
Tests ran across 4 shards in parallel. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Additional context: touches background tasks or the delivery pipeline lightly (12 lines, under the 30-line bar for Tier 4) Review process: Full human review — logic, architecture, edge cases. Stats
|
| attributes: { | ||
| 'hyperdx.slo.id': slo._id.toString(), | ||
| 'hyperdx.team.id': slo.team.toString(), | ||
| }, |
There was a problem hiding this comment.
🔴 P1 — A query cut off by the refresh deadline marks the SLO as error instead of deferring it
getQueryTimeout caps each query at whatever is left of the deadline, and runSloQuery (controllers/slo.ts:84) passes that to AbortSignal.timeout. When that signal fires, the error is an AbortError/ClickHouse timeout, not a SloQueryDeadlineError, so the catch here stores state: 'error'. Example: an SLO that starts with 6s left and needs 8s is flagged error, even though the PR says work that runs out of time waits for the next run. Fix: in this catch, also return 'deferred' when Date.now() >= deadline (or when the deadline signal has aborted), so only real failures get stored as errors.
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
| existing.source.toString() !== definition.source || | ||
| existing.target !== definition.target || | ||
| existing.window !== definition.window || | ||
| (existing.groupBy ?? null) !== (definition.groupBy ?? null) || |
There was a problem hiding this comment.
🟡 P2 — Saving an SLO with groupBy: '' always drops its status
SloInputSchema.groupBy is z.string().trim().nullish(), so '' passes validation and is stored as null (definition.groupBy || null). The check then compares null !== '' with ??, sees a change, and unsets status on every save, even a rename. Fix: normalise both sides the way the stored value is, with (existing.groupBy || null) !== (definition.groupBy || null).
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
5 finding(s): 🔴 1 P0/P1 · 🟡 2 P2 · 🔵 2 P3 2 posted as inline comment(s) on the changed lines. 1 listed below. 2 P3 folded at the bottom. Findings outside the changed lines
🔵 2 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. No data loss, injection, auth, or guaranteed-crash defects. The one adversarial lead — an 🟡 P2 — recommended
🔵 P3 nitpicks (6)
Reviewers (10): correctness, reliability, performance, adversarial, kieran-typescript, testing, maintainability, project-standards, 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
Each SLO stores a status snapshot so lists read it without querying. The
check-alerts task refreshes the snapshots beside the alert evaluation: burn
rates every 5 minutes from a 6-hour query in 5-minute buckets, and the SLI
and error budget every 30 minutes, since that query reads the whole 7 or 30
day window. A grouped SLO also stores the numbers of its 100 busiest groups
and how many groups there are, and takes the state of its worst group.
Queries use a materialized view of the source when one covers them, and
every query is bounded by a 40 second deadline, so a slow SLO never holds
up alerts; what is left waits for the next run. A failed refresh keeps the
last numbers and marks the SLO as an error. Changing what an SLO measures
drops its snapshot, and a refresh never changes updatedAt.
Stack
Part 8 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.Known limits
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:
make dev-int FILE=slos: the refresh stores a status (NULL good conditions count as bad), recomputes burn numbers every 5 minutes and window numbers every 30, tracks each group of a grouped SLO, and drops the status when what the SLO measures changes.cd packages/api && npx jest src/tasks/checkAlerts/__tests__/checkAlertsTask.test.ts: the refresh starts after the provider connects, and the connection closes only after it, even when the run fails.Test plan
routers/api/__tests__/slos.int.test.ts(refresh, NULL as bad, cadence, groups, snapshot dropped on change)tasks/checkAlerts/__tests__/checkAlertsTask.test.ts(refresh ordering)How to test on Vercel preview
N/A, non-UI change.
References