Repository navigation
feat(common-utils): SLO stats and state - #3792
alex-fedotyev wants to merge 1 commit into
Conversation
Adds the math that turns the counts query's rows into SLO numbers: the SLI, the error budget and how much of it is left, the burn rate of each window, and the fast and slow burn conditions. An SLO is breached when its budget is spent, burning when either condition holds, and healthy otherwise. A group of a grouped SLO needs 100 events in the window for a state of its own, and the SLO takes the state of its worst group. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
E2E Test Results✅ All tests passed • 475 passed • 1 skipped • 1122s
Tests ran across 4 shards in parallel. |
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
| worst = state; | ||
| } | ||
| } | ||
| return worst ?? deriveSloState(overall); |
There was a problem hiding this comment.
🔴 P1 — Grouped SLO state ignores the overall numbers once any group has 100+ events, so a breached or burning SLO can report 'healthy'
Once any group qualifies, deriveGroupedSloState returns worst and never looks at overall. The groups don't cover everything: groups under SLO_GROUP_MIN_EVENTS are skipped, and SloStatus.groups keeps only the busiest SLO_MAX_GROUPS (packages/common-utils/src/slo.ts). So the bad events behind an overspent overall budget can sit in those small or untracked groups. Example: one healthy group with 10k events plus 500 groups of 50 events, each fully bad. The status then shows state: 'healthy' next to a negative overall budgetRemaining, and the SLO never burns or breaches. Fix: return the worse of worst and deriveSloState(overall) (stateSeverity already ranks them), and add a test where the overall SLO is breached and every qualifying group is healthy.
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
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 Review✅ No critical issues found. The correctness and adversarial passes traced the math against the shared helpers and found no logic bugs introduced by this diff: 🟡 P2 -- recommended
🔵 P3 nitpicks (5)
Reviewers (8): correctness, testing, maintainability, project-standards, kieran-typescript, adversarial, 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 the math that turns the counts query's rows into SLO numbers: the SLI,
the error budget and how much of it is left, the burn rate of each window,
and the fast and slow burn conditions. An SLO is breached when its budget is
spent, burning when either condition holds, and healthy otherwise. A group
of a grouped SLO needs 100 events in the window for a state of its own, and
the SLO takes the state of its worst group.
Stack
Part 5 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.How to reproduce
Starting point: a checkout of this branch.
On
main: nothing to compare; this is new code.On this branch:
cd packages/common-utils && npx jest src/core/__tests__/sloStats.test.ts: bad is eligible minus good, the burn rate is a multiple of the allowed bad rate, a condition needs both windows and enough events, and a grouped SLO takes its worst group with enough events.Test plan
core/__tests__/sloStats.test.ts(stats, burn rule, groups)How to test on Vercel preview
N/A, non-UI change.
References
[no-changeset: allow] The changeset for this piece is in part 6.