Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Keep /api/health off the monitor write lock; tolerate load stalls in the dev watchdog

rcourtmanb1114f49865f
diff --git a/internal/api/router.go b/internal/api/router.go
index e898bbcf78..21d3994423 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -4468,7 +4468,12 @@ func (r *Router) handleHealth(w http.ResponseWriter, req *http.Request) {
monitorHealthy := r.monitor != nil
schedulerHealthy := false
if monitorHealthy {
- schedulerHealthy = r.monitor.SchedulerHealth().DeadLetter.Count == 0
+ // Liveness probes are watchdog-polled and must stay minimal: the
+ // full SchedulerHealth refreshes provider caches under the monitor's
+ // write lock on every call, which this endpoint only needed for the
+ // dead-letter count. DeadLetterCount touches only the queue's own
+ // short-lived mutex.
+ schedulerHealthy = r.monitor.DeadLetterCount() == 0
}
statusCode := http.StatusOK
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 73f73d38db..176044bb70 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -2451,6 +2451,18 @@ func emptySchedulerHealthResponse(enabled bool) SchedulerHealthResponse {
}
// SchedulerHealth returns a complete snapshot of scheduler health for API exposure.
+// DeadLetterCount reports the number of dead-lettered poll tasks using only
+// the queue's own short-lived mutex. Liveness probes (/api/health) use this
+// instead of SchedulerHealth, which refreshes provider caches under the
+// monitor's write lock on every call — far more work and lock surface than a
+// watchdog-polled liveness check should pay for.
+func (m *Monitor) DeadLetterCount() int {
+ if m == nil || m.deadLetterQueue == nil {
+ return 0
+ }
+ return m.deadLetterQueue.Size()
+}
+
func (m *Monitor) SchedulerHealth() SchedulerHealthResponse {
response := emptySchedulerHealthResponse(m.config != nil && m.config.AdaptivePollingEnabled)
diff --git a/scripts/hot-dev.sh b/scripts/hot-dev.sh
index e923eea8cc..9ddaa84f64 100755
--- a/scripts/hot-dev.sh
+++ b/scripts/hot-dev.sh
@@ -23,8 +23,11 @@
# Allow automatic Patrol/discovery/alert AI in dev
# HOT_DEV_BACKEND_HEALTH_STARTUP_GRACE_SECONDS=180
# Backend /api/health grace after starts/restarts
-# HOT_DEV_BACKEND_UNHEALTHY_THRESHOLD=2
+# HOT_DEV_BACKEND_UNHEALTHY_THRESHOLD=4
# Consecutive failed /api/health probes before restart
+# (default tolerates ~20s of load-induced stall; test
+# suites and builds on the same machine routinely peg
+# the CPU and a kill mid-AI-stream bricks that chat turn)
#
# Pro Features Mode:
# When pulse-enterprise repo exists and HOT_DEV_USE_PRO is not "false",
@@ -519,11 +522,11 @@ fi
log_info "Starting backend health monitor..."
(
UNHEALTHY_STREAK=0
- UNHEALTHY_THRESHOLD="${HOT_DEV_BACKEND_UNHEALTHY_THRESHOLD:-2}"
+ UNHEALTHY_THRESHOLD="${HOT_DEV_BACKEND_UNHEALTHY_THRESHOLD:-4}"
BACKEND_HEALTH_STARTUP_GRACE_SECONDS="${HOT_DEV_BACKEND_HEALTH_STARTUP_GRACE_SECONDS:-180}"
BACKEND_PROCESS_MISSING_GRACE_SECONDS="${HOT_DEV_BACKEND_PROCESS_MISSING_GRACE_SECONDS:-10}"
- [[ "${UNHEALTHY_THRESHOLD}" =~ ^[1-9][0-9]*$ ]] || UNHEALTHY_THRESHOLD=2
+ [[ "${UNHEALTHY_THRESHOLD}" =~ ^[1-9][0-9]*$ ]] || UNHEALTHY_THRESHOLD=4
[[ "${BACKEND_HEALTH_STARTUP_GRACE_SECONDS}" =~ ^[0-9]+$ ]] || BACKEND_HEALTH_STARTUP_GRACE_SECONDS=180
[[ "${BACKEND_PROCESS_MISSING_GRACE_SECONDS}" =~ ^[0-9]+$ ]] || BACKEND_PROCESS_MISSING_GRACE_SECONDS=10