Repository navigation
feat(pm-stack): sample SLO budgets on health page #11811
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
08091e7
43a3b44
a6e3e4c
ea686bc
765ecce
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 |
|---|---|---|
|
|
@@ -230,6 +230,9 @@ import { dispatchStateFor, fetchRfaState, RFA_NOT_PICKED_UP } from "./sources/re | |
| import { TodayCache, TODAY_CACHE_TTL_MS } from "./today-cache.ts"; | ||
| import { boardJsonBody, boardJsonViewBody } from "./board-json.ts"; | ||
| import { ItemHistoryStore } from "./item-history.ts"; | ||
| import { SloJournal, groupSamplesByFacet } from "./slo-journal.ts"; | ||
| import { sampleSloFacets } from "./slo-sampler.ts"; | ||
| import { SLO_DEFINITIONS, summarizeSloFacet, type SloFacetSummary } from "./slo.ts"; | ||
| import { computeFlowAnalytics } from "./flow-analytics.ts"; | ||
| import { | ||
| FORECAST_CONTRACT_VERSION, | ||
|
|
@@ -259,6 +262,8 @@ const commentsStore = new CommentsStore(cfg.commentsFile); | |
| const roadmapAnnotationsStore = new RoadmapAnnotationsStore(cfg.roadmapAnnotationsFile); | ||
| const coverageStore = new CoverageSnapshotStore(cfg.coverageSnapshotFile); | ||
| const itemHistoryStore = new ItemHistoryStore(cfg.itemHistoryFile); | ||
| const sloJournal = new SloJournal(cfg.sloJournalFile); | ||
| let sloSummaryCache: { at: number; value: SloFacetSummary[] } | null = null; | ||
| const spendRollupStore = new SpendRollupStore(cfg.snapshotsDir); | ||
| /** #4824: the Projects/Roadmap spend-beside-progress view over the | ||
| * #4823 rollup store. A failed read renders no spend block (the | ||
|
|
@@ -585,9 +590,23 @@ async function healthContext(prime = true): Promise<HealthView> { | |
| comments: await commentsStore.pendingCounts().catch(() => undefined), | ||
| conflicts: await assembleConflicts().catch(() => null), | ||
| pushHealth: cfg.source === "fixtures" ? null : freshnessReconciler.health(new Date()), | ||
| slo: cfg.source === "fixtures" ? null : await sloSummaries(), | ||
| }); | ||
| } | ||
|
|
||
| // SLO error budgets (#9988): summaries are read from the append-only journal | ||
| // and cached for a minute, the same cadence the sampler writes at. | ||
| const SLO_SUMMARY_CACHE_MS = 60_000; | ||
| async function sloSummaries(nowMs = Date.now()): Promise<SloFacetSummary[]> { | ||
| if (sloSummaryCache && nowMs - sloSummaryCache.at < SLO_SUMMARY_CACHE_MS) return sloSummaryCache.value; | ||
|
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. Expire the summary when a sample is committed. If a refresh finishes just before the first down sample is appended, the health page can keep showing the prior result for nearly another minute. Use the journal's committed generation in the cache key. This also prevents a refresh that started before the append from making an old snapshot current again.
|
||
| const byFacet = groupSamplesByFacet(await sloJournal.readAll().catch(() => [])); | ||
| const value = SLO_DEFINITIONS.map((definition) => | ||
| summarizeSloFacet(definition, byFacet.get(definition.id) ?? [], nowMs), | ||
| ); | ||
| sloSummaryCache = { at: nowMs, value }; | ||
| return value; | ||
| } | ||
|
|
||
| /** The identities half of the comment form options, behind a | ||
| * stale-while-revalidate cache (#5082, 2026-11-14). commentFormOpts | ||
| * is awaited on the request path of /program, /api/program.json and | ||
|
|
@@ -4522,6 +4541,30 @@ if (githubHotListConsumer) { | |
| }); | ||
| } | ||
|
|
||
| // SLO sampler (#9988): one sample per facet per minute, appended to the | ||
| // journal from the same health view /health renders. Live mode only. | ||
| const SLO_SAMPLE_INTERVAL_MS = 60_000; | ||
| if (cfg.source !== "fixtures") { | ||
| let sloSampling = false; | ||
| const sampleSlo = async (): Promise<void> => { | ||
| if (sloSampling) return; | ||
| sloSampling = true; | ||
| try { | ||
| const view = await healthContext(false); | ||
| await sloJournal.append(sampleSloFacets(view, Date.now())); | ||
| } catch (error) { | ||
| console.error( | ||
| `[slo] WARNING: SLO sample failed: ${error instanceof Error ? error.message : String(error)}`, | ||
| ); | ||
| } finally { | ||
| sloSampling = false; | ||
| } | ||
| }; | ||
| void sampleSlo(); | ||
| const timer = setInterval(() => void sampleSlo(), SLO_SAMPLE_INTERVAL_MS); | ||
| timer.unref?.(); | ||
| } | ||
|
|
||
| // The alert throat's engine (#3676): the ~60s delivery/escalation | ||
| // tick (live mode only, fail-soft — see src/alerts.ts). | ||
| startAlertEngine(cfg, async (): Promise<NotificationSnapshot> => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { appendFile, mkdir, readFile } from "node:fs/promises"; | ||
| import { dirname } from "node:path"; | ||
| import type { SloSample } from "./slo.ts"; | ||
|
|
||
| /** One append-only line in the SLO journal (#9988): one facet's sample for | ||
| * one minute. The journal never rewrites or compacts a line. */ | ||
| export interface SloJournalLine extends SloSample { | ||
| facet: string; | ||
| } | ||
|
|
||
| export class SloJournal { | ||
| private writes: Promise<void> = Promise.resolve(); | ||
|
|
||
| constructor(private readonly file: string) {} | ||
|
|
||
| append(lines: readonly SloJournalLine[]): Promise<void> { | ||
| if (lines.length === 0) return this.writes; | ||
| const payload = lines.map((line) => `${JSON.stringify(line)}\n`).join(""); | ||
| // A failed append must not poison the chain: each write starts from | ||
| // the previous one settled, so one bad write does not fail every | ||
| // later append and read. | ||
| this.writes = this.writes.catch(() => undefined).then(async () => { | ||
| await mkdir(dirname(this.file), { recursive: true }); | ||
| await appendFile(this.file, payload, "utf8"); | ||
| }); | ||
| return this.writes; | ||
| } | ||
|
|
||
| async readAll(): Promise<SloJournalLine[]> { | ||
| await this.writes.catch(() => undefined); | ||
| const raw = await readFile(this.file, "utf8").catch((error: NodeJS.ErrnoException) => { | ||
| if (error.code === "ENOENT") return ""; | ||
| throw error; | ||
| }); | ||
| return raw | ||
| .split("\n") | ||
| .filter(Boolean) | ||
| .flatMap((line) => { | ||
| // A line cut short by a crash mid-append is skipped, not fatal: | ||
| // one torn line must not blank every budget on /health. | ||
| try { | ||
| return [JSON.parse(line) as SloJournalLine]; | ||
| } catch { | ||
| return []; | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| export function groupSamplesByFacet(lines: readonly SloJournalLine[]): Map<string, SloSample[]> { | ||
| const byFacet = new Map<string, SloSample[]>(); | ||
| for (const { facet, atMs, bad, value } of lines) { | ||
| const list = byFacet.get(facet); | ||
| const sample: SloSample = { atMs, bad, value }; | ||
| if (list) list.push(sample); | ||
| else byFacet.set(facet, [sample]); | ||
| } | ||
| return byFacet; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,61 @@ | ||||||||
| import type { HealthView, ServiceHealth } from "./health.ts"; | ||||||||
| import type { SloJournalLine } from "./slo-journal.ts"; | ||||||||
|
|
||||||||
| const MINUTE = 60_000; | ||||||||
|
|
||||||||
| /** Per-facet bad thresholds, mirroring the SLO targets in slo.ts and the | ||||||||
| * design note. Age facets are bad past their threshold; up facets are bad | ||||||||
| * when a probed service answers not-ok. A facet with no probe or no age | ||||||||
| * source records bad: null so it is excluded, never called good. */ | ||||||||
| const FEED_BAD_AGE_MS = 10 * MINUTE; | ||||||||
| const QUOTA_BAD_AGE_MS = 75 * MINUTE; | ||||||||
| const ORCHESTRATION_BAD_AGE_MS = 90 * MINUTE; | ||||||||
|
|
||||||||
| function serviceOk(view: HealthView, ids: readonly string[]): boolean | null { | ||||||||
| const rows: ServiceHealth[] = ids.map((id) => view.services.find((s) => s.def.id === id)).filter( | ||||||||
| (s): s is ServiceHealth => s !== undefined, | ||||||||
| ); | ||||||||
| if (rows.length !== ids.length) return null; | ||||||||
| if (rows.some((s) => s.ok === false)) return false; | ||||||||
| if (rows.every((s) => s.ok === true)) return true; | ||||||||
| return null; | ||||||||
| } | ||||||||
|
|
||||||||
| function upSample(ids: readonly string[], view: HealthView): { bad: boolean | null; value: null } { | ||||||||
| const ok = serviceOk(view, ids); | ||||||||
| return { bad: ok === null ? null : !ok, value: null }; | ||||||||
| } | ||||||||
|
|
||||||||
| /** Sample every SLO facet once from an assembled health view (#9988). Pure: | ||||||||
| * the caller supplies the view and the minute timestamp. */ | ||||||||
| export function sampleSloFacets(view: HealthView, atMs: number): SloJournalLine[] { | ||||||||
| const quotaAgeMs = view.quotaGatherer ? Math.max(0, atMs - Date.parse(view.quotaGatherer.generatedAt)) : null; | ||||||||
|
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.
When quota providers keep failing but the gatherer continues running, this records healthy quota-age samples indefinitely. Useful? React with 👍 / 👎. 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. Treat an unparseable quota
Suggested fix
Committable suggestion
|
||||||||
| const orchestrationAgeMs = view.jobs.orchestration.ageMs ?? null; | ||||||||
| const feedAgeMs = view.feed.ageMs; | ||||||||
| const facets: SloJournalLine[] = [ | ||||||||
| { | ||||||||
| facet: "feed-age", | ||||||||
| atMs, | ||||||||
| value: feedAgeMs, | ||||||||
| bad: feedAgeMs === null ? null : feedAgeMs > FEED_BAD_AGE_MS, | ||||||||
| }, | ||||||||
| { | ||||||||
| facet: "quota-age", | ||||||||
| atMs, | ||||||||
| value: quotaAgeMs, | ||||||||
| bad: quotaAgeMs === null ? null : quotaAgeMs > QUOTA_BAD_AGE_MS, | ||||||||
| }, | ||||||||
| { | ||||||||
| facet: "orchestration-age", | ||||||||
| atMs, | ||||||||
| value: orchestrationAgeMs, | ||||||||
| bad: orchestrationAgeMs === null ? null : orchestrationAgeMs > ORCHESTRATION_BAD_AGE_MS, | ||||||||
| }, | ||||||||
| { facet: "aggregator-up", atMs, ...upSample(["aggregator"], view) }, | ||||||||
| { facet: "intake-up", atMs, ...upSample(["intake"], view) }, | ||||||||
| { facet: "projector-up", atMs, ...upSample(["projector"], view) }, | ||||||||
| { facet: "pad-grist-up", atMs, ...upSample(["pad", "grist"], view) }, | ||||||||
| { facet: "tunnel-up", atMs, ...upSample(["tunnel"], view) }, | ||||||||
| ]; | ||||||||
| return facets; | ||||||||
| } | ||||||||
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.
Do not display a measured burn rate for an unsourced facet.
When an age facet has no observations,
summarizeSloFacetsets its state tounknownbut retains the computed burn of zero. The Health page then shows0.00, which implies that it measured no burn. Return a null burn for unsourced facets insummarizeSloFacetso the API and page agree. Keep a measured zero visible for sourced facets.