fix(schedule): drop runs left queued for too long; shorter result claims #177

Merged
Sebi merged 1 commits from fix/stale-runs-claim-ttl into main 2026-11-29 18:44:08 +00:00
Owner

Drop runs left queued for too long

pawhost and realtoxmedia sat at about 50K overdue checks for good. Their checkers work at capacity. Dispatch keeps queuing a new run every interval, even while the previous run of the same monitor still waits, so a checker that once fell behind works off runs from minutes ago forever and the backlog never shrinks.

  • Queue entries now carry their dispatch time: monitor|scheduled|dispatched. Entries without it, from before this release, are still parsed and never dropped. The overdue script reads the scheduled time with a pattern, so the extra field does not disturb it.
  • Take drops runs that waited longer than 2 intervals. A newer run of the monitor is queued by then, because the next run is due at most 1.5 intervals after a dispatch (phase rule). So the only run of a monitor is never dropped.
  • If a whole pop is stale, Take pops on instead of returning empty-handed.
  • New metric uptimesebi_checks_stale_total.

Result claims: 10 minutes instead of 2 hours

claimResults keeps one Redis key per check result (result:<instance>:<monitor>:<ts>) against duplicate reports. With a TTL of 2 h and about 530 results/s, that was 4.46M keys, 1.1 GiB of the shared Redis (limit 1.5 GiB, no eviction), which puts the writes of other apps at risk. Retries come with the next report or the first one after an API outage, so the TTL is now 10 min: about 300K keys, roughly 70 MiB. Existing keys expire on their own within 2 h after rollout.

Tests

  • TestTakeDropsStaleRuns: a run is still handed out after 2 intervals and dropped after more, in favour of the newer one.
  • TestTakeSkipsAllStaleRuns: a pop with only stale runs is followed by the next pop.
  • TestParseEntry: old and new format, plus invalid entries.
  • Metrics test covers Stale.
  • go test ./... with DB and Redis, and golangci-lint: green.

🤖 Generated with Claude Code

https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3

## Drop runs left queued for too long pawhost and realtoxmedia sat at about 50K overdue checks for good. Their checkers work at capacity. Dispatch keeps queuing a new run every interval, even while the previous run of the same monitor still waits, so a checker that once fell behind works off runs from minutes ago forever and the backlog never shrinks. - Queue entries now carry their dispatch time: `monitor|scheduled|dispatched`. Entries without it, from before this release, are still parsed and never dropped. The overdue script reads the scheduled time with a pattern, so the extra field does not disturb it. - `Take` drops runs that waited longer than **2 intervals**. A newer run of the monitor is queued by then, because the next run is due at most 1.5 intervals after a dispatch (phase rule). So the only run of a monitor is never dropped. - If a whole pop is stale, `Take` pops on instead of returning empty-handed. - New metric `uptimesebi_checks_stale_total`. ## Result claims: 10 minutes instead of 2 hours `claimResults` keeps one Redis key per check result (`result:<instance>:<monitor>:<ts>`) against duplicate reports. With a TTL of 2 h and about 530 results/s, that was **4.46M keys, 1.1 GiB** of the shared Redis (limit 1.5 GiB, no eviction), which puts the writes of other apps at risk. Retries come with the next report or the first one after an API outage, so the TTL is now **10 min**: about 300K keys, roughly 70 MiB. Existing keys expire on their own within 2 h after rollout. ## Tests - `TestTakeDropsStaleRuns`: a run is still handed out after 2 intervals and dropped after more, in favour of the newer one. - `TestTakeSkipsAllStaleRuns`: a pop with only stale runs is followed by the next pop. - `TestParseEntry`: old and new format, plus invalid entries. - Metrics test covers `Stale`. - `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 18:42:07 +00:00
fix(schedule): drop runs left queued for too long; shorter result claims
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m48s
ci / test (pull_request) Successful in 13m35s
ci / build (pull_request) Successful in 10m22s
ci / image (pull_request) Successful in 3m35s
94c529a97e
A checker that fell behind kept working off runs from minutes ago while
dispatch queued newer runs of the same monitors behind them, so a backlog
never shrank: pawhost and realtoxmedia stayed at about 50K overdue checks.
Queued runs now record when they were dispatched, and Take drops runs
that waited longer than two intervals. A newer run of the monitor has
been queued by then, since the next run is due at most one and a half
intervals after a dispatch. uptimesebi_checks_stale_total counts them.

Result claims, one Redis key per check result, lived 2 hours although
retries come within minutes. At about 530 results a second that was
4.5 million keys and 1.1 GiB of the shared Redis. They now live 10
minutes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi merged commit 3bc927a5f7 into main 2026-11-29 18:44:08 +00:00
Sebi deleted branch fix/stale-runs-claim-ttl 2026-11-29 18:44:10 +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#177