fix(statuspages): encode a page once for all servers, gzipped #178

Merged
Sebi merged 1 commits from fix/page-snapshot-memory into main 2026-11-29 21:00:47 +00:00
Owner

Why

Both API pods were OOMKilled at 512 MiB within about 90 s of starting: every status page server fetched a ~20 MB page at the same moment. Per request and server, agentPage:

  • marshalled the snapshot once for the ETag (Checksum());
  • marshalled it again for the answer (c.JSON), into a growing buffer;
  • copied it into a stream frame.

So each server cost about 60–80 MB, and the shared build (singleflight) only shared the snapshot struct, not its encoding.

What

  • sharedSnapshot now also encodes the page inside the shared build, once: ETag, JSON and gzipped JSON (encodedSnapshot). Every server asking at the same time gets the same bytes; nothing is marshalled per request.
  • agentPage sends the gzipped bytes with Content-Encoding: gzip when the request accepts gzip, otherwise the plain JSON. The compress middleware leaves an already encoded response alone.
  • Agent client: PageIfChanged asks for Accept-Encoding: gzip, and doWith unpacks a gzipped answer. The transport does not do that once the header is set explicitly, and the stream never did. Older agents keep getting plain JSON, which is now also encoded only once.
  • Snapshot size: uptime ratios (days, hours, SLAs) are rounded to 6 decimals instead of up to 18 characters, about 11% less JSON. A ratio below 1 never becomes 1, so a page never shows 100% for a component that failed.

Measured with a synthetic page of 5,500 components × 90 days and realistic ratios: 20.6 MB JSON → 1.1 MB gzip.

Tests

  • TestAgentPageEncoding: plain request → JSON with ETag = checksum; gzip request → gzip with the same ETag and the same content; If-None-Match → 304; the client unpacks over plain HTTP.
  • TestAgentStream and the other status page tests cover the stream path with gzip.
  • TestRoundRatio.
  • go test ./... with DB and Redis, and golangci-lint: green.

🤖 Generated with Claude Code

https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3

## Why Both API pods were OOMKilled at 512 MiB within about 90 s of starting: every status page server fetched a ~20 MB page at the same moment. Per request and server, `agentPage`: - marshalled the snapshot once for the ETag (`Checksum()`); - marshalled it again for the answer (`c.JSON`), into a growing buffer; - copied it into a stream frame. So each server cost about 60–80 MB, and the shared build (singleflight) only shared the snapshot struct, not its encoding. ## What - `sharedSnapshot` now also **encodes** the page inside the shared build, once: ETag, JSON and gzipped JSON (`encodedSnapshot`). Every server asking at the same time gets the same bytes; nothing is marshalled per request. - `agentPage` sends the gzipped bytes with `Content-Encoding: gzip` when the request accepts gzip, otherwise the plain JSON. The compress middleware leaves an already encoded response alone. - **Agent client:** `PageIfChanged` asks for `Accept-Encoding: gzip`, and `doWith` unpacks a gzipped answer. The transport does not do that once the header is set explicitly, and the stream never did. Older agents keep getting plain JSON, which is now also encoded only once. - **Snapshot size:** uptime ratios (days, hours, SLAs) are rounded to 6 decimals instead of up to 18 characters, about 11% less JSON. A ratio below 1 never becomes 1, so a page never shows 100% for a component that failed. Measured with a synthetic page of 5,500 components × 90 days and realistic ratios: **20.6 MB JSON → 1.1 MB gzip**. ## Tests - `TestAgentPageEncoding`: plain request → JSON with ETag = checksum; gzip request → gzip with the same ETag and the same content; `If-None-Match` → 304; the client unpacks over plain HTTP. - `TestAgentStream` and the other status page tests cover the stream path with gzip. - `TestRoundRatio`. - `go test ./...` with DB and Redis, and golangci-lint: green. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added 1 commit 2026-11-29 20:58:27 +00:00
fix(statuspages): encode a page once for all servers, gzipped
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (pull_request) Waiting for needed jobs
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m55s
ci / test (pull_request) Successful in 13m30s
ci / build (pull_request) In progress
9424824416
Every status page server asking for a page got it encoded anew: the
snapshot was marshalled once for its checksum and again for the answer,
then copied into a stream frame. A page of several thousand components
is about 20 MB of JSON, so servers fetching it together, as they do when
told it changed, ran both API pods out of their 512 MiB.

The shared build now also encodes the page once, as JSON and gzipped,
and every server asking at the same time gets those bytes. Servers ask
for gzip and unpack it, over HTTP and the stream; older ones still get
plain JSON. A 20 MB page shrinks to about 1 MB. Uptime ratios in the
snapshot are rounded to six decimals instead of up to 18 characters,
never to 100% for a component that failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi merged commit efd2f2d793 into main 2026-11-29 21:00:47 +00:00
Sebi deleted branch fix/page-snapshot-memory 2026-11-29 21:00:50 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ZB-Server/uptimesebi#178