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

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
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-29 19:41:54 +01:00
1 parent 71219d8031
commit 94c529a97e
5 files changed
+216 -44

No files matched your search

+13 -1
View File
@@ -27,6 +27,7 @@ type Metrics struct {
duration *prometheus.HistogramVec
inFlight prometheus.Gauge
dispatched prometheus.Counter
stale prometheus.Counter
results *prometheus.CounterVec
rejected *prometheus.CounterVec
resultDelay prometheus.Histogram
@@ -62,6 +63,10 @@ func New(edition string) *Metrics {
Namespace: namespace, Name: "checks_dispatched_total",
Help: "Checks this instance moved from the schedule to the checkers' queues.",
}),
stale: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace, Name: "checks_stale_total",
Help: "Queued checks dropped because they waited longer than two intervals; a newer run of the monitor was queued by then.",
}),
results: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace, Name: "check_results_total",
Help: "Check results stored, by region (\"own\" for organizations' own checkers) and outcome.",
@@ -116,7 +121,7 @@ func New(edition string) *Metrics {
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
build,
m.requests, m.duration, m.inFlight,
m.dispatched, m.results, m.rejected, m.resultDelay,
m.dispatched, m.stale, m.results, m.rejected, m.resultDelay,
m.notifications, m.notifyDuration, m.subscriberMail,
m.incidents,
m.jobRuns, m.jobDuration, m.jobSuccess,
@@ -162,6 +167,13 @@ func (m *Metrics) HTTP(streaming ...string) gin.HandlerFunc {
// Dispatched counts checks moved to the checkers' queues.
func (m *Metrics) Dispatched(n int) { m.dispatched.Add(float64(n)) }
// Stale counts n queued checks dropped as out of date.
func (m *Metrics) Stale(n int) {
if n > 0 {
m.stale.Add(float64(n))
}
}
// Result counts a stored check result and how long it took to arrive.
func (m *Metrics) Result(region string, ok bool, delay time.Duration) {
m.results.WithLabelValues(region, strconv.FormatBool(ok)).Inc()
+3
View File
@@ -66,6 +66,8 @@ func TestJobRecordsOutcome(t *testing.T) {
func TestCountersAndHandler(t *testing.T) {
m := New("cloud")
m.Dispatched(3)
m.Stale(2)
m.Stale(0)
m.Result("fsn", true, 2*time.Second)
m.Result("fsn", false, -time.Second)
m.Rejected("duplicate", 2)
@@ -79,6 +81,7 @@ func TestCountersAndHandler(t *testing.T) {
got, want float64
}{
"dispatched": {testutil.ToFloat64(m.dispatched), 3},
"stale": {testutil.ToFloat64(m.stale), 2},
"ok results": {testutil.ToFloat64(m.results.WithLabelValues("fsn", "true")), 1},
"failed results": {testutil.ToFloat64(m.results.WithLabelValues("fsn", "false")), 1},
"duplicates": {testutil.ToFloat64(m.rejected.WithLabelValues("duplicate")), 2},