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 high percentage triggers evaluable when the critical cap collides

rcourtmanc05a66578772
diff --git a/internal/alerts/unified_eval.go b/internal/alerts/unified_eval.go
index 483b54ae89..ace503741a 100644
--- a/internal/alerts/unified_eval.go
+++ b/internal/alerts/unified_eval.go
@@ -346,8 +346,14 @@ func buildCanonicalMetricSpec(resourceID, title string, resourceType unifiedreso
recovery := threshold.Clear
spec.MetricThreshold.Recovery = &recovery
}
- critical := computeCriticalThreshold(threshold.Trigger, metricType)
- spec.MetricThreshold.Critical = &critical
+ // A percentage trigger of 99+ collides with the 99 critical cap; a
+ // critical at or below the trigger fails spec validation and used to
+ // drop the whole metric from evaluation (silently unmonitored, plus a
+ // warn-log every cycle). Omit escalation instead so the warning-level
+ // threshold keeps working.
+ if critical := computeCriticalThreshold(threshold.Trigger, metricType); critical > threshold.Trigger {
+ spec.MetricThreshold.Critical = &critical
+ }
}
return spec, spec.Validate()
diff --git a/internal/alerts/unified_eval_critical_cap_test.go b/internal/alerts/unified_eval_critical_cap_test.go
new file mode 100644
index 0000000000..2acdfd49ad
--- /dev/null
+++ b/internal/alerts/unified_eval_critical_cap_test.go
@@ -0,0 +1,30 @@
+package alerts
+
+import (
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
+)
+
+// A percentage metric with trigger at or above the 99 critical cap must still
+// produce a valid, evaluable spec (warning-only, no escalation) instead of
+// being skipped as invalid (#1593 log spam / silent monitoring gap).
+func TestBuildCanonicalMetricSpec_HighPercentageTriggerStaysEvaluable(t *testing.T) {
+ for _, trigger := range []float64{99, 100} {
+ spec, err := buildCanonicalMetricSpec("agent-1", "nas", unifiedresources.ResourceTypeAgent, "memory", &HysteresisThreshold{Trigger: trigger, Clear: trigger - 5})
+ if err != nil {
+ t.Fatalf("trigger %v: expected valid spec, got error %v", trigger, err)
+ }
+ if spec.MetricThreshold.Critical != nil {
+ t.Fatalf("trigger %v: expected escalation omitted, got critical %v", trigger, *spec.MetricThreshold.Critical)
+ }
+ }
+
+ spec, err := buildCanonicalMetricSpec("agent-1", "nas", unifiedresources.ResourceTypeAgent, "memory", &HysteresisThreshold{Trigger: 95, Clear: 90})
+ if err != nil {
+ t.Fatalf("trigger 95: unexpected error %v", err)
+ }
+ if spec.MetricThreshold.Critical == nil || *spec.MetricThreshold.Critical != 99 {
+ t.Fatalf("trigger 95: expected critical capped at 99, got %+v", spec.MetricThreshold.Critical)
+ }
+}