Skip to content

feat(common-utils): SLO history and ordering - #3793

Open
alex-fedotyev wants to merge 1 commit into
alex/HDX-3001-slo-05-statsfrom
alex/HDX-3001-slo-06-history
Open

alex-fedotyev wants to merge 1 commit into
alex/HDX-3001-slo-05-statsfrom
alex/HDX-3001-slo-06-history

Conversation

@alex-fedotyev

@alex-fedotyev alex-fedotyev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the history behind the SLO charts, computed on read from bucketed
counts: the SLI per bucket, the error budget burndown over the displayed
window, and the burn rate over the trailing burn window, as the alerts read
it. Also adds worst first ordering for SLO lists: by state, then by budget
left, then by name.

Stack

Part 6 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 on main, one squashed commit each. Each diff is only its own change, and CI runs as if each PR targets main.

  1. feat(common-utils): SLO definition schema #3788 common-utils: SLO definition schema
  2. feat(common-utils): SLO fast and slow burn rules #3789 common-utils: SLO fast and slow burn rules
  3. feat(common-utils): SLO alert targets and status types #3790 common-utils: SLO alert targets and status types
  4. feat(common-utils): SLO counts query #3791 common-utils: SLO counts query
  5. feat(common-utils): SLO stats and state #3792 common-utils: SLO stats and state
  6. feat(common-utils): SLO history and ordering #3793 common-utils: SLO history and ordering (this PR)
  7. feat(api): SLO definitions behind ENABLE_SLOS #3794 api: SLO definitions behind ENABLE_SLOS
  8. feat(api): refresh SLO statuses in the check-alerts task #3795 api: refresh SLO statuses in the check-alerts task
  9. feat(api): SLO burn alerts as their own alert source #3796 api: SLO burn alerts as their own alert source
  10. feat(api): keep SLO alerts out of the external alerts API #3797 api: keep SLO alerts out of the external alerts API
  11. feat(api): evaluate SLO burn alerts and notify #3798 api: evaluate SLO burn alerts and notify
  12. feat(api): clickstack_get_slo MCP tool #3799 api: clickstack_get_slo MCP tool
  13. feat(api): SLO preview, save and delete MCP tools #3800 api: SLO preview, save and delete MCP tools
  14. feat(app): SLO list page behind NEXT_PUBLIC_ENABLE_SLOS #3801 app: SLO list page behind NEXT_PUBLIC_ENABLE_SLOS
  15. feat(app): search, filter, sort and delete SLOs in the list #3802 app: search, filter, sort and delete SLOs in the list
  16. feat(app): SLO builder for a new SLO #3803 app: SLO builder for a new SLO
  17. feat(app): SLO objective, details and editing in the builder #3804 app: SLO objective, details and editing in the builder
  18. feat(app): eligible-event filters and the latency template in the builder #3805 app: eligible-event filters and the latency template in the builder
  19. feat(app): preview an SLO in the builder before saving it #3806 app: preview an SLO in the builder before saving it
  20. feat(app): create an SLO from a search, and duplicate an SLO #3807 app: create an SLO from a search, and duplicate an SLO
  21. feat(app): SLO detail page #3808 app: SLO detail page
  22. feat(app): bad events flyout on the SLO page #3809 app: bad events flyout on the SLO page
  23. feat(app): SLI, error budget and burn rate charts on the SLO page #3810 app: SLI, error budget and burn rate charts on the SLO page
  24. feat(app): fast and slow burn alerts in the SLO builder, list and page #3811 app: fast and slow burn alerts in the SLO builder, list and page
  25. feat(app): SLO alerts on the Alerts page #3812 app: SLO alerts on the Alerts page
  26. feat(app): group-by in the SLO builder #3813 app: group-by in the SLO builder
  27. feat(app): grouped SLOs in the list and on the SLO page #3814 app: grouped SLOs in the list and on the SLO page

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) and NEXT_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:

  1. cd packages/common-utils && npx jest src/core/__tests__/sloStats.test.ts: the burndown ends at the budget left, the burn rate reads the trailing window in time rather than in buckets, and SLOs sort worst first.

Test plan

  • unit: core/__tests__/sloStats.test.ts (history, ordering); all common-utils unit tests
  • typecheck and knip at this commit, for every package

How to test on Vercel preview

N/A, non-UI change.

References

  • Linear Issue: HDX-3001
  • Related PRs: the rest of this stack, listed above

Adds the history behind the SLO charts, computed on read from bucketed
counts: the SLI per bucket, the error budget burndown over the displayed
window, and the burn rate over the trailing burn window, as the alerts read
it. Also adds worst first ordering for SLO lists: by state, then by budget
left, then by name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 24, 2026 6:36pm UTC
hyperdx-storybook Ready Ready Preview Nov 24, 2026 6:36pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2b18fb7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hyperdx/common-utils Patch

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

