Public: anyone can read this; the crew can change it.
The board's one-line verdict says 'needs you: forge …' when the forge itself is degraded #2308
scout/forge:scout/2284-the-board-s-one-line-verdict-says-needs → main 2 commits fork
7 files
changed +79
−15
src/actions/health.ts +2 −6
| @@ -12,7 +12,7 @@ import type { App } from "../app.ts"; | ||
| 12 | 12 | import { appsRuntime } from "../apps/runtime.ts"; |
| 13 | 13 | import { listApps } from "../core/apps.ts"; |
| 14 | 14 | import type { User } from "../core/users.ts"; |
| 15 | import { forgeHealth, rolloutLine, type ForgeHealth } from "../kernel/guard.ts"; | |
| 15 | import { forgeHealth, forgeProblems, type ForgeHealth } from "../kernel/guard.ts"; | |
| 16 | 16 | import { |
| 17 | 17 | laneLine, |
| 18 | 18 | sinceWords, |
| @@ -70,12 +70,8 @@ export function readHealth( | ||
| 70 | 70 | export function forgeNeeds(app: App, actor: User | undefined): string[] | undefined { |
| 71 | 71 | if (!actor?.isAdmin) return undefined; |
| 72 | 72 | const h = readHealth(app, actor) as Vitals & ForgeHealth; |
| 73 | const rollout = rolloutLine(h); | |
| 74 | 73 | return [ |
| 75 | ...(rollout === null ? [] : [rollout]), | |
| 76 | ...h.incidents | |
| 77 | .filter((i) => i.key !== "stuck" && i.key !== "held") | |
| 78 | .map((i) => `${i.key}: ${i.message}`), | |
| 74 | ...forgeProblems(h).map((p) => `Needs you: forge ${p}`), | |
| 79 | 75 | ...h.degraded.map(needLine), |
| 80 | 76 | ]; |
| 81 | 77 | } |
src/http/health.ts +5 −1
| @@ -16,7 +16,10 @@ | ||
| 16 | 16 | |
| 17 | 17 | import type { Log } from "../kernel/log.ts"; |
| 18 | 18 | |
| 19 | export const health = { draining: false }; | |
| 19 | export const health: { draining: boolean; drainingSince: number | null } = { | |
| 20 | draining: false, | |
| 21 | drainingSince: null, | |
| 22 | }; | |
| 20 | 23 | |
| 21 | 24 | /** Whether the last liveness answer was a 503, so the log says so once. */ |
| 22 | 25 | let databaseDown = false; |
| @@ -28,6 +31,7 @@ let databaseDown = false; | ||
| 28 | 31 | export function startDraining(log: Log, why: string, fields: Record<string, number> = {}): void { |
| 29 | 32 | if (health.draining) return; |
| 30 | 33 | health.draining = true; |
| 34 | health.drainingSince = Date.now(); | |
| 31 | 35 | log.info("forge draining: /readyz answers 503 from now", { why, ...fields }); |
| 32 | 36 | } |
| 33 | 37 |
src/kernel/guard.ts +27
| @@ -14,6 +14,8 @@ import { health } from "../http/health.ts"; | ||
| 14 | 14 | import { running } from "./version.ts"; |
| 15 | 15 | |
| 16 | 16 | export const GUARD_STALE_MS = 10 * 60_000; |
| 17 | /** A drain longer than this is a release that is not finishing. */ | |
| 18 | export const DRAIN_LONG_MS = 5 * 60_000; | |
| 17 | 19 | const MAX_INCIDENTS = 50; |
| 18 | 20 | const MAX_MESSAGE = 800; |
| 19 | 21 | |
| @@ -38,6 +40,8 @@ export interface ForgeHealth { | ||
| 38 | 40 | readonly version: string; |
| 39 | 41 | readonly commit: string | null; |
| 40 | 42 | readonly draining: boolean; |
| 43 | /** Draining for longer than `DRAIN_LONG_MS`. */ | |
| 44 | readonly drainingLong: boolean; | |
| 41 | 45 | readonly rollout: Rollout; |
| 42 | 46 | readonly incidents: Incident[]; |
| 43 | 47 | readonly stale: boolean; |
| @@ -120,6 +124,10 @@ export function forgeHealth( | ||
| 120 | 124 | version, |
| 121 | 125 | commit, |
| 122 | 126 | draining: health.draining, |
| 127 | drainingLong: | |
| 128 | health.draining && | |
| 129 | health.drainingSince !== null && | |
| 130 | now - health.drainingSince > DRAIN_LONG_MS, | |
| 123 | 131 | rollout, |
| 124 | 132 | incidents: guard.incidents, |
| 125 | 133 | stale, |
| @@ -133,3 +141,22 @@ export function rolloutLine(h: ForgeHealth): string | null { | ||
| 133 | 141 | if (h.rollout.state === "held") return `rollout held: ${h.rollout.reason}`; |
| 134 | 142 | return h.stale ? h.rollout.reason : null; |
| 135 | 143 | } |
| 144 | ||
| 145 | /** | |
| 146 | * Everything wrong with the forge itself, one sentence each, every incident | |
| 147 | * among them (a `held` beside a `stuck` too, and those the watchdog already | |
| 148 | * paged): what the board's line says after "needs you: forge". Empty means | |
| 149 | * the platform has nothing to add. | |
| 150 | */ | |
| 151 | export function forgeProblems(h: ForgeHealth): string[] { | |
| 152 | const out = h.incidents.map((i) => | |
| 153 | i.key === "stuck" | |
| 154 | ? `rollout blocked: ${i.message}` | |
| 155 | : i.key === "held" | |
| 156 | ? `rollout held: ${i.message}` | |
| 157 | : `${i.key}: ${i.message}`, | |
| 158 | ); | |
| 159 | if (h.stale) out.push(h.rollout.reason || `the platform's view is stale: its last check was ${h.checkedAt}`); | |
| 160 | if (h.drainingLong) out.push("draining for more than 5 minutes: the release is not finishing"); | |
| 161 | return out; | |
| 162 | } |
src/web/pages/board.ts +3 −7
| @@ -43,7 +43,7 @@ import { | ||
| 43 | 43 | import { readSpend } from "../../actions/spend.ts"; |
| 44 | 44 | import { spendView } from "./spend.ts"; |
| 45 | 45 | import type { HandContext } from "../../crew/handover.ts"; |
| 46 | import { forgeHealth, rolloutLine } from "../../kernel/guard.ts"; | |
| 46 | import { forgeHealth, forgeProblems } from "../../kernel/guard.ts"; | |
| 47 | 47 | import { laneLine, type Vitals } from "../../kernel/vitals.ts"; |
| 48 | 48 | import { getIssue, getIssuesByIds, type Issue } from "../../core/issues.ts"; |
| 49 | 49 | import { looksForApps } from "../../core/looks.ts"; |
| @@ -328,10 +328,7 @@ function forgeStrip(ctx: Ctx): Html | null { | ||
| 328 | 328 | if (!ctx.auth.user?.isAdmin) return null; |
| 329 | 329 | const v = forgeVitals(ctx.app); |
| 330 | 330 | const fh = forgeHealth(); |
| 331 | const rollout = rolloutLine(fh); | |
| 332 | const others = fh.incidents.filter( | |
| 333 | (i) => i.key !== "stuck" && i.key !== "held", | |
| 334 | ); | |
| 331 | const problems = forgeProblems(fh); | |
| 335 | 332 | const ok = v.ok && fh.ok; |
| 336 | 333 | const lane = laneLine(v.lane); |
| 337 | 334 | return html`<div |
| @@ -343,8 +340,7 @@ function forgeStrip(ctx: Ctx): Html | null { | ||
| 343 | 340 | role="status" |
| 344 | 341 | > |
| 345 | 342 | ${sentinelSpan(ctx.app)} |
| 346 | ${rollout === null ? "" : html`<span class="board-forge-need">${rollout}</span>`} | |
| 347 | ${others.map((i) => html`<span class="board-forge-need">${i.key}: ${i.message}</span>`)} | |
| 343 | ${problems.map((p) => html`<span class="board-forge-need">Needs you: forge ${p}</span>`)} | |
| 348 | 344 | ${lane === null ? "" : html`<span class="board-forge-lane">Lane: ${lane}</span>`} |
| 349 | 345 | ${ |
| 350 | 346 | ok |
test/board.test.ts +25
| @@ -525,6 +525,31 @@ describe("the board's forge strip", () => { | ||
| 525 | 525 | } |
| 526 | 526 | }); |
| 527 | 527 | |
| 528 | test("the forge's line says needs you for a held incident and a stale view, and not for an empty one", async () => { | |
| 529 | const guard = mkdtempSync(join(tmpdir(), "forge-board-guard-")); | |
| 530 | process.env["FORGE_GUARD_DIR"] = guard; | |
| 531 | const put = (incidents: Record<string, string>, at: Date) => { | |
| 532 | writeFileSync(join(guard, "status.json"), JSON.stringify({ incidents })); | |
| 533 | writeFileSync(join(guard, "checkedAt"), at.toISOString()); | |
| 534 | }; | |
| 535 | try { | |
| 536 | put({}, new Date()); | |
| 537 | expect(await board("root")).toContain("All fine"); | |
| 538 | put({ held: "preflight refused: 9Gi", stuck: "no room" }, new Date()); | |
| 539 | const held = await board("root"); | |
| 540 | expect(held).toContain("Needs you: forge rollout held: preflight refused: 9Gi"); | |
| 541 | expect(held).toContain("Needs you: forge rollout blocked: no room"); | |
| 542 | expect(held).not.toContain("All fine"); | |
| 543 | put({}, new Date(Date.now() - 20 * 60_000)); | |
| 544 | const stale = await board("root"); | |
| 545 | expect(stale).toContain("Needs you: forge the platform's view is stale"); | |
| 546 | expect(stale).not.toContain("All fine"); | |
| 547 | } finally { | |
| 548 | delete process.env["FORGE_GUARD_DIR"]; | |
| 549 | rmSync(guard, { recursive: true, force: true }); | |
| 550 | } | |
| 551 | }); | |
| 552 | ||
| 528 | 553 | test("the sentinel's line is the admin's alone, and absent before the first hunt", async () => { |
| 529 | 554 | expect(await board("root")).not.toContain("sentinel"); |
| 530 | 555 |
test/guard.test.ts +16
| @@ -7,9 +7,11 @@ import { tmpdir } from "node:os"; | ||
| 7 | 7 | import { join } from "node:path"; |
| 8 | 8 | import { createApp, type App } from "../src/app.ts"; |
| 9 | 9 | import { serve, type Servers } from "../src/http/server.ts"; |
| 10 | import { health } from "../src/http/health.ts"; | |
| 10 | 11 | import { running } from "../src/kernel/version.ts"; |
| 11 | 12 | import { |
| 12 | 13 | forgeHealth, |
| 14 | forgeProblems, | |
| 13 | 15 | parseGuard, |
| 14 | 16 | readGuard, |
| 15 | 17 | rolloutLine, |
| @@ -105,3 +107,17 @@ test("/api/v1/health answers anyone, from the mounted ConfigMap", async () => { | ||
| 105 | 107 | expect(body.ok).toBe(false); |
| 106 | 108 | expect(body.incidents).toEqual([{ key: "stuck", message: "quota refused <b>" }]); |
| 107 | 109 | }); |
| 110 | ||
| 111 | test("a drain is a problem only after five minutes; oom incidents always are", () => { | |
| 112 | const g = parseGuard(status({ "oom:forge": "raise the limit" }), fresh); | |
| 113 | try { | |
| 114 | health.draining = true; | |
| 115 | health.drainingSince = NOW - 4 * 60_000; | |
| 116 | expect(forgeProblems(forgeHealth(g, NOW))).toEqual(["oom:forge: raise the limit"]); | |
| 117 | health.drainingSince = NOW - 6 * 60_000; | |
| 118 | expect(forgeProblems(forgeHealth(g, NOW)).length).toBe(2); | |
| 119 | } finally { | |
| 120 | health.draining = false; | |
| 121 | health.drainingSince = null; | |
| 122 | } | |
| 123 | }); |
test/vitals.test.ts +1 −1
| @@ -83,7 +83,7 @@ test("a site admin with a read-only token gets the shape; others get the short o | ||
| 83 | 83 | const v = (await res.json()) as Record<string, any>; |
| 84 | 84 | expect(Object.keys(v).sort()).toEqual( |
| 85 | 85 | [ |
| 86 | "apps", "at", "checkedAt", "commit", "degraded", "disk", "draining", "errors", | |
| 86 | "apps", "at", "checkedAt", "commit", "degraded", "disk", "draining", "drainingLong", "errors", | |
| 87 | 87 | "incidents", "lane", "memory", "needs", "ok", "queue", "rollout", "stale", "stuck", |
| 88 | 88 | "version", |
| 89 | 89 | ].sort(), |
new above
offline