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

A month of 5-minute roll-ups stays bounded in the boards ring #2489

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/2485-a-month-of-5-minute-roll-ups-stays-bound → main 1 commit fork

  • Merged. scout/2485-a-month-of-5-minute-roll-ups-stays-bound was merged into main as 629df54.

Review

Sign in to review this change.
1 file changed +28 −1
test/boards-sampler.test.ts +28 −1
@@ -10,7 +10,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
1010 import { tmpdir } from "node:os";
1111 import { join } from "node:path";
1212 import { runQuery } from "../src/boards/query.ts";
13 import { COARSE_KEEP_MS, FINE_KEEP_MS, record, rollUp, type Point } from "../src/boards/ring.ts";
13 import { COARSE_KEEP_MS, COARSE_MS, FINE_KEEP_MS, FINE_MS, record, rollUp, type Point } from "../src/boards/ring.ts";
1414 import { gaps, pointsOf, readCounters, startSampler, type Paths } from "../src/boards/sampler.ts";
1515 import { SOURCES } from "../src/boards/sources.ts";
1616 import type { CellCounter } from "../src/apps/contain.ts";
@@ -174,6 +174,33 @@ describe("the ring", () => {
174174 const coarse = db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM machine_sample WHERE step = 300").get()!.n;
175175 expect(coarse).toBe((2 * FINE_KEEP_MS) / 300_000);
176176 });
177
178 test("31 days of 15-s points keep at most 30 days of 5-min roll-ups, none past COARSE_KEEP_MS", () => {
179 const db = fresh();
180 const days = 31;
181 const end = T0 + days * 24 * 3_600_000;
182 const started = performance.now();
183 // Real 15-s cadence, handed over one 5-min batch at a time, `now` at the batch's last point.
184 for (let w = T0; w < end; w += COARSE_MS) {
185 const batch: Point[] = [];
186 for (let t = w; t < w + COARSE_MS; t += FINE_MS) {
187 batch.push({ at: t, target: "forge", cpuCores: 1, memoryBytes: 1, load: null });
188 }
189 record(db, batch, w + COARSE_MS - FINE_MS);
190 }
191 const now = end - FINE_MS;
192 expect(performance.now() - started).toBeLessThan(5_000);
193
194 const count = (step: number) =>
195 db.query<{ n: number }, [number]>("SELECT COUNT(*) AS n FROM machine_sample WHERE step = ? AND target = 'forge'").get(step)!.n;
196 // 30 × 288 closed windows, plus the one the edge of the window falls in.
197 expect(count(300)).toBeLessThanOrEqual(30 * 288 + 1);
198 expect(count(300)).toBeGreaterThan(29 * 288);
199 expect(count(15)).toBeLessThanOrEqual(FINE_KEEP_MS / FINE_MS + 1);
200 expect(count(15)).toBeGreaterThan(FINE_KEEP_MS / FINE_MS - 20);
201 const oldest = db.query<{ at: string }, []>("SELECT MIN(at) AS at FROM machine_sample WHERE step = 300").get()!.at;
202 expect(Date.parse(oldest)).toBeGreaterThanOrEqual(now - COARSE_KEEP_MS);
203 });
177204 });
178205
179206 describe("the machine source", () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs