fixup! feat(status): a status page, for the phone of whoever looks after the box
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
booting: a ready counts unless it's from before the latest outage the server saw. The box's services restart together, so the button's ready can come before the next check sees the IR port up; comparing ready with when the port came up read that as booting, until the next ready. A server restarted while the box stayed up did the same. Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
c335935e2d
commit
f35da9b883
2 files changed
+25
-3
No files matched your search
+7
-3
@@ -24,7 +24,7 @@ const fromButton = (source) => source.endsWith('-button');
|
||||
|
||||
/**
|
||||
* @typedef {{ at: number, kind: string, source: string, reason?: string, code?: string, times?: number }} Event
|
||||
* @typedef {{ name: string, up: boolean, at: number, since: number }} Check
|
||||
* @typedef {{ name: string, up: boolean, at: number, since: number, outage?: number }} Check outage: when the latest outage we saw began
|
||||
* @typedef {{ conversations: number, turns: number, huh: number, interrupts: number, irPresses: number, looks: number }} Tally
|
||||
* @typedef {{ word: string, since?: number, why?: string }} State
|
||||
* @typedef {{ state: State, heartbeat?: number, checks: (typeof CHECKS[number] & Partial<Check>)[], today: Tally, total: Tally, recent: Event[] }} Summary
|
||||
@@ -82,7 +82,9 @@ export class Status {
|
||||
/** @param {string} name @param {boolean} up @param {number} at */
|
||||
check(name, up, at) {
|
||||
const prev = this.#checks.get(name);
|
||||
this.#checks.set(name, { name, up, at, since: prev && prev.up === up ? prev.since : at });
|
||||
const since = prev && prev.up === up ? prev.since : at;
|
||||
const outage = up ? prev?.outage : since;
|
||||
this.#checks.set(name, { name, up, at, since, ...(outage === undefined ? {} : { outage }) });
|
||||
}
|
||||
|
||||
size() { return this.#events.length; }
|
||||
@@ -93,7 +95,9 @@ export class Status {
|
||||
if (!up) return { word: 'not checked yet' };
|
||||
if (!up.up) return { word: 'unreachable', since: up.since };
|
||||
const ready = this.#events.findLast((e) => e.kind === 'ready');
|
||||
if (!ready || ready.at < up.since) return { word: 'booting', since: up.since };
|
||||
// Services restart together, so ready can come before the check sees the box up again: a ready
|
||||
// counts unless it's from before the latest outage we saw.
|
||||
if (!ready || ready.at < (up.outage ?? -Infinity)) return { word: 'booting', since: up.since };
|
||||
const alive = Math.max(this.#heartbeat ?? 0, this.#events.findLast((e) => fromButton(e.source))?.at ?? 0);
|
||||
if (now - alive > 3 * HEARTBEAT_MS) return { word: 'not responding', since: alive, why: 'no heartbeat from its button service' };
|
||||
const last = this.#events.findLast((e) => e.kind === 'conversation' || e.kind === 'end');
|
||||
|
||||
@@ -41,6 +41,24 @@ test('a ready from before the box went away does not count: booting', () => {
|
||||
assert.equal(s.summary(4 * MIN).state.word, 'booting');
|
||||
});
|
||||
|
||||
test('a ready during the outage counts: services restart together, and the check sees the box up last', () => {
|
||||
const s = new Status(dayOf);
|
||||
s.check('box', true, 0);
|
||||
s.record({ at: 1 * MIN, kind: 'ready', source: 'pdtv26-button' });
|
||||
s.check('box', false, 2 * MIN);
|
||||
s.record({ at: 2.5 * MIN, kind: 'ready', source: 'pdtv26-button' });
|
||||
s.check('box', true, 3 * MIN);
|
||||
assert.deepEqual(s.summary(4 * MIN).state, { word: 'ready for duty', since: 2.5 * MIN });
|
||||
});
|
||||
|
||||
test('a ready from before the server started counts, if the server saw no outage', () => {
|
||||
const s = new Status(dayOf);
|
||||
s.record({ at: 1 * MIN, kind: 'ready', source: 'pdtv26-button' });
|
||||
s.check('box', true, 10 * MIN);
|
||||
s.beat(10.5 * MIN);
|
||||
assert.deepEqual(s.summary(11 * MIN).state, { word: 'ready for duty', since: 1 * MIN });
|
||||
});
|
||||
|
||||
test('checks keep when they last changed', () => {
|
||||
const s = new Status(dayOf);
|
||||
s.check('brain', true, 1 * MIN);
|
||||
|
||||
Reference in new issue
Block a user