fix(evidence): spread periodic evidence and store a report's in one go #176

Merged
Sebi merged 1 commits from fix/evidence-burst into main 2026-11-29 17:18:21 +00:00
Owner

Why

The overdue waves continued after v0.16.1, about every 10 minutes and only in the external regions. In the prod API logs (read-only):

  • POST /agent/v1/results normally takes about 0.4 s. In the waves (16:41–43, 16:51–53, from 17:00 UTC) it took 5–36 s for every external checker at once.
  • Then the checker's result buffer fills, its slots stay busy, and its polls drop from about 120 to 20 a minute.
  • The checkers all restarted between 16:36 and 16:40 (self-update to v0.16.1). The waves followed 10 minutes after that, then every 10 minutes.

Cause: the checker sends evidence of a healthy check with the first result after starting, then every evidenceEvery (10 min). After a joint restart, every monitor's evidence lands in the same minute, every 10 minutes. storeEvidence wrote each piece of evidence in a transaction of its own, one after another, inside the report request.

What

  • Checker: evidence sent for another reason than the period (first result, failure, recovery) puts the next periodic one at a random point of the period. Periodic evidence keeps its 10-minute cadence. Volume stays the same; it is spread evenly.
  • API: all evidence of a report goes into one transaction:
    • one DELETE … monitor_id = ANY(...) for the successes to replace;
    • one DISTINCT ON query for the failures last kept;
    • then the inserts.
    • Within a report, only the latest success per monitor is stored, and failures are thinned out against each other as well.
    • The failure comparison now uses the stored, truncated error text, so long errors are thinned out too.

Tests

  • TestEvidenceSpreadsAfterStart: 600 monitors start together; their periodic evidence over the next period comes once per monitor, with at most 150 in a minute (mean 60). Without jitter all 600 land in one minute.
  • TestEvidenceBatch: a report with two successes of one monitor and three failures of another keeps the latest success and 2 failures. A second report replaces the success and thins out the repeated failure.
  • TestEvidence and TestEvidencePolicy unchanged and green (the policy test pins the jitter to 0).
  • go test ./... with DB and Redis, and golangci-lint: green.

The first periodic burst after this rollout is unavoidable (the checkers restart once more); after that, evidence spreads within one period.

🤖 Generated with Claude Code

https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3

## Why The overdue waves continued after v0.16.1, about every 10 minutes and only in the external regions. In the prod API logs (read-only): - `POST /agent/v1/results` normally takes about 0.4 s. In the waves (16:41–43, 16:51–53, from 17:00 UTC) it took **5–36 s** for every external checker at once. - Then the checker's result buffer fills, its slots stay busy, and its polls drop from about 120 to 20 a minute. - The checkers all restarted between 16:36 and 16:40 (self-update to v0.16.1). The waves followed 10 minutes after that, then every 10 minutes. **Cause:** the checker sends evidence of a healthy check with the first result after starting, then every `evidenceEvery` (10 min). After a joint restart, every monitor's evidence lands in the same minute, every 10 minutes. `storeEvidence` wrote each piece of evidence in a transaction of its own, one after another, inside the report request. ## What - **Checker:** evidence sent for another reason than the period (first result, failure, recovery) puts the next periodic one at a random point of the period. Periodic evidence keeps its 10-minute cadence. Volume stays the same; it is spread evenly. - **API:** all evidence of a report goes into **one transaction**: - one `DELETE … monitor_id = ANY(...)` for the successes to replace; - one `DISTINCT ON` query for the failures last kept; - then the inserts. - Within a report, only the latest success per monitor is stored, and failures are thinned out against each other as well. - The failure comparison now uses the stored, truncated error text, so long errors are thinned out too. ## Tests - `TestEvidenceSpreadsAfterStart`: 600 monitors start together; their periodic evidence over the next period comes once per monitor, with at most 150 in a minute (mean 60). Without jitter all 600 land in one minute. - `TestEvidenceBatch`: a report with two successes of one monitor and three failures of another keeps the latest success and 2 failures. A second report replaces the success and thins out the repeated failure. - `TestEvidence` and `TestEvidencePolicy` unchanged and green (the policy test pins the jitter to 0). - `go test ./...` with DB and Redis, and golangci-lint: green. The first periodic burst after this rollout is unavoidable (the checkers restart once more); after that, evidence spreads within one period. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added 1 commit 2026-11-29 17:16:26 +00:00
fix(evidence): spread periodic evidence and store a report's in one go
ci / lint (push) Skipped
ci / test (push) Skipped
ci / image (pull_request) Waiting for needed jobs
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 13m0s
ci / test (pull_request) Successful in 13m56s
ci / build (pull_request) In progress
e26194d260
Checkers send evidence of healthy checks every 10 minutes, first with
the first result after they start. When checkers restart together, as
after a self-update, every monitor's evidence came in the same minute,
every 10 minutes. The API stored each in a transaction of its own while
the checker waited, reports took up to 36 seconds, the checkers' slots
filled and runs piled up: the overdue waves seen in prod.

Evidence sent for another reason than the period now puts the next
periodic one at a random point of the period, and the API writes all of
a report's evidence in one transaction, with one query each for the
successes to replace and the failures last kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi merged commit 71219d8031 into main 2026-11-29 17:18:21 +00:00
Sebi deleted branch fix/evidence-burst 2026-11-29 17:18:23 +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#176