Repository navigation
feat(api): evaluate SLO burn alerts and notify #3798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| '@hyperdx/api': patch | ||
| '@hyperdx/common-utils': patch | ||
| --- | ||
|
|
||
| feat: SLO fast and slow burn alerts as their own alert source | ||
|
|
||
| An SLO can have a fast burn and a slow burn alert, each an alert with the | ||
| new `slo` source and its own channels, kept in sync with the SLO. 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 needs its last 5 or 30 minutes to | ||
| burn as fast, so it resolves soon after a burn stops. Each notifies once | ||
| when it starts firing and once when it resolves, and its message names the | ||
| rule and states the numbers. A grouped SLO's alerts fire and resolve for | ||
| each group with enough events, and their notifications name the group and | ||
| link to it. Each check also stores the burn rates on the SLO, so the SLO | ||
| list shows the alerts' own verdict. SLO alerts are changed from their SLO, | ||
| stay out of the external alerts API, and only run while SLOs are enabled. | ||
| Deleting one from the Alerts page turns that alert off on its SLO. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,12 @@ | ||
| import PQueue from '@esm2cjs/p-queue'; | ||
| import { withQueryAttribution } from '@hyperdx/common-utils/dist/clickhouse/node'; | ||
| import { getSloWindowRange } from '@hyperdx/common-utils/dist/core/slo'; | ||
| import { | ||
| compareSloGroupsWorstFirst, | ||
| deriveGroupedSloState, | ||
| deriveSloGroupState, | ||
| deriveSloState, | ||
| } from '@hyperdx/common-utils/dist/core/sloStats'; | ||
| import type { SloStatus } from '@hyperdx/common-utils/dist/slo'; | ||
|
|
||
| import { getSloQueryContext } from '@/controllers/slo'; | ||
|
|
@@ -21,7 +27,12 @@ import { | |
| } from '@/utils/instrumentation'; | ||
| import logger from '@/utils/logger'; | ||
|
|
||
| /** How old the burn numbers get before the refresh recomputes them. */ | ||
| /** | ||
| * How old the burn numbers get before the refresh recomputes them. Each | ||
| * check of an ungrouped SLO's burn alerts writes them too, so the refresh | ||
| * fills in only when no alert check did in the last 5 minutes. A grouped | ||
| * SLO's alerts write only their groups' numbers. | ||
| */ | ||
| const SLO_BURN_MAX_AGE_MS = 5 * 60 * 1000; | ||
| /** | ||
| * How old the window numbers (SLI, budget) get. Their query reads the whole | ||
|
|
@@ -43,6 +54,50 @@ const refreshCounter = getCounter('hyperdx.slo.refresh', { | |
| description: 'SLO status refreshes, by outcome', | ||
| }); | ||
|
|
||
| /** | ||
| * Stores the burn numbers an SLO's alert check computed, so the list shows | ||
| * the alert's own verdict: for an ungrouped SLO its burn numbers, for a | ||
| * grouped one each group's. The window numbers stay as the refresh stored | ||
| * them; until it has, there is nothing to add to. Returns the stored | ||
| * snapshot. | ||
| */ | ||
| export async function recordSloAlertBurn( | ||
| slo: ISlo, | ||
| burn: Partial<SloBurnNumbers>, | ||
| now: Date, | ||
| ): Promise<SloStatus | null> { | ||
| const previous = slo.status; | ||
| if (previous?.windowEvaluatedAt == null) return null; | ||
| const groups = previous.groups | ||
| ?.map(group => { | ||
| const groupBurn = burn.groups?.get(group.value); | ||
| if (groupBurn == null) return group; | ||
| const next = { ...group, burn: groupBurn }; | ||
| return { ...next, state: deriveSloGroupState(next) }; | ||
| }) | ||
| .sort(compareSloGroupsWorstFirst); | ||
| const overall = { ...previous, burn: burn.burn ?? previous.burn }; | ||
| const status: SloStatus = { | ||
| ...overall, | ||
| // Only new overall burn numbers make the snapshot's burn part fresh. | ||
| evaluatedAt: burn.burn != null ? now.toISOString() : previous.evaluatedAt, | ||
| ...(groups != null ? { groups } : {}), | ||
| // A failing window query keeps its error until the refresh clears it. | ||
| state: | ||
| previous.state === 'error' | ||
| ? 'error' | ||
| : groups != null | ||
| ? deriveGroupedSloState(overall, groups) | ||
| : deriveSloState(overall), | ||
| }; | ||
| await Slo.updateOne( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — Alert's burn write-back can overwrite a newer refresh snapshot with stale window numbers
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 |
||
| { _id: slo._id, updatedAt: slo.updatedAt }, | ||
| { $set: { status } }, | ||
| { timestamps: false }, | ||
| ); | ||
| return status; | ||
| } | ||
|
|
||
| const getErrorMessage = (e: unknown) => | ||
| e instanceof Error ? e.message : String(e); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 P2 — Error state outlives a successful burn check because the alert keeps evaluatedAt fresh
An ungrouped SLO's fast burn alert sets
evaluatedAtto now every 5 minutes, but keepsstate: 'error'when it is already error. The refresh only reruns whenevaluatedAtis 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 updatingevaluatedAtwhile 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