Skip to content

Commit 2cd147a

Browse files
committed
fix(health): normalize prober global status_counts
1 parent 2bcd5c1 commit 2cd147a

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/health-prober.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ export async function runHealthProber(env, ctx, overrides = {}) {
494494
await persistToKv(kv, probed, runAt);
495495

496496
const counts = { ok: 0, degraded: 0, failed: 0, unknown: 0 };
497-
for (const row of probed) counts[row.status] = (counts[row.status] || 0) + 1;
497+
for (const row of probed) counts[normalizeProbeStatus(row.status)] += 1;
498498
const durationMs = now() - runAt;
499499
// Wall-time guard: the prober runs on a 15-minute Cron Trigger, a hard CF
500500
// ceiling. As the autonomous flywheel grows surfaces, a sweep that creeps past
@@ -592,7 +592,7 @@ async function persistToD1(db, probed, runAt) {
592592
async function persistToKv(kv, probed, runAt) {
593593
if (!kv?.put) return;
594594
const counts = { ok: 0, degraded: 0, failed: 0, unknown: 0 };
595-
for (const row of probed) counts[row.status] = (counts[row.status] || 0) + 1;
595+
for (const row of probed) counts[normalizeProbeStatus(row.status)] += 1;
596596

597597
const surfaceRows = probed.map((row) => ({
598598
surface_id: row.surface_id,

tests/health-prober.test.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,48 @@ describe("runHealthProber", () => {
383383
assert.equal(meta.last_run_at, new Date(50000).toISOString());
384384
});
385385

386+
test("folds unrecognized probe status into unknown in global status_counts", async () => {
387+
const kv = makeKv();
388+
const result = await runHealthProber(
389+
{},
390+
{},
391+
{
392+
now: () => 60000,
393+
db: makeDb(),
394+
kv,
395+
loadSurfaces: async () => [SURFACES[0]],
396+
probeSurface: async () => ({
397+
status: "throttled",
398+
classification: "rate-limited",
399+
latency_ms: 120,
400+
status_code: 429,
401+
}),
402+
probeOptions: {},
403+
},
404+
);
405+
assert.deepEqual(result.counts, {
406+
ok: 0,
407+
degraded: 0,
408+
failed: 0,
409+
unknown: 1,
410+
});
411+
const current = kv.json(KV_HEALTH_CURRENT);
412+
assert.deepEqual(current.summary.status_counts, {
413+
ok: 0,
414+
degraded: 0,
415+
failed: 0,
416+
unknown: 1,
417+
});
418+
const meta = kv.json(KV_HEALTH_META);
419+
assert.deepEqual(meta.status_counts, {
420+
ok: 0,
421+
degraded: 0,
422+
failed: 0,
423+
unknown: 1,
424+
});
425+
assert.equal(current.summary.status_counts.throttled, undefined);
426+
});
427+
386428
test("rejects unsafe or implausibly high live RPC block heights", async () => {
387429
const kv = makeKv();
388430
const rpcSurfaces = [

0 commit comments

Comments
 (0)