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

Cloud account digitalocean/prod shows more than the forge made #17857

opened this in answer to

Merged 30h 18m ago, live in production

torque/forge:torque/17849-cloud-account-digitalocean-prod-shows-mo → main 0 commits fork 3 threads · 3 unresolved

  • Merged. torque/17849-cloud-account-digitalocean-prod-shows-mo was merged into main as 137546a.

Review

Sign in to review this change.
2 files changed +31 −7
src/cloud/watch.ts +2 −2
@@ -121,7 +121,7 @@ export async function readLive(provider: string, f: Fetch, token: string, pause:
121121 if (per === undefined) throw new Error(`${provider} is not watched`);
122122 if (provider === "digitalocean") {
123123 const api = "https://api.digitalocean.com/v2";
124 const [d, v, w] = [await pages(f, token, `${api}/droplets`, "droplets", per, pause), await pages(f, token, `${api}/volumes`, "volumes", per, pause), await pages(f, token, `${api}/firewalls`, "firewalls", per, pause)];
124 const [d, v, w] = await Promise.all([pages(f, token, `${api}/droplets`, "droplets", per, pause), pages(f, token, `${api}/volumes`, "volumes", per, pause), pages(f, token, `${api}/firewalls`, "firewalls", per, pause)]);
125125 return [
126126 ...d.map((x): Seen => ({ kind: "machine", id: text(x.id), name: text(x.name), createdAt: text(x.created_at), datacenter: text(x.region?.slug), size: text(x.size_slug), gib: 0 })),
127127 ...v.map((x): Seen => ({ kind: "volume", id: text(x.id), name: text(x.name), createdAt: text(x.created_at), datacenter: text(x.region?.slug), size: "", gib: Number(x.size_gigabytes) || VOLUME_GIB })),
@@ -129,7 +129,7 @@ export async function readLive(provider: string, f: Fetch, token: string, pause:
129129 ];
130130 }
131131 const api = "https://api.hetzner.cloud/v1";
132 const [s, v, w] = [await pages(f, token, `${api}/servers`, "servers", per, pause), await pages(f, token, `${api}/volumes`, "volumes", per, pause), await pages(f, token, `${api}/firewalls`, "firewalls", per, pause)];
132 const [s, v, w] = await Promise.all([pages(f, token, `${api}/servers`, "servers", per, pause), pages(f, token, `${api}/volumes`, "volumes", per, pause), pages(f, token, `${api}/firewalls`, "firewalls", per, pause)]);
133133 return [
134134 ...s.map((x): Seen => ({ kind: "machine", id: text(x.id), name: text(x.name), createdAt: text(x.created), datacenter: text(x.datacenter?.location?.name), size: text(x.server_type?.name), gib: 0 })),
135135 ...v.map((x): Seen => ({ kind: "volume", id: text(x.id), name: text(x.name), createdAt: text(x.created), datacenter: text(x.location?.name), size: "", gib: Number(x.size) || VOLUME_GIB })),
test/cloud-watch-read.test.ts +29 −5
@@ -60,9 +60,10 @@ describe("paging", () => {
6060 test("a list that never ends fails as not read whole, never a partial pass", async () => {
6161 let n = 0;
6262 const read = readLive("hetzner", async (url) => {
63 // The three lists are read together: only servers never end, the others are empty.
64 if (!new URL(url).pathname.endsWith("servers")) return json({ volumes: [], firewalls: [] });
6365 n++;
64 const key = new URL(url).pathname.endsWith("servers") ? "servers" : "volumes";
65 return json({ [key]: Array.from({ length: 50 }, (_, i) => ({ id: n * 100 + i, name: "x" })) });
66 return json({ servers: Array.from({ length: 50 }, (_, i) => ({ id: n * 100 + i, name: "x" })) });
6667 }, "tok");
6768 await expect(read).rejects.toThrow("more than 500 servers: not read whole");
6869 expect(n).toBe(10);
@@ -87,7 +88,8 @@ describe("paging", () => {
8788 );
8889 expect(seen.map((s) => s.id)).toEqual(["1"]);
8990 expect(tries).toEqual({ "/v1/servers": 2, "/v1/volumes": 3, "/v1/firewalls": 2 });
90 expect(paused).toEqual([5_000, 5_000, 15_000, 5_000]);
91 // The lists are read together, so their pauses interleave.
92 expect([...paused].sort((a, b) => a - b)).toEqual([5_000, 5_000, 5_000, 15_000]);
9193 });
9294
9395 test("three misses in a row fail the read; a refusal is not tried again", async () => {
@@ -97,14 +99,36 @@ describe("paging", () => {
9799 throw new DOMException("The operation timed out.", "TimeoutError");
98100 }, "tok", async () => {});
99101 await expect(slow).rejects.toMatchObject({ name: "TimeoutError" });
100 expect(n).toBe(3);
102 // Three tries at each of the three lists, read together.
103 expect(n).toBe(9);
101104 n = 0;
102105 const refused = readLive("hetzner", async () => {
103106 n++;
104107 return json({ error: "unauthorized" }, 401);
105108 }, "tok", async () => {});
106109 await expect(refused).rejects.toThrow("answered 401 to servers");
107 expect(n).toBe(1);
110 // One try at each list: a refusal is not tried again.
111 expect(n).toBe(3);
112 });
113
114 test("the three lists are asked together, not one after another", async () => {
115 const started: string[] = [];
116 let release: () => void = () => {};
117 const held = new Promise<void>((r) => (release = r));
118 let allStarted: () => void = () => {};
119 const together = new Promise<void>((r) => (allStarted = r));
120 const read = readLive("digitalocean", async (url) => {
121 const list = new URL(url).pathname.split("/").pop()!;
122 started.push(list);
123 if (started.length === 3) allStarted();
124 if (list === "droplets") await held;
125 return json({ [list]: [] });
126 }, "tok");
127 // Droplets are held open: volumes and firewalls must start before it resolves.
128 await together;
129 expect([...started].sort()).toEqual(["droplets", "firewalls", "volumes"]);
130 release();
131 expect(await read).toEqual([]);
108132 });
109133
110134 test("a provider's strange text is made plain before it reaches a sentence", () => {

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

Keyboard shortcuts

Docs