diff --git a/docs/CONSOLE.md b/docs/CONSOLE.md index e1e1518ce..1aa849a08 100644 --- a/docs/CONSOLE.md +++ b/docs/CONSOLE.md @@ -140,19 +140,22 @@ The console opens on **Overview**: the whole fleet on one page. - **Tiles**: how full the fleet is (leases held, as a share of every running slot on connected workers), the leases held, the requests waiting and the longest wait, the workers connected of all, and the leases granted in the - last hour. A tile that has a page of its own opens it. + last hour. A tile that has a page of its own opens it. While a + worker's devices and leases are not known, the first two show a dash. - **Leases held, last hour**: a chart of how many leases were held at the end of each minute. It starts from the leases held now and counts back through the lease events of the last hour, the same events the Events page shows, so it can only go back as far as those. A lease that ends with no event, such as one on a worker removed from a gateway, is not counted back. The line under it says now, the highest and the lowest, and **Minute by minute** - lists each minute's number. + lists each minute's number. It says "Not reported." in the same case. - **Capacity**: per platform, the devices running of the limit, and a bar - split into leased, ready and booting. + split into leased, ready and booting. A dash stands in for the figures in + the same case. - **Workers**: a row per worker with its status square, a square per device slot (leased, ready, booting, quarantined, absent or free), its CPU and - memory, and the leases it holds. Select a worker to open it. + memory, and the leases it holds (a dash while they are not known). Select a + worker to open it. - **Attention** and **Activity**: what needs you, and the latest events. Each opens its own page. diff --git a/ui/src/model/overview.test.ts b/ui/src/model/overview.test.ts index 76239e186..e29bcbea6 100644 --- a/ui/src/model/overview.test.ts +++ b/ui/src/model/overview.test.ts @@ -61,6 +61,21 @@ const fleet = [ worker("down-1", [], { connection: "disconnected" }), ]; +// why: A worker whose uplink is open but which answers `starting`: its view carries no leases, no +// devices and no capacity, which is "not known" (ADR 0005, #365), not "none". A gateway sends +// exactly this view (test: "lists no device or lease for a worker that is starting..." in +// src/gateway/dispatcher.test.ts), and it holds whatever the console cannot see: its live leases. +function unread(id: string): WorkerView { + return { + connection: "connected", + drained: false, + health: "starting", + id, + label: id, + lastSeenAt: NOW, + } as unknown as WorkerView; +} + describe("the overview", () => { it("counts the fleet's headline figures from what the workers, the queue and the events say", () => { const requests = [{ createdAt: NOW - 74_000, id: "r1" }] as unknown as WaitingRequest[]; @@ -147,4 +162,58 @@ describe("the overview", () => { expect(workers[0]?.slotsLabel).toBe("2 leased, 1 ready, 3 free"); expect(workers[2]).not.toHaveProperty("cpu"); }); + + it("leaves the fleet's lease and device figures and the lease chart unknown, not zero, while a connected worker is starting", () => { + const events = [ + event(1, "lease.granted", NOW - 10 * 60 * 1_000), + event(2, "lease.granted", NOW - 9 * 60 * 1_000), + event(3, "lease.granted", NOW - 8 * 60 * 1_000), + ]; + + const alone = overviewOf({ events, now: NOW, requests: [], workers: [unread("mini-3")] }); + + expect(alone.tiles.map((tile) => [tile.label, tile.value])).toEqual([ + ["Utilisation", "—"], + ["Leases", "—"], + ["Waiting", "0"], + ["Workers", "1"], + ["Granted", "3"], + ]); + + expect(alone.minutes).toEqual([]); + expect(alone.chartSummary).toBe(""); + + expect(alone.platforms.map((p) => [p.name, p.running, p.limit])).toEqual([ + ["iOS", undefined, undefined], + ["Android", undefined, undefined], + ]); + + const row = alone.workers[0]; + expect(row).toBeDefined(); + expect(row).not.toHaveProperty("leases"); + expect(row?.slotsLabel).toBe("Not reported"); + + const reporting = worker("mini-1", [device("a", "leased", "ios"), device("b", "ready", "ios")]); + const mixed = overviewOf({ + events, + now: NOW, + requests: [], + workers: [reporting, unread("mini-3")], + }); + + expect(mixed.tiles.map((tile) => [tile.label, tile.value])).toEqual([ + ["Utilisation", "—"], + ["Leases", "—"], + ["Waiting", "0"], + ["Workers", "2"], + ["Granted", "3"], + ]); + expect(mixed.minutes).toEqual([]); + expect(mixed.chartSummary).toBe(""); + + expect(mixed.workers.map((r) => [r.name, r.leases, r.slotsLabel])).toEqual([ + ["mini-1", 1, "1 leased, 1 ready, 4 free"], + ["mini-3", undefined, "Not reported"], + ]); + }); }); diff --git a/ui/src/model/overview.ts b/ui/src/model/overview.ts index 9049291d4..3d0a3be1a 100644 --- a/ui/src/model/overview.ts +++ b/ui/src/model/overview.ts @@ -10,19 +10,19 @@ import { itemPath } from "./paths"; import { formatDuration } from "./time"; import type { Tone, Toned } from "./tones"; import type { WaitingRequest } from "./waiting"; -import { leasesHeld, type WorkerView, workerName, workerPath } from "./workers"; +import { isUnread, leasesHeld, type WorkerView, workerName, workerPath } from "./workers"; export interface OverviewTile { readonly label: string; readonly value: string; - readonly unit: string; + readonly unit?: string; readonly to?: string; } export interface PlatformUse { readonly name: string; - readonly running: number; - readonly limit: number; + readonly running?: number; + readonly limit?: number; readonly leasedPercent: number; readonly readyPercent: number; readonly busyPercent: number; @@ -43,7 +43,7 @@ export interface OverviewWorker { readonly slotsLabel: string; readonly cpu?: Gauge; readonly memory?: Gauge; - readonly leases: number; + readonly leases?: number; } export interface OverviewItem { @@ -82,6 +82,10 @@ function percentOf(part: number, whole: number): number { function platformUse(workers: readonly WorkerView[], platform: "ios" | "android"): PlatformUse { const live = workers.filter((worker) => worker.connection === "connected"); + const name = platform === "ios" ? "iOS" : "Android"; + if (workers.some(isUnread)) { + return { busyPercent: 0, leasedPercent: 0, name, readyPercent: 0 }; + } const limit = live.reduce((sum, worker) => sum + (worker.capacity?.[platform].limit ?? 0), 0); const devices = live.flatMap((worker) => (worker.devices ?? []).filter((device) => device.spec.platform === platform), @@ -95,7 +99,7 @@ function platformUse(workers: readonly WorkerView[], platform: "ios" | "android" busyPercent: percentOf(busy, limit), leasedPercent: percentOf(leased, limit), limit, - name: platform === "ios" ? "iOS" : "Android", + name, readyPercent: percentOf(ready, limit), running: leased + ready + busy, }; @@ -108,7 +112,7 @@ function gauge(percent: number | undefined): Gauge | undefined { } function overviewWorker(worker: WorkerView): OverviewWorker { - const slots = workerSlots(worker); + const slots = isUnread(worker) ? [] : workerSlots(worker); const gauges = worker.connection === "connected" && worker.load !== undefined ? loadGauges(worker.load) : {}; const cpu = gauge(gauges.cpu); @@ -116,11 +120,11 @@ function overviewWorker(worker: WorkerView): OverviewWorker { return { health: workerHealth(worker), id: worker.id, - leases: worker.leases?.length ?? 0, name: workerName(worker), slots, - slotsLabel: slotsLabel(slots), + slotsLabel: isUnread(worker) ? "Not reported" : slotsLabel(slots), to: workerPath(worker.id), + ...(worker.leases === undefined ? {} : { leases: worker.leases.length }), ...(cpu === undefined ? {} : { cpu }), ...(memory === undefined ? {} : { memory }), }; @@ -141,15 +145,25 @@ function tiles( now: number, ): readonly OverviewTile[] { const held = leasesHeld(workers); - const limit = platforms.reduce((sum, platform) => sum + platform.limit, 0); + const limit = platforms.reduce((sum, platform) => sum + (platform.limit ?? 0), 0); const connected = workers.filter((worker) => worker.connection === "connected").length; const granted = events.filter( (event) => event.event === "lease.granted" && event.timestamp > now - HOUR, ).length; const oldest = Math.min(...requests.map((request) => request.createdAt)); + const unknown = held === undefined; return [ - { label: "Utilisation", unit: "%", value: String(Math.round(percentOf(held, limit))) }, - { label: "Leases", to: "/leases", unit: `of ${formatCount(limit)}`, value: formatCount(held) }, + { + label: "Utilisation", + ...(unknown ? {} : { unit: "%" }), + value: unknown ? "—" : String(Math.round(percentOf(held, limit))), + }, + { + label: "Leases", + to: "/leases", + ...(unknown ? {} : { unit: `of ${formatCount(limit)}` }), + value: unknown ? "—" : formatCount(held), + }, { label: "Waiting", to: "/waiting", @@ -176,7 +190,8 @@ export function overviewOf(input: { }): Overview { const { events, now, requests, workers } = input; const platforms = [platformUse(workers, "ios"), platformUse(workers, "android")]; - const minutes = leaseHistory(leasesHeld(workers), events, now); + const held = leasesHeld(workers); + const minutes = held === undefined ? [] : leaseHistory(held, events, now); return { activity: [...events] .sort((a, b) => b.seq - a.seq) diff --git a/ui/src/model/workers.ts b/ui/src/model/workers.ts index f05d4afc8..09e2059a5 100644 --- a/ui/src/model/workers.ts +++ b/ui/src/model/workers.ts @@ -38,7 +38,17 @@ export function capacityByPlatform( ]; } -export function leasesHeld(workers: readonly WorkerView[]): number { +// why: a connected worker that sends no `leases` or `devices` (it is starting) has not said what it +// holds; "not known" is not "none", so a fleet that includes one has no count. +export function isUnread(worker: WorkerView): boolean { + return ( + worker.connection === "connected" && + (worker.leases === undefined || worker.devices === undefined) + ); +} + +export function leasesHeld(workers: readonly WorkerView[]): number | undefined { + if (workers.some(isUnread)) return undefined; return workers.reduce((sum, worker) => sum + (worker.leases?.length ?? 0), 0); } diff --git a/ui/src/screens/overview/index.tsx b/ui/src/screens/overview/index.tsx index 4fb576282..fbe22069c 100644 --- a/ui/src/screens/overview/index.tsx +++ b/ui/src/screens/overview/index.tsx @@ -47,14 +47,20 @@ export function OverviewBody({ overview }: { readonly overview: Overview }) { - -

