fix(prometheus): serve scrapes from cached background poll (#1013)

Decouples Prometheus scrape cadence from upstream UniFi API calls so a
429 backoff loop on the controller side no longer stalls /metrics. The
output plugin now owns a 60s background poller (configurable) whose
result is served from an in-memory cache. Concurrent /scrape requests
for the same target are coalesced via singleflight to prevent a noisy
scraper from multiplying upstream load.

Adds two new metrics so operators can detect cache staleness and
refresh failures independently:
- unpoller_prometheus_cache_age_seconds
- unpoller_prometheus_refresh_failures_total

Background goroutine recovers from panics so a malformed input payload
no longer silently kills refreshes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cody Lee
2026-05-11 17:43:44 -05:00
co-authored by Claude Opus 4.7
parent 0b83c6ad19
commit dabfeffe66
8 changed files with 635 additions and 4 deletions
+2 -1
View File
@@ -11,7 +11,8 @@
"http_listen": "0.0.0.0:9130",
"ssl_cert_path": "",
"ssl_key_path": "",
"report_errors": false
"report_errors": false,
"interval": "60s"
},
"influxdb": {