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
2 changes: 2 additions & 0 deletions .fallowrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"@fontsource-variable/geist",
"@fontsource-variable/geist-mono",
"recharts",
"@tanstack/react-table",
"@tanstack/react-virtual",
// Recharts' peer dependency: installed for it, never imported by the console itself.
"react-is"
],
Expand Down
34 changes: 31 additions & 3 deletions docs/CONSOLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ the leases held and how many expire within 15 minutes. A long id, such as a
lease's, is cut to fit its column; point at it to see it whole, or open its
page.

## Long lists

Every table of workers, devices, leases, requests or attention items shows 25
rows at a time. Under it, the pager says which rows you
see, such as `26–50 of 1,240`, and has **Previous**, **Next**, the page
number, and **Per page**: 25, 50 or 100. When everything fits on one page,
there is no pager. (The **Minute by minute** table under a chart always lists
its 60 minutes.) The worker cards on **Workers** page the same way, 24 at a
time, or 48 or 96.

The page you are on is in the address, such as `/leases?page=3&size=50`, so
a reload or a link you share opens the same page. A page with two tables,
such as a worker's, keeps each one's page under its own name:
`?devices-page=2&leases-page=3`.

Rows keep their order as the page refreshes itself, so a row stays on its
page unless the list changes. When the list shrinks below the page you are
on, you see its last page instead. Leases are listed oldest first, by when
they were granted.

## Turn it on

The console comes with the HTTP API. It is on whenever `http.enabled` is
Expand Down Expand Up @@ -118,8 +138,9 @@ 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. **Minute by minute** under the
chart lists each minute's number. **Busiest workers** ranks the workers by
the leases each holds now.
chart lists each minute's number. **Busiest workers** ranks the five workers
holding the most leases now. With more than five workers, a link under it,
such as **All 12 workers**, takes you to the cards for the rest.

Select a worker to open its page. It adds:

Expand Down Expand Up @@ -256,7 +277,14 @@ whole payload.
devices, workers or components. **Other** lists the rest, such as
`daemon.started`.

The page keeps the newest 1000 events. Older ones drop off the end.
The events sit in a box of their own that scrolls; the page around it stays
put. Click in the box, or Tab to it, to scroll it with the keyboard. While
you are at the top of the box, new events push the list down, so the newest
is always in view. Once you scroll down to read, what you are reading stays
where it is, and a button at the top counts the events that came in since,
such as **3 new events**. Select it to go back to the top.

The page keeps the newest 10,000 events. Older ones drop off the end.

