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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/6952-sentinel-shared-01m23vygyffx5hg2f5vm8r74 → main 1 commit fork
2 files
changed +5
−5
src/http/access_log.ts +2 −2
| @@ -156,7 +156,7 @@ export function lineFor( | ||
| 156 | 156 | let pruned = ""; |
| 157 | 157 | |
| 158 | 158 | /** 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 { | |
| 160 | 160 | const dir = accessDir(dataDir); |
| 161 | 161 | const oldest = dayOf(new Date(at.getTime() - (KEEP_DAYS - 1) * DAY_MS)); |
| 162 | 162 | const files = readdirSync(dir) |
| @@ -169,7 +169,7 @@ export function prune(dataDir: string, at: Date): void { | ||
| 169 | 169 | } |
| 170 | 170 | let total = kept.reduce((n, f) => n + statSync(join(dir, f)).size, 0); |
| 171 | 171 | 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; | |
| 173 | 173 | total -= statSync(join(dir, f)).size; |
| 174 | 174 | unlinkSync(join(dir, f)); |
| 175 | 175 | } |
test/access-log.test.ts +3 −3
| @@ -24,7 +24,6 @@ import { | ||
| 24 | 24 | prune, |
| 25 | 25 | readAccess, |
| 26 | 26 | recordAccess, |
| 27 | TOTAL_BYTES, | |
| 28 | 27 | } from "../src/http/access_log.ts"; |
| 29 | 28 | import { AppsRuntime } from "../src/apps/runtime.ts"; |
| 30 | 29 | import { newApp } from "../src/actions/apps.ts"; |
| @@ -199,11 +198,12 @@ describe("the access log's keeping", () => { | ||
| 199 | 198 | prune(dir, now); |
| 200 | 199 | expect(readdirSync(keep)).toEqual(["access-2026-09-30.log"]); |
| 201 | 200 | // 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); | |
| 203 | 203 | writeFileSync(join(keep, "access-2026-10-10.log"), big); |
| 204 | 204 | writeFileSync(join(keep, "access-2026-10-11.log"), big); |
| 205 | 205 | writeFileSync(join(keep, "access-2026-10-13.log"), "today\n"); |
| 206 | prune(dir, now); | |
| 206 | prune(dir, now, cap); | |
| 207 | 207 | expect(readdirSync(keep).sort()).toEqual([ |
| 208 | 208 | "access-2026-10-11.log", |
| 209 | 209 | "access-2026-10-13.log", |
new above
offline