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.

test: retain PBS observation identity across monitor replacement

pulse-triage[bot]c7596d24d9b8
diff --git a/internal/monitoring/pbs_observation_lifecycle_test.go b/internal/monitoring/pbs_observation_lifecycle_test.go
index 99db895335..60650be9de 100644
--- a/internal/monitoring/pbs_observation_lifecycle_test.go
+++ b/internal/monitoring/pbs_observation_lifecycle_test.go
@@ -96,3 +96,81 @@ func TestPBSObservationHistorySurvivesRebuildsAndStoreReopen(t *testing.T) {
}
}
}
+
+// A fresh monitor has no in-memory deduplication state. Replaying the cached
+// observation while PBS is offline must not manufacture a new durable sample;
+// an equal-valued observation after recovery must still be retained.
+func TestPBSObservationHistoryAcrossMonitorReplacement(t *testing.T) {
+ cfg := metrics.DefaultConfig(t.TempDir())
+ start := time.Now().UTC().Add(-time.Minute).Truncate(time.Second)
+ var targetID string
+ for generation := 0; generation < 2; generation++ {
+ persistent, err := metrics.NewStore(cfg)
+ if err != nil {
+ t.Fatal(err)
+ }
+ func() {
+ defer func() {
+ if err := persistent.Close(); err != nil {
+ t.Error(err)
+ }
+ }()
+ monitor := &Monitor{metricsHistory: NewMetricsHistory(1024, 24*time.Hour), metricsStore: persistent}
+ adapter := unifiedresources.NewMonitorAdapter(nil)
+ snapshot := models.StateSnapshot{PBSInstances: []models.PBSInstance{{
+ ID: "pbs-restart", Name: "pbs-restart", Status: "online", LastSeen: start,
+ Datastores: []models.PBSDatastore{{Name: "backups", Status: "available", Total: 1000, Used: 400, Free: 600, Usage: 40}},
+ }}}
+ if generation == 1 {
+ snapshot.PBSInstances[0].Status = "offline"
+ }
+ for poll := 0; poll < 6; poll++ {
+ adapter.PopulateFromSnapshot(snapshot)
+ for _, resource := range adapter.GetAll() {
+ if resource.Storage == nil || resource.Storage.Platform != "pbs" {
+ continue
+ }
+ target := adapter.MetricsTargetForResource(resource.ID)
+ if target == nil {
+ t.Fatal("missing metrics target")
+ }
+ if targetID != "" && targetID != target.ResourceID {
+ t.Fatal("target changed across replacement")
+ }
+ targetID = target.ResourceID
+ }
+ if targetID == "" {
+ t.Fatal("missing PBS datastore")
+ }
+ monitor.syncUnifiedStorageMetrics(adapter)
+ }
+ if generation == 1 {
+ snapshot.PBSInstances[0].Status = "online"
+ snapshot.PBSInstances[0].LastSeen = start.Add(30 * time.Second)
+ adapter.PopulateFromSnapshot(snapshot)
+ monitor.syncUnifiedStorageMetrics(adapter)
+ }
+ }()
+ }
+ // Reopen again so these assertions cannot be satisfied by buffered writes.
+ persistent, err := metrics.NewStore(cfg)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer persistent.Close()
+ for metric, value := range map[string]float64{"usage": 40, "used": 400, "total": 1000, "avail": 600} {
+ points, err := persistent.Query("storage", targetID, metric, start.Add(-time.Second), start.Add(time.Minute), 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(points) != 2 {
+ t.Fatalf("%s: got %d durable points, want 2", metric, len(points))
+ }
+ for i, point := range points {
+ expectedTime := start.Add(time.Duration(i) * 30 * time.Second)
+ if point.Value != value || !point.Timestamp.Equal(expectedTime) {
+ t.Fatalf("%s[%d] = %+v, want %v at %s", metric, i, point, value, expectedTime)
+ }
+ }
+ }
+}