Public: anyone can read this; the crew can change it.
An EC2 instance's date is its first launch, and a bucket's says it may be its last change #17737
Merged 18h 16m ago, live in production
sold/aws-date → main 0 commits
7 files
changed +48
−6
docs/features/infra.md +2 −1
| @@ -105,7 +105,8 @@ Every DigitalOcean and Hetzner account is read into provider ▸ account ▸ pro | ||
| 105 | 105 | - **Filter.** `/`, then `kind:volume cloud:aws attached:no cost:>10 text`. Properties: kind, cloud, account, project, region, size, name, state, attached, made, for, app, cost, created. `!` negates a term or a word (`!web`), a comma means any of, and the sign carries on over it (`cost:>10,20`) until a value has its own (`cost:>10,=20`). `cost:unknown` is a value, and `app:unknown` finds what has no app known, on any cloud, which does not mean nothing uses it. Quotes are literal: `name:"old web"` holds a space, and `region:"none"` is the word and not the empty value. `created:` takes an age (`<7d` is younger, `>7d` older, `s m h d w`) or a date (`>2026-12-01` is after that day, UTC unless it has an offset). `machine:i-111` is an id, read as text. It is in the URL as `?q=`. |
| 106 | 106 | - **A line that cannot be read whole** still draws rows, and the page and the terminal say what was made of it. An unknown property is text and the near one is named; a sign on a property without an order is left out; `sort:` and `group:` are words this list cannot do yet. A bad `cost:` or `created:`, and what is past 12 words or 200 characters, narrow nothing. The `infra` tool names the first sort in `problems` and refuses the second (`invalid_filter`, with the place). The language is `src/list/line.ts`, for every list to share. |
| 107 | 107 | - **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. |
| 108 | - **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 read, and Ask about this (a talk with those facts, fenced as data). | |
| 108 | - **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). | |
| 109 | - **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. | |
| 109 | 110 | - **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. "not known" is said of a limit (the agent does not send one), 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. |
| 110 | 111 | - **Keys.** j and k move, Enter opens, h and l (or the arrows) close and open, `/` filters and Enter goes to the first match. |
| 111 | 112 | - **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.md#what-was-not-read-17637). |
src/cloud/aws_read.ts +8 −1
| @@ -103,9 +103,16 @@ const words = (...parts: string[]): string => text(parts.filter((p) => p !== "") | ||
| 103 | 103 | const gib = (n: string): string => (n === "" ? "" : `${n} GiB`); |
| 104 | 104 | const none = { name: "", size: "", label: "", state: "", attachedTo: null, madeFrom: "", createdAt: "" } as const; |
| 105 | 105 | |
| 106 | /** | |
| 107 | * When an instance was first launched: its primary interface's attachment, as the EC2 API reference | |
| 108 | * says. `launchTime` is its last start, so it is never read as this; empty when not stated. | |
| 109 | */ | |
| 110 | const firstLaunch = (x: Xml): string => | |
| 111 | text(val(items(x, "networkInterfaceSet").find((c) => val(c, "attachment/deviceIndex") === "0" && ["", "0"].includes(val(c, "attachment/networkCardIndex"))) ?? x, "attachment/attachTime")); | |
| 112 | ||
| 106 | 113 | const machine = (region: string) => (x: Xml): Part => ({ |
| 107 | 114 | ...none, ...ec2Tags(x), kind: "machine", region, id: exactId(val(x, "instanceId")), |
| 108 | size: text(val(x, "instanceType")), state: text(val(x, "instanceState/name")), createdAt: text(val(x, "launchTime")), | |
| 115 | size: text(val(x, "instanceType")), state: text(val(x, "instanceState/name")), createdAt: firstLaunch(x), | |
| 109 | 116 | madeFrom: val(x, "imageId") === "" ? "" : `image:${exactId(val(x, "imageId"))}`, terms: machineTerms(x, region), |
| 110 | 117 | }); |
| 111 | 118 |
src/cloud/tree.ts +6
| @@ -224,6 +224,12 @@ const branch = (level: Level, path: readonly string[], name: string, kids: Cloud | ||
| 224 | 224 | empty: 0, |
| 225 | 225 | }); |
| 226 | 226 | |
| 227 | /** | |
| 228 | * What a resource's date is called: AWS says a bucket's "can change when making changes to your | |
| 229 | * bucket". | |
| 230 | */ | |
| 231 | export const createdLabel = (r: CloudResource): string => (r.provider === "aws" && r.kind === "bucket" ? "Created, or last changed" : "Created"); | |
| 232 | ||
| 227 | 233 | /** The provider's own id, without the kind before it. */ |
| 228 | 234 | const idOf = (r: CloudResource): string => r.id.slice(r.id.indexOf(":") + 1); |
| 229 | 235 |
src/tui/screens/cloudtree.ts +2 −2
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import { cloudResources, readProjectsNow } from "../../actions/infra.ts"; |
| 9 | import { cloudName, CONTAINER_COST, containersSay, costLine, costliestOf, cutSays, factsOf, findingOf, isStale, largestCosts, moneyMark, nodeAt, readingOf, unreadAccounts, unreadLine, unpricedSays, unused, type CloudNode, type CloudView } from "../../cloud/tree.ts"; | |
| 9 | import { cloudName, CONTAINER_COST, containersSay, costLine, costliestOf, createdLabel, cutSays, factsOf, findingOf, isStale, largestCosts, moneyMark, nodeAt, readingOf, unreadAccounts, unreadLine, unpricedSays, unused, type CloudNode, type CloudView } from "../../cloud/tree.ts"; | |
| 10 | 10 | import { dollars } from "../../cloud/prices.ts"; |
| 11 | 11 | import { keyOf } from "../../web/keymap.ts"; |
| 12 | 12 | import type { Ctx, Screen } from "../app/app.ts"; |
| @@ -51,7 +51,7 @@ export function cloudLines(v: CloudView, n: CloudNode): string[] { | ||
| 51 | 51 | const facts = factsOf(v.whole, n).map((f) => `${f.label.padEnd(12)} ${f.value}`); |
| 52 | 52 | if (n.container !== undefined) return [...head, "", ...facts, read]; |
| 53 | 53 | if (n.resource !== undefined) |
| 54 | return [...head, "", ...facts, `${"Created".padEnd(12)} ${n.resource.createdAt.slice(0, 10)}`, read, ...(n.children.length === 0 ? [] : ["", containersSay(n), ...n.children.map((c) => `${c.name} · ${c.container!.state} · ${c.container!.memory}`)])]; | |
| 54 | 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}`)])]; | |
| 55 | 55 | const goes = v.q.text === "" ? largestCosts(n, 6).filter((c) => c.from === "billed") : []; |
| 56 | 56 | const line = (sum: string, words: string): string => `${sum.padStart(13)} ${words}`; |
| 57 | 57 | const cut = cutSays(PANE_LINES, n.count - PANE_LINES, "/ narrows the filter"); |
src/web/pages/cloud_tree.ts +2 −1
| @@ -14,6 +14,7 @@ import { | ||
| 14 | 14 | CLOUD_PROPS, |
| 15 | 15 | cloudName, |
| 16 | 16 | costliestOf, |
| 17 | createdLabel, | |
| 17 | 18 | facetsOf, |
| 18 | 19 | readingOf, |
| 19 | 20 | isStale, |
| @@ -267,7 +268,7 @@ export function cloudPane(v: CloudView, n: CloudNode): Html { | ||
| 267 | 268 | ${sum(v, n)} |
| 268 | 269 | <dl class="cloud-facts"> |
| 269 | 270 | ${facts.filter((f) => f.label !== "Id").map((f) => html`<div><dt>${f.label}</dt><dd>${f.href !== undefined ? html`<a href="${f.href}">${f.value}</a>` : f.tie === undefined || f.tie.to.length === 0 ? f.value : ends(f.tie, v)}</dd></div>`)} |
| 270 | ${r === undefined || r.createdAt === "" ? null : html`<div><dt>Created</dt><dd>${time(r.createdAt, { date: true })}</dd></div>`} | |
| 271 | ${r === undefined ? null : html`<div><dt>${createdLabel(r)}</dt><dd>${r.createdAt === "" ? "not known" : time(r.createdAt, { date: true })}</dd></div>`} | |
| 271 | 272 | <div><dt>Last read</dt><dd>${readLine(v, n)}</dd></div> |
| 272 | 273 | ${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>`)} |
| 273 | 274 | </dl> |
test/cloud-inventory.test.ts +15 −1
| @@ -21,7 +21,7 @@ import projectsTables from "../src/core/migrations/20261201200000-cloud-projects | ||
| 21 | 21 | import inventoryTables from "../src/core/migrations/20261202184323-cloud-inventory.ts"; |
| 22 | 22 | import listPrices from "../src/core/migrations/20261202185423-cloud-list-prices.ts"; |
| 23 | 23 | import priceNote from "../src/core/migrations/20261202185456-cloud-price-note.ts"; |
| 24 | import { account, denied, deniedJson, recordedAws, timeout, type AwsAccount } from "./helpers/recorded-aws.ts"; | |
| 24 | import { account, denied, deniedJson, ec2, recordedAws, timeout, type AwsAccount } from "./helpers/recorded-aws.ts"; | |
| 25 | 25 | |
| 26 | 26 | let dir = ""; |
| 27 | 27 | let app: App; |
| @@ -49,6 +49,20 @@ const one = (id: string): CloudResource => all().find((r) => r.id === id)!; | ||
| 49 | 49 | describe("AWS", () => { |
| 50 | 50 | beforeEach(() => void attach("aws")); |
| 51 | 51 | |
| 52 | test("an instance was created when its first interface was attached, and its last launch is never that", async () => { | |
| 53 | // EC2 moves launchTime at each start; the API reference names the primary interface's attachTime. | |
| 54 | const card = (index: string, at: string, more = ""): string => `<item><networkInterfaceId>eni-${at}</networkInterfaceId><attachment><deviceIndex>${index}</deviceIndex><attachTime>${at}</attachTime>${more}</attachment></item>`; | |
| 55 | const instance = (id: string, cards: string): string => `<item><instanceId>${id}</instanceId><instanceState><name>running</name></instanceState><launchTime>2026-12-01T08:00:00.000Z</launchTime><networkInterfaceSet>${cards}</networkInterfaceSet></item>`; | |
| 56 | await aws({ | |
| 57 | ...account(), | |
| 58 | "ec2.us-east-1.amazonaws.com DescribeInstances": ec2( | |
| 59 | "DescribeInstances", | |
| 60 | `<reservationSet><item><instancesSet>${instance("i-old", card("1", "2025-05-05T00:00:00.000Z") + card("0", "2025-06-06T00:00:00.000Z", "<networkCardIndex>1</networkCardIndex>") + card("0", "2024-03-01T10:00:00.000Z", "<networkCardIndex>0</networkCardIndex>"))}${instance("i-plain", card("0", "2024-04-01T10:00:00.000Z"))}${instance("i-bare", "")}</instancesSet></item></reservationSet>`, | |
| 61 | ), | |
| 62 | }); | |
| 63 | expect(["i-old", "i-plain", "i-bare"].map((id) => one(`machine:${id}`).createdAt)).toEqual(["2024-03-01T10:00:00.000Z", "2024-04-01T10:00:00.000Z", ""]); | |
| 64 | }); | |
| 65 | ||
| 52 | 66 | test("every kind is read, every page followed, with its state and what uses it", async () => { |
| 53 | 67 | expect(await aws(account())).toEqual({ read: ["aws/main"], failed: [] }); |
| 54 | 68 | expect(projectsOf(app.db).map((p) => p.id)).toEqual(["global", "eu-west-1", "us-east-1"]); |
test/cloud-tree.test.ts +13
| @@ -651,6 +651,19 @@ test("the infra tool's list says what each resource is attached to: ids it can o | ||
| 651 | 651 | expect((await mcpTool(servers.url, token, "infra", { action: "list", id: "account:tied kind:machine" })).value.resources[0].attachedTo).toBeNull(); |
| 652 | 652 | }); |
| 653 | 653 | |
| 654 | test("a date says what it is: an S3 bucket's may be its last change, and one that is missing is not known", async () => { | |
| 655 | account("aws", "dates"); | |
| 656 | project("aws", "dates", "us-east-1"); | |
| 657 | for (const id of ["bucket:b-1", "machine:i-5", "machine:i-6"]) resource("aws", "dates", "us-east-1", id, -1); | |
| 658 | app.db.run("UPDATE cloud_resource SET created_at = '' WHERE cloud_resource_id = 'machine:i-6'"); | |
| 659 | for (const [id, label, value] of [["bucket:b-1", "Created, or last changed", "2026-01-02"], ["machine:i-5", "Created", "2026-01-02"], ["machine:i-6", "Created", "not known"]] as const) { | |
| 660 | const pane = await (await get(`/infra/-/aws/dates/us-east-1/${id}?fragment=1`)).text(); | |
| 661 | expect(pane).toMatch(new RegExp(`<dt>${label}</dt><dd>[^/]*${value}`)); | |
| 662 | expect(cloudLines(view(), at(view(), "aws", "dates", "us-east-1", id))).toContain(`${label.padEnd(12)} ${value}`); | |
| 663 | } | |
| 664 | app.db.run("DELETE FROM cloud_resource WHERE cloud_account_id = 'dates'"); | |
| 665 | }); | |
| 666 | ||
| 654 | 667 | test("strangers' text is text: markup in a name, a filter cut inside an emoji, a kind that is a word of JavaScript", async () => { |
| 655 | 668 | account("aws", "odd"); |
| 656 | 669 | project("aws", "odd", "us-east-1"); |
new above
offline