{overview.chartSummary}

- + {overview.minutes.length === 0 ? ( +

Not reported.

+ ) : ( + <> + +

{overview.chartSummary}

+ + + )}
@@ -87,21 +93,30 @@ export function OverviewBody({ overview }: { readonly overview: Overview }) { } function PlatformBar({ platform }: { readonly platform: PlatformUse }) { + const known = platform.running !== undefined && platform.limit !== undefined; return (

{platform.name} - {platform.running} of {platform.limit} running + {!known ? ( + — + ) : ( + <> + {platform.running} of {platform.limit} running + + )}

- + {known ? ( + + ) : null}
); } @@ -150,7 +165,7 @@ function WorkerTable({ workers }: { readonly workers: readonly OverviewWorker[] - {worker.leases} + {worker.leases ?? —} ))} diff --git a/ui/src/screens/overview/overview.test.tsx b/ui/src/screens/overview/overview.test.tsx index 01e3f133b..c47c20790 100644 --- a/ui/src/screens/overview/overview.test.tsx +++ b/ui/src/screens/overview/overview.test.tsx @@ -22,19 +22,32 @@ const quiet: Overview = { }; describe("the overview screen", () => { - it("says so in one line where a fleet has no workers, nothing needs attention and nothing happened", () => { + it("says so in one line where a fleet has no workers, no lease count, nothing needs attention and nothing happened", () => { const shown = text(renderToStaticMarkup()); expect(shown).toContain("No workers have connected."); + expect(shown).toContain("Not reported."); + expect(shown).not.toContain("Minute by minute"); expect(shown).toContain("Nothing needs attention."); expect(shown).toContain("No events in the last hour."); }); - it("names each worker's health in its square, and its devices in words beside the slots", () => { + it("names each worker's health in its square, its devices in words beside the slots, and a muted dash where a count is not known", () => { const html = renderToStaticMarkup( { slotsLabel: "1 leased, 1 free", to: "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/workers/w1", }, + { + health: { tone: "warn", word: "starting" }, + id: "w2", + name: "mac-mini-02", + slots: [], + slotsLabel: "Not reported", + to: "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/workers/w2", + }, ], }} />, @@ -57,5 +78,9 @@ describe("the overview screen", () => { expect(html).toContain('role="img" aria-label="1 leased, 1 free"'); expect(html).toContain('href="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/workers/w1"'); expect(text(html)).not.toContain("memory 88%"); + expect(html).toContain('—'); + expect(html).toContain('—

'); + expect(text(html)).toContain("2 of 4 running"); + expect(html.match(/class="share-bar"/g)).toHaveLength(1); }); });