Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions docs/CONSOLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
69 changes: 69 additions & 0 deletions ui/src/model/overview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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"],
]);
});
});
41 changes: 28 additions & 13 deletions ui/src/model/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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,
};
Expand All @@ -108,19 +112,19 @@ 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);
const memory = gauge(gauges.memory);
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 }),
};
Expand All @@ -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",
Expand All @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion ui/src/model/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
49 changes: 32 additions & 17 deletions ui/src/screens/overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,20 @@ export function OverviewBody({ overview }: { readonly overview: Overview }) {
</StatRow>
<Row>
<Panel title="Leases held, last hour">
<MinuteChart
kind="area"
title="Leases held, last hour"
unit="leases held"
minutes={overview.minutes}
/>
<p className="chart-summary">{overview.chartSummary}</p>
<MinuteTable minutes={overview.minutes} heading="Leases held" />
{overview.minutes.length === 0 ? (
<p className="muted">Not reported.</p>
) : (
<>
<MinuteChart
kind="area"
title="Leases held, last hour"
unit="leases held"
minutes={overview.minutes}
/>
<p className="chart-summary">{overview.chartSummary}</p>
<MinuteTable minutes={overview.minutes} heading="Leases held" />
</>
)}
</Panel>
<Panel title="Capacity">
<div className="capacity">
Expand Down Expand Up @@ -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 (
<div className="platform">
<p className="platform-head">
<span>{platform.name}</span>
<span className="mono">
{platform.running} <span className="muted">of {platform.limit} running</span>
{!known ? (
<span className="muted">—</span>
) : (
<>
{platform.running} <span className="muted">of {platform.limit} running</span>
</>
)}
</span>
</p>
<ShareBar
shares={[
{ kind: "leased", percent: platform.leasedPercent },
{ kind: "ready", percent: platform.readyPercent },
{ kind: "busy", percent: platform.busyPercent },
]}
/>
{known ? (
<ShareBar
shares={[
{ kind: "leased", percent: platform.leasedPercent },
{ kind: "ready", percent: platform.readyPercent },
{ kind: "busy", percent: platform.busyPercent },
]}
/>
) : null}
</div>
);
}
Expand Down Expand Up @@ -150,7 +165,7 @@ function WorkerTable({ workers }: { readonly workers: readonly OverviewWorker[]
<GaugeCell gauge={worker.memory} />
</td>
<td data-label="Leases" className="num">
{worker.leases}
{worker.leases ?? <span className="muted">—</span>}
</td>
</tr>
))}
Expand Down
29 changes: 27 additions & 2 deletions ui/src/screens/overview/overview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<OverviewBody overview={quiet} />));

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(
<OverviewBody
overview={{
...quiet,
platforms: [
{ busyPercent: 0, leasedPercent: 0, name: "iOS", readyPercent: 0 },
{
busyPercent: 0,
leasedPercent: 50,
limit: 4,
name: "Android",
readyPercent: 0,
running: 2,
},
],
workers: [
{
health: { tone: "warn", word: "memory 88%" },
Expand All @@ -48,6 +61,14 @@ describe("the overview screen", () => {
slotsLabel: "1 leased, 1 free",
to: "/workers/w1",
},
{
health: { tone: "warn", word: "starting" },
id: "w2",
name: "mac-mini-02",
slots: [],
slotsLabel: "Not reported",
to: "/workers/w2",
},
],
}}
/>,
Expand All @@ -57,5 +78,9 @@ describe("the overview screen", () => {
expect(html).toContain('role="img" aria-label="1 leased, 1 free"');
expect(html).toContain('href="/workers/w1"');
expect(text(html)).not.toContain("memory 88%");
expect(html).toContain('<td data-label="Leases" class="num"><span class="muted">—</span></td>');
expect(html).toContain('<span class="muted">—</span></span></p>');
expect(text(html)).toContain("2 of 4 running");
expect(html.match(/class="share-bar"/g)).toHaveLength(1);
});
});
Loading