Repository navigation
feat(common-utils): SLO counts query - #3791
alex-fedotyev wants to merge 1 commit into
Conversation
Adds the one query every SLO number comes from (buildSloCountsChartConfig): eligible and good counts over a range, per bucket, for one group, or by group (the 100 groups with the most events, plus one to tell when there are more, and a distinct group count). It is built with buildSearchChartConfig, the builder Search uses, so a drill-down with the same where clause and filters sees the same events. Bad is eligible minus good, so an event whose good condition is NULL counts as bad. The burn rules read 5-minute buckets over the last 6 hours, ending on a 5-minute boundary. Also adds the bad-events search for drill-downs, the parsers for the query rows, describeFilter (moved here so the API and the app share it) and an "slo" query attribution surface. 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 • 1357s
Tests ran across 4 shards in parallel. |
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Additional context: touches the query rendering engine lightly (1 lines, under the 150-line bar for Tier 4) Review process: Full human review — logic, architecture, edge cases. Stats
|
| } | ||
|
|
||
| // `slo_group` is SLO_GROUP_ALIAS, the group's column in a query by group. | ||
| const groupValueSchema = z.object({ slo_group: z.coerce.string() }); |
There was a problem hiding this comment.
🟡 P2 — A NULL group value turns into the string "null", so that group's own queries and drill-downs match nothing
z.coerce.string() turns a NULL slo_group (for example toString of a Nullable or JSON subcolumn) into "null", and a missing column into "undefined". getSloGroupFilter then filters on toString(x) = 'null', which matches no rows, so the group's scoped counts, burn and bad-events drill-down come back empty. Coercion also means safeParse can never fail, so the !parsed.success branches are dead code. Fix: use z.union([z.string(), z.number()]).transform(String) so null and undefined are rejected, or wrap the group expression as ifNull(toString(...), '') in getSloGroupExpression.
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
| * Per group: the SLO_MAX_GROUPS busiest plus one, which tells the caller | ||
| * there are more, or the given groups. | ||
| */ | ||
| | { byGroup: true; groups?: string[] }; |
There was a problem hiding this comment.
🟡 P2 — { byGroup: true } with a granularity and no groups returns every group, with no limit
The limit of SLO_MAX_GROUPS + 1 only applies when granularity == null. So buildSloBurnChartConfig({ scope: { byGroup: true } }), or a bucketed counts query, returns rows for every distinct group times 72 buckets, which can be unbounded on a high-cardinality group-by. The SloGroupScope type allows this, but the docs don't describe it. Fix: make the bucketed by-group variant require groups (for example { byGroup: true; groups: string[] } for bucketed queries), or apply a limit there as well.
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
4 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 2 P3 2 posted as inline comment(s) on the changed lines. 2 P3 folded at the bottom. 🔵 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. This is a new, well-structured, well-commented query layer in 🟡 P2 — recommended
🔵 P3 nitpicks (8)
Reviewers (12): correctness, adversarial, security, testing, maintainability, performance, api-contract, kieran-typescript, project-standards, agent-native, learnings-researcher, previous-comments. Testing gaps:
Other notes:
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 one query every SLO number comes from
(buildSloCountsChartConfig): eligible and good counts over a range, per
bucket, for one group, or by group (the 100 groups with the most events,
plus one to tell when there are more, and a distinct group count). It is
built with buildSearchChartConfig, the builder Search uses, so a
drill-down with the same where clause and filters sees the same events.
Bad is eligible minus good, so an event whose good condition is NULL
counts as bad. The burn rules read 5-minute buckets over the last 6
hours, ending on a 5-minute boundary.
Also adds the bad-events search for drill-downs, the parsers for the
query rows, describeFilter (moved here so the API and the app share it)
and an "slo" query attribution surface.
Stack
Part 4 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__/slo.test.ts: the counts, burn and group queries, the row parsers and the bad-events search are covered, and a snapshot pins the rendered counts SQL.Test plan
core/__tests__/slo.test.ts(counts, burn and group queries, parsers, bad-events search, rendered SQL snapshot)How to test on Vercel preview
N/A, non-UI change.
References
[no-changeset: allow] The changeset for this piece is in part 6.
[as-cast: allow] The cast check matches the word "as" in comments and strings here; the diff has no
ascasts.