Public: anyone can read this; the crew can change it.
Health tells a stranger only ok and draining #16604
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/16262-health-tells-a-stranger-only-ok-and-drai → main 0 commits fork
10 files
changed +54
−25
scripts/forge-compat-lab/driver.ts +4 −3
| @@ -225,11 +225,12 @@ const results = async (): Promise<void> => { | ||
| 225 | 225 | /** Direct answers of a source forge's own endpoints, no receiver in between. */ |
| 226 | 226 | const probeSource = async (name: string, s: string, seed: Seed): Promise<void> => { |
| 227 | 227 | const tag = name; |
| 228 | await cell(tag, "1 discovery", "health names version and commit", async () => { | |
| 228 | // A forge tells a stranger only ok and draining on health (#16262); the API version is public. | |
| 229 | await cell(tag, "1 discovery", "health says ok; version names the API", async () => { | |
| 229 | 230 | const h = await api(s, "/api/v1/health", ""); |
| 230 | must(h.status === 200 && typeof h.data.version === "string", `health ${h.status}`); | |
| 231 | must(h.status === 200 && typeof h.data.ok === "boolean", `health ${h.status}`); | |
| 231 | 232 | const v = await api(s, "/api/v1/version", ""); |
| 232 | return `version ${h.data.version}; /api/v1/version ${v.status}; /user/repos ${(await api(s, "/api/v1/user/repos", `Bearer ${seed.ann.ro}`)).status}`; | |
| 233 | return `version ${h.data.version ?? v.data?.version ?? "unsaid"}; /api/v1/version ${v.status}; /user/repos ${(await api(s, "/api/v1/user/repos", `Bearer ${seed.ann.ro}`)).status}`; | |
| 233 | 234 | }); |
| 234 | 235 | for (const [scheme, header] of [ |
| 235 | 236 | ["Bearer", `Bearer ${seed.ann.ro}`], |
src/actions/health.ts +9 −11
| @@ -4,11 +4,10 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * - a stranger learns whether the forge is well and whether it is draining, |
| 6 | 6 | * how many schedules are overdue and by how long the worst one is (counts |
| 7 | * only, no app or repository: #12512), and nothing of the platform's | |
| 8 | * incidents or rollout. It is also told the | |
| 9 | * version and commit for one release more — a running forge's swap reads | |
| 10 | * its successor's commit without a probe (`release/swap.ts` before #2917); | |
| 11 | * once that forge is gone the stranger's answer is `ok` alone. | |
| 7 | * only, no app or repository: #12512), the release number (#13263), and | |
| 8 | * nothing of the commit, the platform's incidents or rollout (#16262): | |
| 9 | * every swap, boot, launch, rollback and proof that reads the commit sends | |
| 10 | * the probe. | |
| 12 | 11 | * - anyone signed in, and the forge's own release machinery carrying the |
| 13 | 12 | * probe (`kernel/probe.ts`), get the whole answer: version, commit, |
| 14 | 13 | * rollout and the platform's incidents. |
| @@ -111,11 +110,10 @@ export function withHeavyAskers(v: Vitals, app: App, now: number = Date.now()): | ||
| 111 | 110 | } |
| 112 | 111 | |
| 113 | 112 | /** |
| 114 | * What a stranger is told: no incident, no rollout, no platform words. | |
| 115 | * Version and commit stay for one release, while a running forge's swap | |
| 116 | * reads its successor's commit without the probe; #2962 removes them. | |
| 113 | * What a stranger is told: whether the forge is well and whether it is draining. No version, | |
| 114 | * commit, incident, rollout or platform words (#16262); the release machinery carries the probe. | |
| 117 | 115 | */ |
| 118 | export type StrangerHealth = Pick<ForgeHealth, "ok" | "version" | "commit" | "draining">; | |
| 116 | export type StrangerHealth = Pick<ForgeHealth, "ok" | "draining">; | |
| 119 | 117 | |
| 120 | 118 | /** The optional parts beside the health of anyone signed in (`system/footprint.ts`). */ |
| 121 | 119 | export interface Parts { |
| @@ -164,8 +162,8 @@ export function readHealth( | ||
| 164 | 162 | ): StrangerHealth | ForgeHealth | (ForgeHealth & Parts) | (Vitals & ForgeHealth & Parts) { |
| 165 | 163 | const health = forgeHealth(); |
| 166 | 164 | if (actor === undefined && !probe) { |
| 167 | const { ok, version, commit, draining } = health; | |
| 168 | return { ok, version, commit, draining }; | |
| 165 | const { ok, draining } = health; | |
| 166 | return { ok, draining }; | |
| 169 | 167 | } |
| 170 | 168 | // A probe without an actor keeps the forge's own shape: no parts, no memory class. |
| 171 | 169 | if (actor === undefined) return health; |
src/tui/screens/system.ts +3 −1
| @@ -124,7 +124,9 @@ const capOf = (g: SystemView["groups"][number]): string => | ||
| 124 | 124 | * incidents, so it never has a second line. |
| 125 | 125 | */ |
| 126 | 126 | export function forgeLines(h: ReturnType<typeof readHealth>, inner = WIDTH - 6): string[] { |
| 127 | const head = `forge ${h.version} · ${h.commit === null ? "no commit" : h.commit.slice(0, 7)} · ${h.draining ? "draining" : "serving"}`; | |
| 127 | const serving = h.draining ? "draining" : "serving"; | |
| 128 | // A stranger is told no version or commit (#16262). | |
| 129 | const head = "version" in h ? `forge ${h.version} · ${h.commit === null ? "no commit" : h.commit.slice(0, 7)} · ${serving}` : `forge · ${serving}`; | |
| 128 | 130 | if (!("incidents" in h)) return [head]; |
| 129 | 131 | const full = h as ForgeHealth; |
| 130 | 132 | const rollout = rolloutLine(full); |
test/app-release-15497.test.ts +6 −1
| @@ -16,6 +16,7 @@ import { serve, type Servers } from "../src/http/server.ts"; | ||
| 16 | 16 | import { appEnv } from "../src/apps/process.ts"; |
| 17 | 17 | import { newestRelease, releaseAt } from "../src/apps/release_at.ts"; |
| 18 | 18 | import { releaseOf, running } from "../src/kernel/version.ts"; |
| 19 | import { ownProbeHeaders } from "../src/kernel/probe.ts"; | |
| 19 | 20 | |
| 20 | 21 | const git = (cwd: string, ...args: string[]): string => { |
| 21 | 22 | const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "[email protected]", "-c", "tag.gpgSign=false", "-c", "commit.gpgSign=false", ...args], { cwd }); |
| @@ -125,7 +126,11 @@ describe("/api/v1/health on an unstamped production app", () => { | ||
| 125 | 126 | }); |
| 126 | 127 | |
| 127 | 128 | test("names the release its commit is at, not null", async () => { |
| 128 | const health = (await (await fetch(`${servers.url}/api/v1/health`)).json()) as Record<string, unknown>; | |
| 129 | // The commit and version go to the probe alone (#16262); the release number to anyone. | |
| 130 | const told = (await (await fetch(`${servers.url}/api/v1/health`)).json()) as Record<string, unknown>; | |
| 131 | expect(told["release"]).toBe("0.7.629"); | |
| 132 | expect(told["commit"]).toBeUndefined(); | |
| 133 | const health = (await (await fetch(`${servers.url}/api/v1/health`, { headers: ownProbeHeaders(dataDir) })).json()) as Record<string, unknown>; | |
| 129 | 134 | expect(health["release"]).toBe("0.7.629"); |
| 130 | 135 | expect(health["commit"]).toBe("1701de1790eb21474f584fed5b02accf0b839434"); |
| 131 | 136 | expect(health["version"]).toBe("dev"); |
test/health-schedules.test.ts +7 −2
| @@ -14,6 +14,7 @@ import { createUser } from "../src/core/users.ts"; | ||
| 14 | 14 | import { OVERDUE_AFTER_MS, overdueSchedules, recordRun, setPaused, scheduleTimer, syncSchedules } from "../src/core/timers.ts"; |
| 15 | 15 | import { releaseOf, running, UNSTAMPED } from "../src/kernel/version.ts"; |
| 16 | 16 | import { serve, type Servers } from "../src/http/server.ts"; |
| 17 | import { ownProbeHeaders } from "../src/kernel/probe.ts"; | |
| 17 | 18 | import { openapi } from "../src/contract/openapi.ts"; |
| 18 | 19 | |
| 19 | 20 | let dataDir: string; |
| @@ -74,7 +75,7 @@ test("a schedule due inside the loop's slack is not overdue; one past it is, wit | ||
| 74 | 75 | |
| 75 | 76 | const text = await strangerHealth(); |
| 76 | 77 | const body = JSON.parse(text) as { schedules: { overdue: number; oldestSeconds: number; total: number } }; |
| 77 | expect(Object.keys(body).sort()).toEqual(["commit", "draining", "ok", "release", "schedules", "version"]); | |
| 78 | expect(Object.keys(body).sort()).toEqual(["draining", "ok", "release", "schedules"]); | |
| 78 | 79 | expect(body.schedules.overdue).toBe(1); |
| 79 | 80 | expect(body.schedules.total).toBe(read.total); |
| 80 | 81 | expect(body.schedules.oldestSeconds).toBeGreaterThanOrEqual(read.oldestSeconds); |
| @@ -93,7 +94,11 @@ test("a paused schedule is not overdue", async () => { | ||
| 93 | 94 | }); |
| 94 | 95 | |
| 95 | 96 | test("a build with no release says release null, and version is unchanged (#13263)", async () => { |
| 96 | const body = JSON.parse(await strangerHealth()) as { version: unknown; release: unknown }; | |
| 97 | const told = JSON.parse(await strangerHealth()) as { version: unknown; release: unknown }; | |
| 98 | expect(told.release).toBeNull(); | |
| 99 | // The version goes to the probe alone (#16262), as the swap and the keeper send it. | |
| 100 | const res = await fetch(servers.url + "/api/v1/health", { headers: ownProbeHeaders(dataDir) }); | |
| 101 | const body = (await res.json()) as { version: unknown; release: unknown }; | |
| 97 | 102 | // The test forge is built from no release: version keeps its word for the swap and the |
| 98 | 103 | // keeper, release says there is none rather than passing that word off as a version. |
| 99 | 104 | expect(body.version).toBe(running().version); |
test/health.test.ts +12
| @@ -136,6 +136,18 @@ describe("the served paths", () => { | ||
| 136 | 136 | } |
| 137 | 137 | }); |
| 138 | 138 | |
| 139 | test("a stranger hears ok and draining; the probe also hears version and commit (#16262)", async () => { | |
| 140 | for (const path of ["/api/v1/health", "/health"]) { | |
| 141 | for (const headers of [{}, { "x-forge-probe": "guess" }]) { | |
| 142 | const told = (await (await fetch(`${servers.url}${path}`, { headers })).json()) as Record<string, unknown>; | |
| 143 | expect(Object.keys(told).sort()).toEqual(["draining", "ok", "release", "schedules"]); | |
| 144 | } | |
| 145 | const probed = (await (await fetch(`${servers.url}${path}`, { headers: ownProbeHeaders(dataDir) })).json()) as Record<string, unknown>; | |
| 146 | expect(probed["version"]).toBe(running().version); | |
| 147 | expect(probed["commit"]).toBe(running().commit); | |
| 148 | } | |
| 149 | }); | |
| 150 | ||
| 139 | 151 | test("a drain turns /readyz into 503; /healthz and the landing page stay up", async () => { |
| 140 | 152 | expect((await fetch(`${servers.url}/readyz`)).status).toBe(200); |
| 141 | 153 | startDraining(recordingLog(), "SIGTERM"); |
test/status-page.test.ts +3 −1
| @@ -4,6 +4,7 @@ import { tmpdir } from "node:os"; | ||
| 4 | 4 | import { join } from "node:path"; |
| 5 | 5 | import { createApp, type App } from "../src/app.ts"; |
| 6 | 6 | import { serve, type Servers } from "../src/http/server.ts"; |
| 7 | import { ownProbeHeaders } from "../src/kernel/probe.ts"; | |
| 7 | 8 | import { asOfWords, rowWords, statusJson, statusOf, statusReuse, statusWords, type StatusInput } from "../src/core/status_words.ts"; |
| 8 | 9 | import { statusBuilds } from "../src/web/pages/status.ts"; |
| 9 | 10 | import { createForgeApp, forgeCommands, Session } from "../src/tui/forge.ts"; |
| @@ -219,7 +220,8 @@ describe("GET /status", () => { | ||
| 219 | 220 | process.env["FORGE_VERSION"] = "v9.8.7"; |
| 220 | 221 | try { |
| 221 | 222 | const s = (await (await fetch(`${base}/status`, { headers: { accept: "application/json" } })).json()) as Record<string, unknown>; |
| 222 | const h = (await (await fetch(`${base}/api/v1/health`)).json()) as Record<string, unknown>; | |
| 223 | // The commit goes to the probe alone on health (#16262); /status says it to anyone. | |
| 224 | const h = (await (await fetch(`${base}/api/v1/health`, { headers: ownProbeHeaders(dir) })).json()) as Record<string, unknown>; | |
| 223 | 225 | expect(s["commit"]).toBe(commit); |
| 224 | 226 | expect(h["commit"]).toBe(commit); |
| 225 | 227 | expect(s["short"]).toBe("0123456"); |
test/tui-system.test.ts +2 −2
| @@ -442,9 +442,9 @@ describe("tui system: the forge's own state (#7296)", () => { | ||
| 442 | 442 | } |
| 443 | 443 | }); |
| 444 | 444 | |
| 445 | test("a stranger's answer, as MCP gives it, never has a second line", async () => { | |
| 445 | test("a stranger's answer, as MCP gives it, never has a second line, version or commit (#16262)", async () => { | |
| 446 | 446 | await seed({ down: "the edge answered 502" }); |
| 447 | expect(forgeLines(readHealth(app, undefined))).toEqual(["forge 9.8.7 · 0123456 · serving"]); | |
| 447 | expect(forgeLines(readHealth(app, undefined))).toEqual(["forge · serving"]); | |
| 448 | 448 | }); |
| 449 | 449 | }); |
| 450 | 450 |
test/version.test.ts +7 −3
| @@ -235,8 +235,12 @@ describe("where the stamp is read", () => { | ||
| 235 | 235 | await rm(dataDir, { recursive: true, force: true }); |
| 236 | 236 | }); |
| 237 | 237 | |
| 238 | test("the health report says the stamp to anyone who asks", async () => { | |
| 239 | const health = (await (await fetch(`${base}/api/v1/health`)).json()) as any; | |
| 238 | test("the health report says the stamp to anyone signed in, and not to a stranger (#16262)", async () => { | |
| 239 | const told = (await (await fetch(`${base}/api/v1/health`)).json()) as any; | |
| 240 | expect([told.version, told.commit]).toEqual([undefined, undefined]); | |
| 241 | const health = (await ( | |
| 242 | await fetch(`${base}/api/v1/health`, { headers: { authorization: `Bearer ${memberToken}` } }) | |
| 243 | ).json()) as any; | |
| 240 | 244 | expect([health.version, health.commit]).toEqual(["9.8.7", COMMIT]); |
| 241 | 245 | // A site admin's fuller answer says the same. |
| 242 | 246 | const full = (await ( |
| @@ -330,7 +334,7 @@ describe("where the stamp is read", () => { | ||
| 330 | 334 | stamp(); |
| 331 | 335 | try { |
| 332 | 336 | const health = (await ( |
| 333 | await fetch(`${base}/api/v1/health`) | |
| 337 | await fetch(`${base}/api/v1/health`, { headers: { authorization: `Bearer ${memberToken}` } }) | |
| 334 | 338 | ).json()) as any; |
| 335 | 339 | expect([health.version, health.commit]).toEqual(["dev", null]); |
| 336 | 340 | const init = await mcp(memberToken, "initialize", { |
test/vitals.test.ts +1 −1
| @@ -115,7 +115,7 @@ test("a site admin with a read-only token gets the shape; others get the short o | ||
| 115 | 115 | expect(short["rollout"]).toBeDefined(); |
| 116 | 116 | // A stranger is told whether it is well, and no more (#2917). |
| 117 | 117 | const stranger = (await (await health()).json()) as Record<string, unknown>; |
| 118 | expect(Object.keys(stranger).sort()).toEqual(["commit", "draining", "ok", "release", "schedules", "version"]); | |
| 118 | expect(Object.keys(stranger).sort()).toEqual(["draining", "ok", "release", "schedules"]); | |
| 119 | 119 | expect((await fetch(servers.url + "/healthz")).status).toBe(200); |
| 120 | 120 | }); |
| 121 | 121 |
new above
offline