Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Back off container update checks for an hour after a rate limit
rcourtmanfcb7c068a10c
diff --git a/internal/dockeragent/registry.go b/internal/dockeragent/registry.goindex 239e235f94..e96a2fc2c0 100644--- a/internal/dockeragent/registry.go+++ b/internal/dockeragent/registry.go@@ -45,6 +45,12 @@ const (defaultCacheTTL = 6 * time.Hour// ErrorCacheTTL is the TTL for caching errors (shorter to allow retry).errorCacheTTL = 15 * time.Minute+ // RateLimitCacheTTL is the TTL for rate-limited lookups. Retrying these on+ // the short error TTL keeps hammering a registry whose allowance is+ // already exhausted (every refused HEAD still counts against it), which+ // can hold a strict registry's limit tripped indefinitely. Back off for+ // an hour instead so the allowance can actually recover.+ rateLimitCacheTTL = 1 * time.Hour// DefaultCheckInterval is how often to check for updates.defaultCheckInterval = 6 * time.Hour)@@ -572,9 +578,14 @@ func (r *RegistryChecker) cacheError(key, errMsg string) {r.cache.mu.Lock()defer r.cache.mu.Unlock()+ ttl := errorCacheTTL+ if strings.Contains(strings.ToLower(errMsg), "rate limit") {+ ttl = rateLimitCacheTTL+ }+r.cache.entries[key] = cacheEntry{err: errMsg,- expiresAt: time.Now().Add(errorCacheTTL),+ expiresAt: time.Now().Add(ttl),}}diff --git a/internal/dockeragent/registry_coverage_test.go b/internal/dockeragent/registry_coverage_test.goindex 81a3a57fcb..158ba0df2f 100644--- a/internal/dockeragent/registry_coverage_test.go+++ b/internal/dockeragent/registry_coverage_test.go@@ -80,6 +80,28 @@ func TestRegistryChecker_CheckImageUpdate_CacheHits(t *testing.T) {})}+func TestRegistryChecker_CacheError_RateLimitBacksOffLonger(t *testing.T) {+ logger := zerolog.Nop()+ checker := NewRegistryChecker(logger)++ checker.cacheError("limited", "rate limited")+ checker.cacheError("transient", "registry error: 502")++ checker.cache.mu.RLock()+ limited := checker.cache.entries["limited"]+ transient := checker.cache.entries["transient"]+ checker.cache.mu.RUnlock()++ // A refused HEAD still counts against the registry's allowance, so+ // rate-limited lookups must back off well past the transient-error TTL.+ if !limited.expiresAt.After(time.Now().Add(errorCacheTTL)) {+ t.Errorf("Expected rate-limited entry to outlive the transient error TTL, expires %v", limited.expiresAt)+ }+ if transient.expiresAt.After(time.Now().Add(errorCacheTTL)) {+ t.Errorf("Expected transient error entry to use the short TTL, expires %v", transient.expiresAt)+ }+}+func TestRegistryChecker_CheckImageUpdate_ProBrokerRegistrySkipped(t *testing.T) {logger := zerolog.Nop()checker := NewRegistryChecker(logger)