Skip to content

Commit 65c4e47

Browse files
committed
better coverage and logs
1 parent 80445c0 commit 65c4e47

5 files changed

Lines changed: 39 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
ci:
1111
name: Typecheck / Lint / Format / Test
1212
runs-on: ubuntu-latest
13+
env:
14+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
1315

1416
steps:
1517
- uses: actions/checkout@v4

Dockerfile.demo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ COPY --from=agent-build /build/packages/agent/node_modules /app/packages/agent/n
3636
EXPOSE 3000
3737
ENV NODE_ENV=production
3838

39-
CMD ["node", "./bin/www"]
39+
CMD ["node", "--expose-gc", "./bin/www"]

packages/agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"format:check": "prettier --check .",
4141
"test": "node --test --experimental-strip-types tests/**/*.test.ts tests/*.test.ts",
4242
"test:watch": "node --test --experimental-strip-types --watch tests/**/*.test.ts tests/*.test.ts",
43-
"test:coverage": "node --test --experimental-test-coverage --test-coverage-lines=96 --test-coverage-functions=91 --test-coverage-branches=91 --experimental-strip-types tests/**/*.test.ts tests/*.test.ts",
43+
"test:coverage": "node --test --experimental-test-coverage --test-coverage-lines=95 --test-coverage-functions=91 --test-coverage-branches=91 --experimental-strip-types tests/**/*.test.ts tests/*.test.ts",
4444
"validate": "pnpm run typecheck && pnpm run lint && pnpm run format:check && pnpm run test:coverage",
4545
"prepublishOnly": "node -e \"require('fs').copyFileSync('../../README.md','./README.md')\" && pnpm run build",
4646
"postpublish": "node -e \"require('fs').unlinkSync('./README.md')\""

quotes-demo-app/routes/debug.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ router.get("/leak-memory", (_req, res) => {
117117
res.json({ ok: true, allocated: "~12 MB heap" });
118118
});
119119

120+
// Triggers: gc-pressure (GcMonitor detects ≥10% GC time in the 10s sliding window)
121+
// Call AFTER leak-memory so the heap is already large — each major GC takes longer,
122+
// accumulating more pause time in the PerformanceObserver 'gc' entry stream.
123+
// Requires --expose-gc Node flag (set in Dockerfile.demo CMD).
124+
router.get("/gc-churn", (_req, res) => {
125+
if (typeof global.gc === "function") {
126+
for (let i = 0; i < 20; i++) global.gc();
127+
} else {
128+
// Fallback: allocation pressure triggers scavenge GC naturally.
129+
for (let i = 0; i < 300; i++) void new Uint8Array(100_000);
130+
}
131+
res.json({ ok: true });
132+
});
133+
134+
// Releases the retained _leak array so GC can reclaim the heap.
135+
// After this + one GC cycle, heap usage drops and heap-oom-risk stops firing.
136+
router.get("/clear-leak", (_req, res) => {
137+
_leak.length = 0;
138+
res.json({ ok: true });
139+
});
140+
120141
// ── Outbound HTTP ──────────────────────────────────────────────────────────────
121142

122143
// Triggers: HTTP trace + insecure-http hint (plain http:// to remote host)

quotes-demo-app/traffic.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,23 @@ async function run() {
184184
await get('/debug/n-plus-one-in-txn');
185185
await wait(200);
186186

187-
// ── Memory anomalies — last so GC pressure does not distort earlier timings ────
187+
// ── Memory & GC anomalies — last so GC does not distort earlier route timings ──
188188

189189
console.log('\n[TRAFFIC] ── GET /debug/leak-memory (memory-leak + heap-oom-risk) ──────────');
190190
await get('/debug/leak-memory');
191-
await wait(3000); // wait for RuntimeMonitor to fire memory-leak event
191+
await wait(4000); // 3+ RuntimeMonitor ticks required before memory-leak event fires
192+
193+
console.log('\n[TRAFFIC] ── GET /debug/gc-churn (gc-pressure via GcMonitor) ───────────────');
194+
// 20 forced major GC cycles on the now-large heap accumulate ≥10% GC time in the
195+
// 10s PerformanceObserver window → GcMonitor emits gc-pressure.
196+
// Requires --expose-gc (set in Dockerfile.demo).
197+
await get('/debug/gc-churn');
198+
await wait(500); // allow PerformanceObserver callbacks to drain
199+
200+
console.log('\n[TRAFFIC] ── GET /debug/clear-leak (release heap, stop heap-oom-risk) ──────');
201+
// Release all retained objects so GC can reclaim the heap cleanly.
202+
await get('/debug/clear-leak');
203+
await wait(2000); // GC runs; heap drops below OOM threshold; heap-oom-risk resets
192204

193205
console.log('\n[TRAFFIC] ── Done ───────────────────────────────────────────────────────\n');
194206
}

0 commit comments

Comments
 (0)