**Events per minute** charts how many of the events the page holds happened in
each minute of the last hour, whatever **Show** picks. **Minute by minute**
Expand Down
7 changes: 6 additions & 1 deletion docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ modes](#gateway-and-worker-modes-adr-0005) below for that topology.
(`ui/src/views/event-feed.ts`, behind `useRecentEvents()`) takes each
event off the stream through the live layer and loads `GET /v1/events`
itself, for the last hour and for each gap the stream left. The events view
lists it, and the workers view's lease chart counts back through it. See
lists it, and the workers view's lease chart counts back through it.
Every route still answers whole lists; the console pages them in the
browser. Every table of a view's items is `DataTable` (`ui/src/table.tsx`, on
`@tanstack/react-table`), which keeps its page in the URL's query through
`usePaging` (`ui/src/pager.tsx`); the events feed draws only the rows in
view, with `@tanstack/react-virtual`. See
[CONSOLE.md](../CONSOLE.md) for the user's side and
[DESIGN.md](DESIGN.md) for the style.
- **CLI**: by default it acquires a lease, prints one JSON result line on
Expand Down
30 changes: 28 additions & 2 deletions docs/internal/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,37 @@ scale; never a value between.
- **Table.** Fills its panel edge to edge. Headers are labels in
`--text-muted`. Rows are roomy, 16px above and below, with a 1px line
between them. Numbers, durations included, are mono and right-aligned.
Every table of a view's items is the one table component
(`ui/src/table.tsx`), so every such table pages the same way. A chart's
"Minute by minute" table is not one: it always has its 60 rows.
- **Pager.** Under a table, edge to edge in its panel, with a 1px `--border`
line above it like a row's: the rows shown of how many in mono (`26–50 of
1,240`), **Per page** as a select, then **Previous**, the page number in
mono `--text-muted` (`Page 2 of 50`), and **Next**, as secondary buttons.
It wraps on a phone. Under a grid of cards it is a bar of its own, a
`--surface` card with a `--border` edge. It is hidden when every row fits
on one page. At either end, the button that would leave the list keeps its
place and its focus, says so with `aria-disabled`, and goes quiet: its text
`--text-muted`, its edge `--border`.
- **Scroll box.** A long feed, such as the events, scrolls inside a box of
fixed height, `min(40rem, 70vh)`, edge to edge in its panel with a 1px
`--border` line above it; the page does not scroll with it. The box takes
focus, with its focus ring inside its edge, so the keyboard can scroll it.
Only the rows in view are drawn. A count of what arrived while the reader
was scrolled down ("3 new events") is a secondary button on `--bg`,
centred over the top of the box. It is outlined, not orange: orange never
says "new".
- **Long ids** (a lease's, a worker's, a device's) stay on one line, cut with
an ellipsis. The whole id is in the element's `title`, in the text a copy or
a screen reader reads, and on the details page.
- **Buttons.** Primary: filled `--accent` with `--on-accent` text. Secondary:
outlined in `--border-strong`, `--text`. Quiet: text only. All are labels.
- **Inputs.** A `--field` fill and a 1px `--border-strong` border.
- **Inputs.** A `--field` fill and a 1px `--border-strong` border. A select is
the same, 40px tall, in mono, with the browser's own arrow turned off
(`appearance: none`): it draws a small chevron in `--text`, two CSS
gradients 12px in from its right edge, and 32px of right padding keep its
value clear of it. It looks the same in every browser and both themes, and
needs no image, which the CSP would refuse.
- **Charts.** Drawn with Recharts, bundled like the rest. A line or columns in
`--accent`, an area with a faint fill of it (8%), horizontal grid lines in
`--border`, axis labels in Geist Mono `--text-muted`. Every colour comes from
Expand All @@ -168,7 +193,8 @@ scale; never a value between.
- From 768px a chart and the panel beside it share a row, two thirds and one
third; two panels of the same weight share it half and half.
- A list of things that each carry several facts, such as workers, is a grid
of cards, each a title and its facts as label and value pairs.
of cards, each a title and its facts as label and value pairs. It pages at
24, 48 or 96 cards, whole rows of the grid at two, three or four columns.

## Focus and keyboard

Expand Down
8 changes: 4 additions & 4 deletions e2e/console/attention.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async function openAttention(page: Page, daemon: RunningDaemon): Promise<void> {
/** The item for `condition` about the worker or device named `subject`. */
function item(page: Page, condition: string, subject: string): Locator {
return page
.locator(".attention-list li")
.locator(".attention-table tbody tr")
.filter({ has: page.locator(".status", { hasText: new RegExp(`^${condition}$`) }) })
.filter({ hasText: subject });
}
Expand Down Expand Up @@ -173,7 +173,7 @@ test.describe("the attention view", () => {
"href",
`/workers/${encodeURIComponent(b?.id ?? "")}`,
);
await expect(page.locator(".attention-list li")).toHaveCount(1);
await expect(page.locator(".attention-table tbody tr")).toHaveCount(1);
} finally {
await disposeFleet(fleet);
}
Expand Down Expand Up @@ -320,7 +320,7 @@ test.describe("the attention view", () => {
await expect(item(page, "quarantined", `Device ${quarantined?.id} on ${name}`)).toBeVisible();
await expect(item(page, "stalled", `Device ${stalled?.id} on ${name}`)).toBeVisible();
await expect(item(page, "over RAM budget", name)).toBeVisible();
await expect(page.locator(".attention-list li")).toHaveCount(3);
await expect(page.locator(".attention-table tbody tr")).toHaveCount(3);
} finally {
await host.dispose();
}
Expand Down Expand Up @@ -375,7 +375,7 @@ test.describe("the attention view", () => {

await openAttention(page, gateway);

await expect(page.locator(".attention-list li")).toHaveCount(1);
await expect(page.locator(".attention-table tbody tr")).toHaveCount(1);
expect(await hasHorizontalScroll(page)).toBe(false);
} finally {
hangUp();
Expand Down
45 changes: 32 additions & 13 deletions e2e/console/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,37 @@ function row(page: Page, name: string, value: string): Locator {
.filter({ has: page.locator("dd", { hasText: new RegExp(`^${value}$`) }) });
}

/** Each event the view shows, as its time, name and payload, in the order shown. */
/**
* Each event the view shows, as its time, name and payload, in the order shown. The feed draws
* only the rows in its box, so this scrolls it from the top to the bottom, reading each row as
* it is drawn, and back to the top.
*/
async function shownEvents(page: Page): Promise<string[]> {
return rows(page).evaluateAll((items) =>
items.map((item) =>
[
item.querySelector("time")?.getAttribute("datetime") ?? "",
item.querySelector(".event-name")?.textContent ?? "",
...[...item.querySelectorAll(".event-payload > div")].map(
(pair) =>
`${pair.querySelector("dt")?.textContent ?? ""}=${pair.querySelector("dd")?.textContent ?? ""}`,
),
].join(" "),
),
);
return page.getByRole("region", { name: "Event feed" }).evaluate(async (box) => {
const frame = () => new Promise((resolve) => requestAnimationFrame(resolve));
const seen = new Map<number, string>();
box.scrollTop = 0;
for (let step = 0; step < 1_000; step += 1) {
await frame();
for (const item of box.querySelectorAll("li.event")) {
seen.set(
Number(item.getAttribute("aria-posinset")),
[
item.querySelector("time")?.getAttribute("datetime") ?? "",
item.querySelector(".event-name")?.textContent ?? "",
...[...item.querySelectorAll(".event-payload > div")].map(
(pair) =>
`${pair.querySelector("dt")?.textContent ?? ""}=${pair.querySelector("dd")?.textContent ?? ""}`,
),
].join(" "),
);
}
if (box.scrollTop + box.clientHeight >= box.scrollHeight - 1) break;
box.scrollTop += box.clientHeight;
}
box.scrollTop = 0;
return [...seen.entries()].sort(([a], [b]) => a - b).map(([, shown]) => shown);
});
}

/** An event from the CLI, written as {@link shownEvents} reads the view: strings as themselves. */
Expand Down Expand Up @@ -182,6 +199,8 @@ test.describe("the events view", () => {
const started = await cliEvents(daemon);
await expect.poll(async () => (await shownEvents(page)).length, name).toBe(started.length);

// Every event, drawn as the feed scrolls past it, and the page as it stands.
expect((await shownEvents(page)).join("\n"), name).not.toContain(joinToken);
expect(await page.content(), name).not.toContain(joinToken);
expect(await page.locator("body").innerText(), name).not.toContain(joinToken);

Expand Down
3 changes: 3 additions & 0 deletions e2e/console/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface ConsoleDaemon {
/** A daemon a test drives itself: its CLI, and stopping and starting it in place. */
export interface RunningDaemon extends ConsoleDaemon {
readonly port: number;
/** The daemon's unix socket, for a test that drives it with the programmatic client. */
readonly socketPath: string;
cliBackground(args: readonly string[]): CliBackgroundHandle;
/** Replaces the fake driver's script. A daemon reads its host facts and catalog at start. */
writeDriverScript(script: FakeDriverScript): Promise<void>;
Expand Down Expand Up @@ -146,6 +148,7 @@ export async function startDaemon(
},
dispose,
port,
socketPath,
start,
stop,
tokens,
Expand Down
Loading
Loading