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.

fix(alerts): report clearing observation in metric recovery

pulse-triage[bot]57cb1a83bf82
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index e09b14a016..c0bcfbe9f6 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -15,6 +15,20 @@
## Purpose
+Confirmed canonical metric recovery publishes the clearing evaluation's value,
+observation time, and resolved metric wording in the snapshot consumed by
+recent-resolution reads and notification callbacks. It must not reuse the last
+firing sample, including when the clearing value is zero or guest identity
+migrates between nodes. Clone the snapshot before refreshing recovery content;
+preserve incident identity and start time. Missing or malformed telemetry is
+not a clearing observation. This does not change explicit configuration-disable
+or resource-removal resolution semantics.
+`TestAlertCharacterizationGuestMetricResolutionUsesCurrentNodeIdentityAfterMove`
+in `internal/alerts/migration_characterization_test.go` pins canonical identity
+and clearing content together; `TestPBSPartialMetricsWebhookLifecycle` in
+`internal/monitoring/monitor_pbs_webhook_test.go` verifies low/zero measurements
+and invalid-telemetry suppression through a local HTTP receiver.
+
TrueNAS INFO provider incidents remain on the canonical resource but do not
enter the actionable active-alert lifecycle. Native NOTICE remains actionable
at informational canonical severity; it must not be discarded merely because
diff --git a/internal/alerts/canonical_metric.go b/internal/alerts/canonical_metric.go
index e7b15c494a..d9d136c6ec 100644
--- a/internal/alerts/canonical_metric.go
+++ b/internal/alerts/canonical_metric.go
@@ -381,6 +381,14 @@ func (m *Manager) evaluateCanonicalMetricAlert(spec alertspecs.ResourceAlertSpec
return
}
+ // Publish the observation that cleared the incident, not the last
+ // firing sample. Both history and resolved callbacks consume this snapshot.
+ existingAlert = existingAlert.Clone()
+ existingAlert.Value = value
+ existingAlert.LastSeen = observedAt
+ message, _ := metricAlertMessage(resourceType, metricType, value, opts)
+ existingAlert.Message = "Resolved: " + message
+
recoveryEvidence, hasRecoveryEvidence := canonicalAlertEvidenceEnvelope(
spec,
evidence,
diff --git a/internal/alerts/migration_characterization_test.go b/internal/alerts/migration_characterization_test.go
index 0d9520133b..17a2f075b9 100644
--- a/internal/alerts/migration_characterization_test.go
+++ b/internal/alerts/migration_characterization_test.go
@@ -1,6 +1,7 @@
package alerts
import (
+ "strings"
"testing"
"time"
@@ -682,6 +683,14 @@ func TestAlertCharacterizationGuestMetricResolutionUsesCurrentNodeIdentityAfterM
if resolved.Alert.ResourceID != newResourceID {
t.Fatalf("resolved alert resource ID = %q, want %q", resolved.Alert.ResourceID, newResourceID)
}
+ // Identity migration must not preserve the old firing observation in
+ // the snapshot used by recovery callbacks and recent-resolution reads.
+ if resolved.Value != 70 || !strings.HasPrefix(resolved.Message, "Resolved: VM cpu ") || !strings.Contains(resolved.Message, "70.0%") || strings.Contains(resolved.Message, "95.0%") {
+ t.Fatalf("resolved snapshot retained firing content: value=%v message=%q", resolved.Value, resolved.Message)
+ }
+ if !resolved.LastSeen.After(resolved.StartTime) {
+ t.Fatalf("resolved observation time %v did not advance past incident start %v", resolved.LastSeen, resolved.StartTime)
+ }
history := m.GetAlertHistory(5)
if len(history) != 1 || history[0].ID != newState {
diff --git a/internal/monitoring/monitor_pbs_webhook_test.go b/internal/monitoring/monitor_pbs_webhook_test.go
index 707fb5d72f..9924ddbbea 100644
--- a/internal/monitoring/monitor_pbs_webhook_test.go
+++ b/internal/monitoring/monitor_pbs_webhook_test.go
@@ -3,8 +3,10 @@ package monitoring
import (
"context"
"encoding/json"
+ "fmt"
"net/http"
"net/http/httptest"
+ "strings"
"testing"
"time"
@@ -146,10 +148,29 @@ func testPBSPartialMetricsWebhookLifecycle(t *testing.T, recoveryMode pbsHealthT
recovery.Alerts[0].ID != incident.ID || !recovery.Alerts[0].StartTime.Equal(incident.StartTime) {
t.Fatalf("recovery does not identify delivered incident: %+v", recovery)
}
+ // Inspect what the receiver actually sees, not only the event envelope.
+ wantValue := 100.0 / 1024 * 100
+ if recoveryMode == pbsHealthTestZeroUsage {
+ wantValue = 0
+ }
+ resolved := recovery.Alerts[0]
+ if resolved.Value != wantValue {
+ t.Fatalf("recovery value = %v, want measured %v (firing %v)", resolved.Value, wantValue, incident.Value)
+ }
+ if !strings.HasPrefix(resolved.Message, "Resolved: ") || !strings.Contains(resolved.Message, fmt.Sprintf("%.1f%%", wantValue)) || strings.Contains(strings.ToLower(resolved.Message), "above") {
+ t.Fatalf("recovery retained breach wording: %q", resolved.Message)
+ }
waitSent(2)
if len(manager.GetActiveAlerts()) != 0 || len(manager.GetRecentlyResolved()) != 1 {
t.Fatal("genuine recovery did not update active/history state")
}
+ history := manager.GetResolvedAlert(incident.ID)
+ if history == nil || history.Value != wantValue || history.Message != resolved.Message || !history.LastSeen.Equal(resolved.LastSeen) {
+ t.Fatalf("recovery history differs from receiver: %+v", history)
+ }
+ if !resolved.LastSeen.After(incident.LastSeen) {
+ t.Fatal("recovery retained firing observation time")
+ }
for range 5 {
poll()
}