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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Preserve archive kind during final state placement alignment
pulse-triage[bot]92606aff19c9
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 36a4f0b71c..1950779e75 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -31,12 +31,16 @@ live guest lookup, the archive retains its historical typed canonical subjectwithout borrowing the new occupant's ID or display name. Collector placementlookup likewise ignores an opposite-kind occupant: its archive keeps the readnode, while a same-kind migrated guest still supplies its actual placement.-The independent local storage read origin and archive ID are unchanged.+The final state-layer alignment uses the same typed fence, so publishing+the list cannot undo the collector decision. Both date and placement selection+share the model's explicit-kind normalisation; legacy/untyped fallback remains+unchanged. The independent local storage read origin and archive ID are unchanged.Same-kind metadata and legacy/untyped fallback retain their existing behaviour.The point ID, archive time, size and public JSON shape do not change. Ordinarycollection updates existing point attribution; no deletion, schema migration,backup/restore or guest-agent operation is introduced.+`TestUpdateStorageBackupsForInstanceKeepsArchiveGuestKind`,`TestSyncGuestBackupTimesLocalArchiveGuestKinds`,`TestFromPVEStorageBackupsRetainsExplicitGuestKind` and the normal-suite`TestPVEArchiveSubjectKindLifecycle` cover both replacement directions, aliases,diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 1d36dc9c8e..0ff56c8cd8 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -35,12 +35,16 @@ live guest lookup, the archive retains its historical typed canonical subjectwithout borrowing the new occupant's ID or display name. Collector placementlookup likewise ignores an opposite-kind occupant: its archive keeps the readnode, while a same-kind migrated guest still supplies its actual placement.-The independent local storage read origin and archive ID are unchanged.+The final state-layer alignment uses the same typed fence, so publishing+the list cannot undo the collector decision. Both date and placement selection+share the model's explicit-kind normalisation; legacy/untyped fallback remains+unchanged. The independent local storage read origin and archive ID are unchanged.Same-kind metadata and legacy/untyped fallback retain their existing behaviour.The point ID, archive time, size and public JSON shape do not change. Ordinarycollection updates existing point attribution; no deletion, schema migration,backup/restore or guest-agent operation is introduced.+`TestUpdateStorageBackupsForInstanceKeepsArchiveGuestKind`,`TestSyncGuestBackupTimesLocalArchiveGuestKinds`,`TestFromPVEStorageBackupsRetainsExplicitGuestKind` and the normal-suite`TestPVEArchiveSubjectKindLifecycle` cover both replacement directions, aliases,diff --git a/internal/models/models.go b/internal/models/models.goindex 7c6b36f862..780497aae5 100644--- a/internal/models/models.go+++ b/internal/models/models.go@@ -4625,6 +4625,25 @@ func backupKey(instance string, vmid int) string {return instance + "-" + strconv.Itoa(vmid)}+type localBackupSubjectKey struct {+ instance, guestType string+ vmid int+}++// localBackupGuestType keeps explicit archive kinds consistent between date+// selection and placement alignment. An untyped legacy row keeps its existing+// best-effort VMID lookup; a known contradictory kind never uses that fallback.+func localBackupGuestType(kind string) string {+ switch strings.ToLower(strings.TrimSpace(kind)) {+ case "qemu", "vm":+ return "vm"+ case "lxc", "ct":+ return "ct"+ default:+ return ""+ }+}+// UpdatePBSGuestConfirmationsForInstance replaces the PVE-side PBS snapshot// evidence for one connection. Pass an empty slice when the connection's// storage poll saw no pbs-type storage content so stale evidence cannot@@ -4713,11 +4732,7 @@ func (s *State) SyncGuestBackupTimes() {// A retained archive may belong to the other guest kind after VMID reuse.// Keep its kind as well as its connection; the live occupant cannot turn// a removed VM's archive into an LXC backup (or the reverse).- type localSubjectKey struct {- instance, guestType string- vmid int- }- latestBackup := make(map[localSubjectKey]time.Time)+ latestBackup := make(map[localBackupSubjectKey]time.Time)// Guests with a backup running right now: a live vzdump task is the// authoritative PVE-side signal. Partial artifacts (an in-flight PBS@@ -4758,23 +4773,16 @@ func (s *State) SyncGuestBackupTimes() {// above already reports the guest as backing up.continue}- guestType := ""- switch strings.ToLower(strings.TrimSpace(backup.Type)) {- case "qemu", "vm":- guestType = "vm"- case "lxc", "ct":- guestType = "ct"- }- key := localSubjectKey{backup.Instance, guestType, backup.VMID}+ key := localBackupSubjectKey{backup.Instance, localBackupGuestType(backup.Type), backup.VMID}if existing, ok := latestBackup[key]; !ok || backup.Time.After(existing) {latestBackup[key] = backup.Time}}latestLocalBackup := func(instance string, vmid int, guestType string) time.Time {- latest := latestBackup[localSubjectKey{instance, guestType, vmid}]+ latest := latestBackup[localBackupSubjectKey{instance, guestType, vmid}]// Preserve best-effort matching of older/untyped rows. Only an explicit// artifact discriminator can establish a contradictory guest kind.- if untyped := latestBackup[localSubjectKey{instance, "", vmid}]; untyped.After(latest) {+ if untyped := latestBackup[localBackupSubjectKey{instance, "", vmid}]; untyped.After(latest) {latest = untyped}return latest@@ -6274,22 +6282,27 @@ func (s *State) UpdateStorageBackupsForInstance(instanceName string, backups []S// When storage is shared across nodes, backups can appear under whichever node reported the content.// Align each backup with the guest's current node so the frontend column matches the VM/CT placement.- guestNodeByVMID := make(map[int]string)+ // Keep explicit kinds here too: this final state alignment must not undo+ // the collector's refusal to borrow an opposite-kind replacement's node.+ guestNodeBySubject := make(map[localBackupSubjectKey]string)for _, vm := range s.VMs {if vm.Instance == instanceName && vm.Node != "" {- guestNodeByVMID[vm.VMID] = vm.Node+ guestNodeBySubject[localBackupSubjectKey{instanceName, "vm", vm.VMID}] = vm.Node+ guestNodeBySubject[localBackupSubjectKey{instanceName, "", vm.VMID}] = vm.Node}}for _, ct := range s.Containers {if ct.Instance == instanceName && ct.Node != "" {- guestNodeByVMID[ct.VMID] = ct.Node+ guestNodeBySubject[localBackupSubjectKey{instanceName, "ct", ct.VMID}] = ct.Node+ guestNodeBySubject[localBackupSubjectKey{instanceName, "", ct.VMID}] = ct.Node}}normalizedBackups := make([]StorageBackup, 0, len(backups))for _, backup := range backups {if backup.VMID > 0 {- if node, ok := guestNodeByVMID[backup.VMID]; ok {+ key := localBackupSubjectKey{instanceName, localBackupGuestType(backup.Type), backup.VMID}+ if node, ok := guestNodeBySubject[key]; ok {backup.Node = node}}diff --git a/internal/models/state_host_test.go b/internal/models/state_host_test.goindex da263e1431..d23545fa81 100644--- a/internal/models/state_host_test.go+++ b/internal/models/state_host_test.go@@ -2265,3 +2265,38 @@ func TestUpdateNodesForInstanceHoldsASplitAgentBackBeforeItFoldsNodeViews(t *tes}}}++func TestUpdateStorageBackupsForInstanceKeepsArchiveGuestKind(t *testing.T) {+ for _, kind := range []string{"qemu", "vm", " QEMU ", "lxc", "ct", " LXC ", "", "unknown"} {+ t.Run(kind, func(t *testing.T) {+ state := NewState()+ state.UpdateVMs([]VM{{VMID: 100, Instance: "a", Node: "vm-node"}, {VMID: 100, Instance: "b", Node: "other-cluster"}})+ state.UpdateContainers([]Container{{VMID: 101, Instance: "a", Node: "ct-node"}})+ rows := []StorageBackup{{ID: "100", Instance: "a", VMID: 100, Node: "read-node", StorageNode: "read-node", Type: kind}, {ID: "101", Instance: "a", VMID: 101, Node: "read-node", StorageNode: "read-node", Type: kind}}+ state.UpdateStorageBackupsForInstance("a", rows)+ want100, want101 := "vm-node", "ct-node"+ switch kind {+ case "qemu", "vm", " QEMU ":+ want101 = "read-node"+ case "lxc", "ct", " LXC ":+ want100 = "read-node"+ }+ snapshot := state.GetSnapshot()+ if len(snapshot.PVEBackups.StorageBackups) != 2 {+ t.Fatal("archive count changed")+ }+ for _, b := range snapshot.PVEBackups.StorageBackups {+ want := want100+ if b.VMID == 101 {+ want = want101+ }+ if b.Node != want || b.StorageNode != "read-node" || b.Type != kind {+ t.Errorf("explicit kind borrowed opposite placement or lost original facts: %+v want=%s", b, want)+ }+ }+ if rows[0].Node != "read-node" || rows[1].Node != "read-node" {+ t.Error("state alignment mutated caller archive facts")+ }+ })+ }+}