-
Notifications
You must be signed in to change notification settings - Fork 12
observability: Add prerender server heap reporting #5852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
backspace
wants to merge
4
commits into
main
Choose a base branch
from
cs-12585-prerender-heap-telemetry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
279a77f
Report the prerender server's own heap
backspace 460884a
Merge remote-tracking branch 'origin/main' into cs-12585-prerender-he…
backspace 26de2ef
Assert the liveness payload's heap fields
backspace 2cb3fc3
Floor the heap panel's step at the reporting cadence
backspace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { getHeapStatistics } from 'node:v8'; | ||
|
|
||
| // The prerender server's own Node heap, as distinct from the browser-side | ||
| // JS heap the render paths already report (`jsHeapUsedMB` on a paused | ||
| // stack capture). A prerender server is long-lived and holds memory from | ||
| // work it has already finished, so these are the numbers that say whether | ||
| // a task is heading for `FATAL ERROR: Reached heap limit` — a crash that | ||
| // takes the task's warm tabs with it and leaves the surviving instances | ||
| // serving cold ones. | ||
| export interface HeapTelemetry { | ||
| heapUsedMB: number; | ||
| heapTotalMB: number; | ||
| heapLimitMB: number; | ||
| rssMB: number; | ||
| externalMB: number; | ||
| } | ||
|
|
||
| function mb(bytes: number): number { | ||
| return Math.round(bytes / 1024 / 1024); | ||
| } | ||
|
|
||
| export function heapTelemetry(): HeapTelemetry { | ||
| let heap = getHeapStatistics(); | ||
| let mem = process.memoryUsage(); | ||
| return { | ||
| heapUsedMB: mb(heap.used_heap_size), | ||
| heapTotalMB: mb(heap.total_heap_size), | ||
| // V8 sizes its default old-space limit from visible memory rather | ||
| // than from the task's allocation, so this is not derivable from the | ||
| // ECS memory setting — reporting it makes the effective | ||
| // `--max-old-space-size` readable from a running task instead of | ||
| // inferred from a task definition plus a Node version. | ||
| heapLimitMB: mb(heap.heap_size_limit), | ||
| rssMB: mb(mem.rss), | ||
| // Strings and buffers held outside the JS heap. Worth its own field | ||
| // rather than folding into rss: heap exhaustion here has surfaced | ||
| // during response serialisation, and memory retained that way shows | ||
| // up here rather than in `heapUsedMB`. | ||
| externalMB: mb(mem.external), | ||
| }; | ||
| } | ||
|
|
||
| // Rendered as `key=value` pairs to match the surrounding prerender log | ||
| // lines, so the same greps work and a Loki query can pull any single | ||
| // field out with one `regexp` stage. | ||
| export function formatHeapTelemetry(telemetry: HeapTelemetry): string { | ||
| return ( | ||
| `heapUsedMB=${telemetry.heapUsedMB} ` + | ||
| `heapTotalMB=${telemetry.heapTotalMB} ` + | ||
| `heapLimitMB=${telemetry.heapLimitMB} ` + | ||
| `rssMB=${telemetry.rssMB} ` + | ||
| `externalMB=${telemetry.externalMB}` | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every successful
GET /now includesmemory, butpackages/realm-server/tests/prerender-server-test.ts:133still asserts that the response body is exactly{ ready: true }. This makes the realm-server prerender test suite fail deterministically; update the existing assertion and cover the new telemetry fields.AGENTS.md reference: AGENTS.md:L266-L271
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Claude Code 🤖] Confirmed, and fixed in 26de2ef.
assert.deepEqual(res.body, { ready: true })compared the whole body, so the addedmemoryblock failed it deterministically — you're right that it was a guaranteed failure rather than a risk.The test now asserts
readyon its own and checks the heap block beside it. The field names are pinned on purpose: the heap dashboard panel extracts each one by name out of the log line, so a rename would leave those panels silently empty without failing anywhere. The values vary per run, so beyond the shape it only claims the heap in use is positive and within the limit.I checked the surrounding surface for the same problem and this was the only place: no other test asserts that payload, and nothing reads it at runtime — the Docker HEALTHCHECK discards the body and reads only the status code, and the manager tracks servers through heartbeat POSTs to
/prerender-serversrather than this endpoint. So the blast radius was test-only.One note in case it helps future suggestions on this suite:
qunit/no-assert-logical-expressionrejects combining the two numeric claims into oneassert.true(a && b), so they're asserted separately.