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 PBS write evidence poll-scoped

pulse-triage[bot]b8158dce2966
diff --git a/internal/monitoring/monitor_backups.go b/internal/monitoring/monitor_backups.go
index 31e4bfbc01..2e15c9bc69 100644
--- a/internal/monitoring/monitor_backups.go
+++ b/internal/monitoring/monitor_backups.go
@@ -1823,6 +1823,13 @@ func (m *Monitor) pollPBSBackups(ctx context.Context, instanceName string, clien
// denied or transiently unavailable, keep the previous conservative
// inference rather than claiming that no write is active.
if hasIncompletePBSBackup(allBackups) {
+ // Write-activity evidence belongs to this poll, not to the snapshot
+ // cache. A failed snapshot refresh may have reused an incomplete
+ // artifact whose previous poll authoritatively found no writer. Clear
+ // that old observation before asking for the current task view so a
+ // task-query failure leaves visibility unknown instead of publishing a
+ // stale terminal-failure conclusion.
+ clearPBSWriteActivityObservation(allBackups)
runningDataTasks, runningTasksErr := client.ListRunningDataTasks(ctx)
if runningTasksErr != nil {
log.Warn().Err(runningTasksErr).
@@ -1897,6 +1904,13 @@ func hasIncompletePBSBackup(backups []models.PBSBackup) bool {
return false
}
+func clearPBSWriteActivityObservation(backups []models.PBSBackup) {
+ for i := range backups {
+ backups[i].WriteActivityObserved = false
+ backups[i].WriteActive = false
+ }
+}
+
// applyPBSWriteActivity marks whether each incomplete snapshot is accounted
// for by a task which PBS currently reports as running. Backup task worker IDs
// normally identify "<store>:<type>/<id>". If a server version returns a less
diff --git a/internal/monitoring/monitor_full_coverage_test.go b/internal/monitoring/monitor_full_coverage_test.go
index b079a3ff16..d78afc044e 100644
--- a/internal/monitoring/monitor_full_coverage_test.go
+++ b/internal/monitoring/monitor_full_coverage_test.go
@@ -7,6 +7,7 @@ import (
"net/http"
"net/http/httptest"
"strings"
+ "sync/atomic"
"testing"
"time"
@@ -1050,3 +1051,86 @@ func TestMonitor_EvaluateAgents(t *testing.T) {
}
}
}
+
+func TestClearPBSWriteActivityObservationIsPollScoped(t *testing.T) {
+ backups := []models.PBSBackup{
+ {InProgress: true, WriteActivityObserved: true, WriteActive: true},
+ {InProgress: true, WriteActivityObserved: true},
+ {WriteActivityObserved: true, WriteActive: true},
+ }
+
+ clearPBSWriteActivityObservation(backups)
+
+ for i, backup := range backups {
+ if backup.WriteActivityObserved || backup.WriteActive {
+ t.Fatalf("backup %d retained stale write activity: %+v", i, backup)
+ }
+ }
+}
+
+// A snapshot-list failure falls back to the cached artifact. If the separate
+// running-task read also fails, the previous poll's authoritative no-writer
+// result must not survive as current evidence.
+func TestPollPBSBackupsCachedIncompleteSnapshotLosesStaleTaskObservation(t *testing.T) {
+ t.Parallel()
+
+ var snapshotRequests atomic.Int64
+ var taskRequests atomic.Int64
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ switch {
+ case strings.Contains(r.URL.Path, "/admin/datastore/archive/groups"):
+ _, _ = w.Write([]byte(`{"data":[{"backup-type":"vm","backup-id":"117","last-backup":1800000000,"backup-count":1}]}`))
+ case strings.Contains(r.URL.Path, "/admin/datastore/archive/snapshots"):
+ snapshotRequests.Add(1)
+ http.Error(w, `{"errors":"temporary snapshot failure"}`, http.StatusInternalServerError)
+ case r.URL.Path == "/api2/json/nodes/localhost/tasks":
+ taskRequests.Add(1)
+ http.Error(w, `{"errors":"temporary task failure"}`, http.StatusInternalServerError)
+ default:
+ http.NotFound(w, r)
+ }
+ }))
+ defer server.Close()
+
+ client, err := pbs.NewClient(pbs.ClientConfig{
+ Host: server.URL,
+ TokenName: "root@pam!token",
+ TokenValue: "test-token",
+ })
+ if err != nil {
+ t.Fatalf("create PBS client: %v", err)
+ }
+
+ m := &Monitor{state: models.NewState()}
+ m.state.UpdatePBSBackups("pbs1", []models.PBSBackup{{
+ ID: "pbs-pbs1-archive--vm-117-1800000000",
+ Instance: "pbs1",
+ Datastore: "archive",
+ BackupType: "vm",
+ VMID: "117",
+ BackupTime: time.Unix(1800000000, 0),
+ InProgress: true,
+ WriteActivityObserved: true,
+ WriteActive: false,
+ }})
+
+ m.pollPBSBackups(context.Background(), "pbs1", client, []models.PBSDatastore{{Name: "archive"}})
+
+ if snapshotRequests.Load() != 1 {
+ t.Fatalf("snapshot requests = %d, want 1 cached fallback attempt", snapshotRequests.Load())
+ }
+ if taskRequests.Load() != 1 {
+ t.Fatalf("task requests = %d, want 1 failed current-task attempt", taskRequests.Load())
+ }
+
+ backups := m.state.GetSnapshot().PBSBackups
+ if len(backups) != 1 {
+ t.Fatalf("PBS backups = %d, want cached incomplete snapshot", len(backups))
+ }
+ if !backups[0].InProgress {
+ t.Fatalf("cached snapshot lost incomplete state: %+v", backups[0])
+ }
+ if backups[0].WriteActivityObserved || backups[0].WriteActive {
+ t.Fatalf("cached snapshot retained stale task observation: %+v", backups[0])
+ }
+}