@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 107 in total (1.11%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 476 passed • 1 skipped • 1099s

Status Count
✅ Passed 476
❌ Failed 0
⚠️ Flaky 12
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@alex-fedotyev
alex-fedotyev marked this pull request as ready for review November 24, 2026 18:52
@alex-fedotyev
alex-fedotyev requested a review from a team as a code owner November 24, 2026 18:52
@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Nov 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 1
  • Production lines changed: 79 (+ 72 in test files, excluded from tier calculation)
  • Branch: alex/HDX-3001-slo-06-history
  • Author: alex-fedotyev

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

trailingEligible += b.eligible;
trailingGood += b.good;
// Buckets that ended before the burn window began drop out.
const windowStart = b.ts + bucketMs - burnWindowMs;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Burn window shorter than (or not a multiple of) the bucket silently drops the current bucket, so every burnRate is null

With getSloHistoryGranularity buckets (30m for 7d, 1h for 30d, core/slo.ts:141) and a 5m or 30m burn window (getSloBurnWindowMs, slo.ts:152), windowStart = b.ts + bucketMs - burnWindowMs is later than b.ts, so the loop pops the bucket it just pushed and the burn rate comes back null for every point. A 1h window over 30m buckets is fine, but a 45m window would drop the straddling bucket entirely. Always keep the current bucket (trailing.length > 1), or check that burnWindowMs is a positive multiple of bucketMs and throw if not. Add a test for 30m buckets with a 5m or 30m window.

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

@github-actions

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

4 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 3 P3

1 posted as inline comment(s) on the changed lines. 3 P3 folded at the bottom.

🔵 3 P3 — no action needed before merge
  • 🔵 P3 packages/common-utils/src/core/sloStats.ts:236 — compareSlosWorstFirst copies compareSloGroupsWorstFirst line for line → The state, then budget (with the Infinity/NaN handling), then localeCompare logic is the same as compareSloGroupsWorstFirst just above it (line 223). Only the field access differs. Pull out one shared comparator over { state, budgetRemaining, label } and have both call it, so a fix to the tie-break cannot land in one and not the other. Also replace the inline parameter type, written out twice, with a named type such as Pick<SloApiResponse, 'name' | 'status'> (src/slo.ts:353).
  • 🔵 P3 packages/common-utils/src/core/sloStats.ts:299 — Optional chaining on dropped guards a state the loop condition rules out → The while (trailing.length > 0 && …) check means shift() always returns an element, so dropped?.eligible ?? 0 and dropped?.good ?? 0 cannot take their fallbacks. Use a start index into buckets (while (buckets[start].ts < windowStart) { …; start++ }). That removes the dead fallbacks and the O(n) shift() on up to 720 points.
  • 🔵 P3 packages/common-utils/src/core/__tests__/sloStats.test.ts:301 — Ordering test skips the missing-status, null-budget and name tie-break paths → Every SLO in the test has a status and a finite budget, so these all go untested: the ?? 'no_data' default for an SLO without status, the ?? Infinity and NaN tie-break when both budgets are null, and the final localeCompare. Removing any of them would still pass. Add an SLO with status: null, two with null budgets and the same state, and two with equal budgets, and assert their order.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

The two new functions were traced against their tests and against the alert-counting semantics in getSloBurnCounts. computeSloHistory's trailing-window edge inclusion (windowStart = b.ts + bucketMs - burnWindowMs, keep when ts >= windowStart) is consistent with how the burn alert reads the window, the burndown denominator (allowedBad × totalEligible) makes the last point equal the current budget remaining as documented, and the zero/negative-budget and null branches are guarded. compareSlosWorstFirst's null-status default, null-budget Infinity fallback, and NaN tie-break guard are all correct. No correctness or performance defects.

🟡 P2 — recommended

  • packages/common-utils/src/core/sloStats.ts:306 — The sli output field of computeSloHistory is never asserted, including the eligible === 0 → null branch.
    • Fix: Add a history test asserting sli equals good / eligible for a normal bucket and is null for a zero-eligible gap bucket.
    • testing
  • packages/common-utils/src/core/sloStats.ts:308 — The budgetRemaining null branch (budget <= 0, i.e. target 100 or zero total eligible) and the empty-input case are untested.
    • Fix: Add a case with totalEligible === 0 or target 100 asserting budgetRemaining is null for every point, and assert empty buckets return [].
    • testing
  • packages/common-utils/src/core/sloStats.ts:247 — compareSlosWorstFirst's null/undefined-status default ('no_data') and null-budgetRemaining tie-break are untested; the one ordering test only exercises non-null states.
    • Fix: Add SLOs with null/undefined status and with null budgetRemaining and assert they sort as no_data severity and last within a state, respectively.
    • testing, correctness
🔵 P3 nitpicks (3)
  • .changeset/slo-common-utils.md:5 — The changeset body enumerates schema, burn rules and the counts query but not this PR's history/ordering additions (computeSloHistory, compareSlosWorstFirst, SloHistoryPoint).
    • Fix: Extend the changeset body to mention the on-read SLO history series and worst-first SLO ordering.
  • packages/common-utils/src/core/sloStats.ts:236 — compareSlosWorstFirst repeats the three-step sort policy and inline param shape of compareSloGroupsWorstFirst directly above it, so the two must change together.
    • Fix: Extract a shared severity-then-budget comparison helper and give each comparator its own field extractor and final string tie-break.
    • maintainability, kieran-typescript
  • packages/common-utils/src/core/sloStats.ts:299 — dropped?.eligible ?? 0 is unreachable defensive noise: the while (trailing.length > 0) guard means shift() never returns undefined, and it reads asymmetrically against the non-optional trailing[0].ts access above.
    • Fix: Use an index-pointer sliding window so the eviction uses the same non-optional indexed access and drops the ?./??.
    • kieran-typescript

Reviewers (7): correctness, testing, maintainability, project-standards, kieran-typescript, performance, previous-comments.

Testing gaps:

  • computeSloHistory: bad output field and its good > eligible clamp are unasserted; no single-bucket or non-whole-multiple burnWindowMs/bucketMs case.
  • computeSloHistory has an unguarded burnWindowMs >= bucketMs assumption (a smaller burn window would evict the current bucket and force burnRate null) and assumes ascending-sorted buckets; safe for all planned granularity/window pairs but unpinned with no callers in this diff.
  • compareSlosWorstFirst: the name.localeCompare final tie-break is uncovered.

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

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 2b18fb75 Deployed Nov 24, 2026 by vercel[bot]
Preview – hyperdx-storybook — 2b18fb75 Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant