Public: anyone can read this; the crew can change it.

A machine's containers in the cloud tree read as a table: name, state, CPU, memory, started #17954

opened this

Merged 18h 30m ago, live in production

mason/forge:mason/17951-a-machine-s-containers-in-the-cloud-tree → main 0 commits fork 1 thread · 1 unresolved

  • Merged. mason/17951-a-machine-s-containers-in-the-cloud-tree was merged into main as ccd2925.

Review

Sign in to review this change.
5 files changed +52 −4
docs/features/infra.md +1 −1
@@ -109,7 +109,7 @@ Every DigitalOcean and Hetzner account is read into provider ▸ account ▸ pro
109109 - **Changed with the shared language:** `!web` and `!machine:i-111` negate and a leading `"` quotes (both were part of the word); `sort:`, `group:` and `created:` were text; `cost:=10`, `cost:>10,=20` and `cost:>10,<5` were refused; a sign left out and a long line's rest are now said; over MCP `cost:abc` and `cost:none` listed everything and are refused. `test/cloud-filter-lines.test.ts` holds each, and every line that kept its rows.
110110 - **A resource** is at `/infra/-/<cloud>/<account>/<project>/<id>`, beside the tree, or full width on a phone: cost, state, what it is attached to and what it holds (an address its balancer, NAT gateway or task; an ECS service its balancer and cluster; a balancer the services known behind it, "Shared by" when there are several; a link AWS does not state is not drawn, which does not mean nothing uses it), an AWS list price's day, what it leaves out and whose file it is (or why there is none), the app an AWS resource is part of and how that is known (nothing when it is not), what it was made from, who made it, when it was created, when it was read, and Ask about this (a talk with those facts, fenced as data).
111111 - **Created.** An EC2 instance's is when its primary network interface was attached, which is its first launch: AWS's `launchTime` is its last start and is not shown. "not known" when the cloud does not state a date, or the forge does not read one (an AWS address, function, table, cluster or zone). An S3 bucket's is "Created, or last changed", because AWS moves it when the bucket changes, its policy for one; a filter by `created:` uses that date all the same.
112 - **Containers.** A machine that is a game box opens into its containers (`src/cloud/containers.ts`), at `/infra/-/<cloud>/<account>/<project>/machine:<id>/container:<name>`: state, health, CPU, memory, how long it has been up, its image (the box owner's only) and a link to its page under /games, where it is changed. It is what the box's last full sync wrote, and nothing is asked of the box. The sync carries `upSince`, `memLimitMiB` and `cpuLimit` for each service, from one `docker inspect` that asks for those fields by name and never the whole answer, which holds the env (`services` in `src/games/agent.sh`): a limit of 0 is "no limit set", and one left out (an older agent) is "not known", as is a value out of its range. Without `upSince` the uptime is the diagnosis' word. "not known" is also said of figures the box could not measure, and of everything once the box is silent for two minutes ("not known: running 3 hours ago"). A container is in no count and no sum. The machine is the one the box's own row names, never found by name. Who sees which follows the games roles, and nobody sees the waker. A held box (docs/features/games.md) says so on its machine: in its row, and first in its facts with the next step.
112 - **Containers.** A machine that is a game box opens into its containers (`src/cloud/containers.ts`), at `/infra/-/<cloud>/<account>/<project>/machine:<id>/container:<name>`: state, health, CPU, memory, how long it has been up, its image (the box owner's only) and a link to its page under /games, where it is changed. It is what the box's last full sync wrote, and nothing is asked of the box. The sync carries `upSince`, `memLimitMiB` and `cpuLimit` for each service, from one `docker inspect` that asks for those fields by name and never the whole answer, which holds the env (`services` in `src/games/agent.sh`): a limit of 0 is "no limit set", and one left out (an older agent) is "not known", as is a value out of its range. Without `upSince` the uptime is the diagnosis' word. "not known" is also said of figures the box could not measure, and of everything once the box is silent for two minutes ("not known: running 3 hours ago"). A container is in no count and no sum. The machine is the one the box's own row names, never found by name. Who sees which follows the games roles, and nobody sees the waker. A held box (docs/features/games.md) says so on its machine: in its row, and first in its facts with the next step. A machine's pane lists its containers as one table, on the page and in the terminal alike (`CONTAINER_COLUMNS`, `containerCell`): name (a link to the container), state, CPU limit, memory limit and started, as an ago. A value not known, or no limit set, is an em dash, never 0.
113113 - **File.** A machine and a container have two tabs, Facts and File (`?tab=file`; `[` and `]` in the terminal). File says which lines of which file declare the thing, links to them, and says whether that agrees with what the forge knows (`src/cloud/declared_in.ts`, `declared_read.ts`). Two kinds of file are read: an app's `infra.json`, against the forge's own record of the machine (the cloud is not asked), and a game box's compose file, against the commit the box last said it runs. When the branch is at another commit the tab says so, since its lines may not be what runs; a silent box is "not known". Of a service it shows the image, ports, volumes and the names of its environment, never a value. A thing in neither file is "in no file the forge reads", one that is part of a stack is "not known", and one in a repository the reader may not read is "in a file you cannot read", with nothing of it shown. The join goes through the forge's own rows and never by a resource's name. On the branch that is followed, the file's own page says to a forge admin "Declares 3: …" with a link to each node; to anyone else it is as before. Nothing is written.
114114 - **Keys.** j and k move, Enter opens, h and l (or the arrows) close and open, `/` filters and Enter goes to the first match.
115115 - **States.** No account (a link to /settings/cloud), not read yet, a failed read (one line: when, why, and how old what is shown is), a kind that could not be read with its reason (on its project and on the account, which says where; under the headline's sum, "Not everything is listed: 1 kind not read" links to that account, and text doors name it; a billed account's gaps count too, and change no sum), and a reading older than three of its duty's intervals. A project's note ("R2 is not switched on for this account") is a plain line and no trouble, on its account too when that has one project. **Check the account** (`a` in the terminal) opens the account: see [Cloud accounts](cloud.md#what-was-not-read-17637).
src/cloud/containers.ts +24
@@ -24,6 +24,12 @@ export interface Container {
2424 readonly health: string;
2525 readonly cpu: string;
2626 readonly memory: string;
27 /** "2 cores": empty when none is set or it is not known. */
28 readonly cpuLimit: string;
29 /** "2.0 GiB": empty when none is set or it is not known. */
30 readonly memoryLimit: string;
31 /** When it last started, as the box said; empty when that is not known. */
32 readonly startedAt: string;
2733 readonly uptime: string;
2834 /** Memory, CPU and uptime in one short line, as /games says them. */
2935 readonly brief: string;
@@ -83,6 +89,9 @@ export function containersIn(db: Database, viewer: User | undefined, box: GameBo
8389 health: silent ? "" : s.health,
8490 cpu: figure(measured || s.cpuLimit !== null ? `${measured ? `${s.cpuPct.toFixed(1)}% of one core` : UNKNOWN}${limitWords(s.cpuLimit, cores)}` : UNKNOWN),
8591 memory: figure(measured || s.memLimitMiB !== null ? `${measured ? mib(s.memMiB) : UNKNOWN}${limitWords(s.memLimitMiB, mib)}${has > 0 && !s.memLimitMiB ? `; its machine has ${mib(has)}` : ""}` : UNKNOWN),
92 cpuLimit: silent || !s.cpuLimit ? "" : cores(s.cpuLimit),
93 memoryLimit: silent || !s.memLimitMiB ? "" : mib(s.memLimitMiB),
94 startedAt: silent || s.state !== "running" || s.upSince === null ? "" : s.upSince,
8695 uptime: figure(up ?? UNKNOWN),
8796 brief: briefOf(s, silent, up),
8897 image: owner ? (ps?.image ?? "") || UNKNOWN : "",
@@ -92,6 +101,21 @@ export function containersIn(db: Database, viewer: User | undefined, box: GameBo
92101 });
93102 }
94103
104 /** The columns of a machine's containers, on the page and in the terminal. */
105 export const CONTAINER_COLUMNS = [
106 { field: "name", label: "Name" },
107 { field: "state", label: "State" },
108 { field: "cpu", label: "CPU limit" },
109 { field: "memory", label: "Memory limit" },
110 { field: "started", label: "Started" },
111 ] as const;
112
113 /** One cell as text; a value not known is an em dash, never 0. */
114 export function containerCell(c: Container, field: string, now: number): string {
115 const text = field === "name" ? c.name : field === "state" ? c.state : field === "cpu" ? c.cpuLimit : field === "memory" ? c.memoryLimit : field === "started" ? (c.startedAt === "" ? "" : agoWords(c.startedAt, now)) : "";
116 return text === "" ? "—" : text;
117 }
118
95119 /** The line under a server's state on its own page. It always says something, so what is below it stays put on a start or a stop. */
96120 export function figuresOf(db: Database, viewer: User | undefined, box: GameBox, service: string): string {
97121 const c = containersIn(db, viewer, box).find((x) => x.name === service);
src/tui/screens/cloudtree.ts +2 −1
@@ -9,6 +9,7 @@ import { cloudResources, readProjectsNow } from "../../actions/infra.ts";
99 import { cloudCell, CLOUD_COLUMNS, cloudName, CONTAINER_COST, containersSay, costLine, createdLabel, cutSays, factsOf, findingOf, isStale, largestCosts, listedOf, moneyMark, nodeAt, orderSays, readingOf, tabOf, tabsOf, unreadAccounts, unreadLine, unpricedSays, type CloudNode, type CloudView, type NodeTab } from "../../cloud/tree.ts";
1010 import { noFileSays, placeSays } from "../../cloud/declared_in.ts";
1111 import { filesByNode } from "../../cloud/declared_read.ts";
12 import { CONTAINER_COLUMNS, containerCell } from "../../cloud/containers.ts";
1213 import { dollars } from "../../cloud/prices.ts";
1314 import { keyOf } from "../../web/keymap.ts";
1415 import type { Ctx, Screen } from "../app/app.ts";
@@ -69,7 +70,7 @@ export function cloudLines(v: CloudView, n: CloudNode, width = 80, tab: NodeTab
6970 const facts = factsOf(v.whole, n).map((f) => `${f.label.padEnd(12)} ${f.value}`);
7071 if (n.container !== undefined) return [...head, "", ...facts, read];
7172 if (n.resource !== undefined)
72 return [...head, "", ...facts, `${createdLabel(n.resource).padEnd(12)} ${n.resource.createdAt.slice(0, 10) || "not known"}`, read, ...(n.children.length === 0 ? [] : ["", containersSay(n), ...n.children.map((c) => `${c.name} · ${c.container!.state} · ${c.container!.memory}`)])];
73 return [...head, "", ...facts, `${createdLabel(n.resource).padEnd(12)} ${n.resource.createdAt.slice(0, 10) || "not known"}`, read, ...(n.children.length === 0 ? [] : ["", containersSay(n), ...tableLines(CONTAINER_COLUMNS.map((k) => ({ field: { name: k.field, type: "text" }, label: k.label })), v.q.line, n.children.map((c) => CONTAINER_COLUMNS.map((k) => containerCell(c.container!, k.field, v.now))), width)])];
7374 const goes = v.q.text === "" ? largestCosts(n, 6).filter((c) => c.from === "billed") : [];
7475 const line = (sum: string, words: string): string => `${sum.padStart(13)} ${words}`;
7576 const cut = cutSays(PANE_LINES, n.count - PANE_LINES, "/ narrows the filter", orderSays(v.q));
src/web/pages/cloud_tree.ts +5 −1
@@ -49,6 +49,7 @@ import {
4949 type Tie,
5050 type Trouble,
5151 } from "../../cloud/tree.ts";
52 import { CONTAINER_COLUMNS, containerCell } from "../../cloud/containers.ts";
5253 import { dollars } from "../../cloud/prices.ts";
5354 import { emptySection } from "../empty_words.ts";
5455 import { html, raw, type Html } from "../html.ts";
@@ -284,7 +285,10 @@ export function cloudPane(v: CloudView, n: CloudNode, tab: NodeTab = tabOf(n, nu
284285 <div><dt>Last read</dt><dd>${readLine(v, n)}</dd></div>
285286 ${facts.filter((f) => f.label === "Id").map((f) => html`<div><dt>${f.label}</dt><dd>${copyField("cloud-id", f.value, "The provider's id", "Copy the id")}</dd></div>`)}
286287 </dl>
287 ${n.children.length === 0 ? null : html`<h2>${containersSay(n)}</h2>${rowList(n.children.map((c) => row({ href: cloudHref(c.path, v.q), title: c.name, meta: html`${c.container!.state} · ${c.container!.memory}` })), { label: "Containers" })}`}
288 ${n.children.length === 0 ? null : html`<h2>${containersSay(n)}</h2><div class="table-scroll" role="region" tabindex="0" aria-label="Containers"><table class="table" data-dense>
outdated

Principle 1 and accessibility. (a) Give .table-scroll role="region" tabindex="0" aria-label="Containers", as forges.ts:208 does, so a phone user can scroll it by keyboard. (b) Remove the sr-only <caption> on the next line: it says what the <h2> already says (containersSay(n)), so the page explains itself twice.

289 <thead><tr>${CONTAINER_COLUMNS.map((k) => html`<th scope="col">${k.label}</th>`)}</tr></thead>
290 <tbody>${n.children.map((c) => html`<tr>${CONTAINER_COLUMNS.map((k) => html`<td>${k.field === "name" ? html`<a href="${cloudHref(c.path, v.q)}">${c.name}</a>` : containerCell(c.container!, k.field, v.now)}</td>`)}</tr>`)}</tbody>
291 </table></div>`}
288292 <div class="form-actions">${btn("Ask about this", { href: `/talk?about=${encodeURIComponent(`cloud:${n.path.join("/")}`)}` })}</div>
289293 </section>`;
290294 }
test/cloud-containers.test.ts +20 −1
@@ -283,7 +283,7 @@ test("the page: the machine's row opens, its pane lists them, and one container
283283 });
284284
285285 test("the terminal: the same rows and facts, by keys", async () => {
286 expect(cloudLines(view(), at(MACHINE)).join("\n")).toMatch(/3 containers\n.*fresh · running/);
286 expect(cloudLines(view(), at(MACHINE)).join("\n")).toMatch(/3 containers\nName +State +CPU limit +Memory limit +Started\nfresh +running/);
287287 const lines = cloudLines(view(), at(HUB)).join("\n");
288288 for (const [label, value] of Object.entries(facts(HUB))) expect(lines).toContain(`${label.padEnd(12)} ${value}`);
289289 const terminal = headlessTerminal(160, 40);
@@ -313,3 +313,22 @@ test("the infra tool and a talk take a container's id", async () => {
313313 expect(aboutContext(app.db, `cloud:${HUB.join("/")}`, alice)).toContain("uptime: 3 hours");
314314 expect(aboutContext(app.db, `cloud:${HUB.join("/")}`, bob)).toBe("");
315315 });
316
317 test("a machine's containers are one table: name, state, CPU limit, memory limit, started; a missing value is an em dash", async () => {
318 const hours = (n: number): string => new Date(Date.now() - n * 3_600_000).toISOString().replace("Z", "123456Z");
319 app.db.run("DELETE FROM game_service");
320 sync({ ...SYNC, services: [{ ...service("hub", "running", 12.5, 900), upSince: hours(26), memLimitMiB: 2048, cpuLimit: 1.5 }, service("survival", "exited", 0, 0)] });
321 const cells = (html: string): string[][] =>
322 [...html.split("<tbody>")[1]!.split("</tbody>")[0]!.matchAll(/<tr>(.*?)<\/tr>/gs)].map((r) => [...r[1]!.matchAll(/<td>(.*?)<\/td>/gs)].map((c) => c[1]!.replace(/<[^>]+>/g, "").trim()));
323 const page = await get(MACHINE);
324 expect(page).toContain('<th scope="col">CPU limit</th>');
325 expect(page).toContain('role="region" tabindex="0" aria-label="Containers"');
326 expect(page).toContain('<a href="/infra/-/hetzner/eu/games/machine:77/container:hub">hub</a>');
327 expect(cells(page)).toEqual([
328 ["hub", "running", "1.5 cores", "2.0 GiB", "26 hours ago"],
329 ["survival", "exited", "—", "—", "—"],
330 ]);
331 const text = cloudLines(view(), at(MACHINE), 100).join("\n");
332 expect(text).toMatch(/hub +running +1\.5 cores +2\.0 GiB +26 hours ago/);
333 expect(text).toMatch(/survival +exited +— +— +—/);
334 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs