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.

Guard PBS runtime ownership instead of obsolete context spelling

pulse-triage[bot]da07bcb1f3a2
diff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.go
index 64693a1ef0..31b0962645 100644
--- a/internal/monitoring/canonical_guardrails_test.go
+++ b/internal/monitoring/canonical_guardrails_test.go
@@ -2602,7 +2602,12 @@ func TestReloadAndRuntimeContextStayOnCanonicalMonitoringPath(t *testing.T) {
"parentCtx := m.getRuntimeContext()",
},
"monitor_pbs_pmg.go": {
- "parentCtx := m.getRuntimeContext()",
+ "owner := m.beginPBSBackupPoll(instanceName, client, lastPoll, newLast)",
+ "parentCtx := context.WithValue(owner.ctx, pbsBackupPollContextKey{}, owner)",
+ },
+ "pbs_backup_poll.go": {
+ "parent := m.runtimeCtx",
+ "ctx, cancel := context.WithCancel(parent)",
},
"../config/config.go": {
"func LoadWithoutLoggingInit() (*Config, error) {",
@@ -2622,6 +2627,12 @@ func TestReloadAndRuntimeContextStayOnCanonicalMonitoringPath(t *testing.T) {
}
}
}
+
+ // PBS captures its runtime with the client and admission claim, rather
+ // than reading it again after starting the goroutine. Check the inherited
+ // context itself as well as the entry point so this remains a safety guard,
+ // not a requirement to restore an obsolete implementation spelling.
+ exercisePBSBackupRuntimeContext(t)
}
func TestUnifiedStorageMetricsFallbackToResourceIDWhenResolverTargetMissing(t *testing.T) {
diff --git a/internal/monitoring/pbs_backup_lifecycle_test.go b/internal/monitoring/pbs_backup_lifecycle_test.go
index eabeee4e88..a07cfc2f3b 100644
--- a/internal/monitoring/pbs_backup_lifecycle_test.go
+++ b/internal/monitoring/pbs_backup_lifecycle_test.go
@@ -19,6 +19,54 @@ func waitPBSBudget(t *testing.T, ch <-chan struct{}, phase string) {
}
}
+func exercisePBSBackupRuntimeContext(t *testing.T) {
+ t.Run("PBS inherits the canonical runtime", func(t *testing.T) {
+ type runtimeKey struct{}
+ value := new(int)
+ parent, cancel := context.WithTimeout(context.WithValue(context.Background(), runtimeKey{}, value), time.Minute)
+ defer cancel()
+ m := &Monitor{}
+ client := &pbs.Client{}
+ m.replacePBSClient("reader", client)
+ m.setRuntimeContext(parent, nil)
+ owner := m.beginPBSBackupPoll("reader", client, time.Time{}, time.Now())
+ if owner == nil {
+ t.Fatal("live runtime did not admit its PBS worker")
+ }
+ defer m.finishPBSBackupPoll("reader", owner)
+ if owner.ctx.Value(runtimeKey{}) != value {
+ t.Error("PBS worker does not inherit the runtime's context values")
+ }
+ deadline, ok := owner.ctx.Deadline()
+ want, _ := parent.Deadline()
+ if !ok || !deadline.Equal(want) {
+ t.Error("PBS worker does not inherit the runtime's deadline")
+ }
+ cancel()
+ if owner.ctx.Err() != context.Canceled {
+ t.Error("runtime cancellation did not reach its PBS worker")
+ }
+ if m.pbsBackupPollers["reader"] != owner {
+ t.Error("runtime cancellation released the claim before the worker exited")
+ }
+ })
+ t.Run("an ended runtime cannot admit PBS work", func(t *testing.T) {
+ parent, cancel := context.WithCancel(context.Background())
+ m := &Monitor{}
+ client := &pbs.Client{}
+ m.replacePBSClient("reader", client)
+ m.setRuntimeContext(parent, nil)
+ cancel()
+ if owner := m.beginPBSBackupPoll("reader", client, time.Time{}, time.Now()); owner != nil {
+ m.finishPBSBackupPoll("reader", owner)
+ t.Fatal("ended runtime admitted a PBS worker")
+ }
+ if len(m.pbsBackupPollers) != 0 || len(m.lastPBSBackupPoll) != 0 {
+ t.Error("rejected admission left a worker or postponed the next scan")
+ }
+ })
+}
+
func exercisePBSBudgetOwnerWithdrawal(t *testing.T) {
for _, transition := range []string{"runtime cancellation", "runtime replacement", "client replacement", "client retirement"} {
t.Run(transition, func(t *testing.T) {