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

Parked opened this
Closed without merging

scout/forge:scout/2284-the-board-s-one-line-verdict-says-needs → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +79 −15
src/actions/health.ts +2 −6
@@ -12,7 +12,7 @@ import type { App } from "../app.ts";
1212 import { appsRuntime } from "../apps/runtime.ts";
1313 import { listApps } from "../core/apps.ts";
1414 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";
1616 import {
1717 laneLine,
1818 sinceWords,
@@ -70,12 +70,8 @@ export function readHealth(
7070 export function forgeNeeds(app: App, actor: User | undefined): string[] | undefined {
7171 if (!actor?.isAdmin) return undefined;
7272 const h = readHealth(app, actor) as Vitals & ForgeHealth;
73 const rollout = rolloutLine(h);
7473 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}`),
7975 ...h.degraded.map(needLine),
8076 ];
8177 }
src/http/health.ts +5 −1
@@ -16,7 +16,10 @@
1616
1717 import type { Log } from "../kernel/log.ts";
1818
19 export const health = { draining: false };
19 export const health: { draining: boolean; drainingSince: number | null } = {
20 draining: false,
21 drainingSince: null,
22 };
2023
2124 /** Whether the last liveness answer was a 503, so the log says so once. */
2225 let databaseDown = false;
@@ -28,6 +31,7 @@ let databaseDown = false;
2831 export function startDraining(log: Log, why: string, fields: Record<string, number> = {}): void {
2932 if (health.draining) return;
3033 health.draining = true;
34 health.drainingSince = Date.now();
3135 log.info("forge draining: /readyz answers 503 from now", { why, ...fields });
3236 }
3337
src/kernel/guard.ts +27
@@ -14,6 +14,8 @@ import { health } from "../http/health.ts";
1414 import { running } from "./version.ts";
1515
1616 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;
1719 const MAX_INCIDENTS = 50;
1820 const MAX_MESSAGE = 800;
1921
@@ -38,6 +40,8 @@ export interface ForgeHealth {
3840 readonly version: string;
3941 readonly commit: string | null;
4042 readonly draining: boolean;
43 /** Draining for longer than `DRAIN_LONG_MS`. */
44 readonly drainingLong: boolean;
4145 readonly rollout: Rollout;
4246 readonly incidents: Incident[];
4347 readonly stale: boolean;
@@ -120,6 +124,10 @@ export function forgeHealth(
120124 version,
121125 commit,
122126 draining: health.draining,
127 drainingLong:
128 health.draining &&
129 health.drainingSince !== null &&
130 now - health.drainingSince > DRAIN_LONG_MS,
123131 rollout,
124132 incidents: guard.incidents,
125133 stale,
@@ -133,3 +141,22 @@ export function rolloutLine(h: ForgeHealth): string | null {
133141 if (h.rollout.state === "held") return `rollout held: ${h.rollout.reason}`;
134142 return h.stale ? h.rollout.reason : null;
135143 }
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 {
4343 import { readSpend } from "../../actions/spend.ts";
4444 import { spendView } from "./spend.ts";
4545 import type { HandContext } from "../../crew/handover.ts";
46 import { forgeHealth, rolloutLine } from "../../kernel/guard.ts";
46 import { forgeHealth, forgeProblems } from "../../kernel/guard.ts";
4747 import { laneLine, type Vitals } from "../../kernel/vitals.ts";
4848 import { getIssue, getIssuesByIds, type Issue } from "../../core/issues.ts";
4949 import { looksForApps } from "../../core/looks.ts";
@@ -328,10 +328,7 @@ function forgeStrip(ctx: Ctx): Html | null {
328328 if (!ctx.auth.user?.isAdmin) return null;
329329 const v = forgeVitals(ctx.app);
330330 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);
335332 const ok = v.ok && fh.ok;
336333 const lane = laneLine(v.lane);
337334 return html`<div
@@ -343,8 +340,7 @@ function forgeStrip(ctx: Ctx): Html | null {
343340 role="status"
344341 >
345342 ${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>`)}
348344 ${lane === null ? "" : html`<span class="board-forge-lane">Lane: ${lane}</span>`}
349345 ${
350346 ok
test/board.test.ts +25
@@ -525,6 +525,31 @@ describe("the board's forge strip", () => {
525525 }
526526 });
527527
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&#39;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
528553 test("the sentinel's line is the admin's alone, and absent before the first hunt", async () => {
529554 expect(await board("root")).not.toContain("sentinel");
530555
test/guard.test.ts +16
@@ -7,9 +7,11 @@ import { tmpdir } from "node:os";
77 import { join } from "node:path";
88 import { createApp, type App } from "../src/app.ts";
99 import { serve, type Servers } from "../src/http/server.ts";
10 import { health } from "../src/http/health.ts";
1011 import { running } from "../src/kernel/version.ts";
1112 import {
1213 forgeHealth,
14 forgeProblems,
1315 parseGuard,
1416 readGuard,
1517 rolloutLine,
@@ -105,3 +107,17 @@ test("/api/v1/health answers anyone, from the mounted ConfigMap", async () => {
105107 expect(body.ok).toBe(false);
106108 expect(body.incidents).toEqual([{ key: "stuck", message: "quota refused <b>" }]);
107109 });
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
8383 const v = (await res.json()) as Record<string, any>;
8484 expect(Object.keys(v).sort()).toEqual(
8585 [
86 "apps", "at", "checkedAt", "commit", "degraded", "disk", "draining", "errors",
86 "apps", "at", "checkedAt", "commit", "degraded", "disk", "draining", "drainingLong", "errors",
8787 "incidents", "lane", "memory", "needs", "ok", "queue", "rollout", "stale", "stuck",
8888 "version",
8989 ].sort(),

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs