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

Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:2m4jgo7fd2 is past its budget: trevato/forge: "the access log's keeping > files older than 14 days go, and the directory stays under its cap" failed o… #6962

Merged opened this

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

Merged

scout/forge:scout/6952-sentinel-shared-01m23vygyffx5hg2f5vm8r74 → main 1 commit fork

  • Merged. scout/6952-sentinel-shared-01m23vygyffx5hg2f5vm8r74 was merged into main as 6e9a3a5.

Review

Sign in to review this change.
2 files changed +5 −5
src/http/access_log.ts +2 −2
@@ -156,7 +156,7 @@ export function lineFor(
156156 let pruned = "";
157157
158158 /** Drop files past their days, then the oldest until the directory fits. */
159 export function prune(dataDir: string, at: Date): void {
159 export function prune(dataDir: string, at: Date, cap: number = TOTAL_BYTES): void {
160160 const dir = accessDir(dataDir);
161161 const oldest = dayOf(new Date(at.getTime() - (KEEP_DAYS - 1) * DAY_MS));
162162 const files = readdirSync(dir)
@@ -169,7 +169,7 @@ export function prune(dataDir: string, at: Date): void {
169169 }
170170 let total = kept.reduce((n, f) => n + statSync(join(dir, f)).size, 0);
171171 for (const f of kept) {
172 if (total <= TOTAL_BYTES || f === kept[kept.length - 1]) break;
172 if (total <= cap || f === kept[kept.length - 1]) break;
173173 total -= statSync(join(dir, f)).size;
174174 unlinkSync(join(dir, f));
175175 }
test/access-log.test.ts +3 −3
@@ -24,7 +24,6 @@ import {
2424 prune,
2525 readAccess,
2626 recordAccess,
27 TOTAL_BYTES,
2827 } from "../src/http/access_log.ts";
2928 import { AppsRuntime } from "../src/apps/runtime.ts";
3029 import { newApp } from "../src/actions/apps.ts";
@@ -199,11 +198,12 @@ describe("the access log's keeping", () => {
199198 prune(dir, now);
200199 expect(readdirSync(keep)).toEqual(["access-2026-09-30.log"]);
201200 // Over the cap: the oldest goes first, today's file always stays.
202 const big = "x".repeat(TOTAL_BYTES / 2 + 1);
201 const cap = 1024;
202 const big = "x".repeat(cap / 2 + 1);
203203 writeFileSync(join(keep, "access-2026-10-10.log"), big);
204204 writeFileSync(join(keep, "access-2026-10-11.log"), big);
205205 writeFileSync(join(keep, "access-2026-10-13.log"), "today\n");
206 prune(dir, now);
206 prune(dir, now, cap);
207207 expect(readdirSync(keep).sort()).toEqual([
208208 "access-2026-10-11.log",
209209 "access-2026-10-13.log",

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs