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
Stabilize RC release backend race proofs
rcourtmanb38d0ac37e40
diff --git a/internal/mock/integration.go b/internal/mock/integration.goindex aaf45f3c45..fa1790bc81 100644--- a/internal/mock/integration.go+++ b/internal/mock/integration.go@@ -550,90 +550,5 @@ func GetMockAlertHistory(limit int) []models.Alert {}func cloneState(state models.StateSnapshot) models.StateSnapshot {- kubernetesClusters := make([]models.KubernetesCluster, len(state.KubernetesClusters))- for i, cluster := range state.KubernetesClusters {- clusterCopy := cluster-- clusterCopy.Nodes = append([]models.KubernetesNode(nil), cluster.Nodes...)-- clusterCopy.Pods = make([]models.KubernetesPod, len(cluster.Pods))- for j, pod := range cluster.Pods {- podCopy := pod-- if pod.Labels != nil {- labelsCopy := make(map[string]string, len(pod.Labels))- for k, v := range pod.Labels {- labelsCopy[k] = v- }- podCopy.Labels = labelsCopy- }-- podCopy.Containers = append([]models.KubernetesPodContainer(nil), pod.Containers...)- clusterCopy.Pods[j] = podCopy- }-- clusterCopy.Deployments = make([]models.KubernetesDeployment, len(cluster.Deployments))- for j, dep := range cluster.Deployments {- depCopy := dep- if dep.Labels != nil {- labelsCopy := make(map[string]string, len(dep.Labels))- for k, v := range dep.Labels {- labelsCopy[k] = v- }- depCopy.Labels = labelsCopy- }- clusterCopy.Deployments[j] = depCopy- }-- kubernetesClusters[i] = clusterCopy- }-- copyState := models.StateSnapshot{- Nodes: append([]models.Node(nil), state.Nodes...),- VMs: append([]models.VM(nil), state.VMs...),- Containers: append([]models.Container(nil), state.Containers...),- DockerHosts: append([]models.DockerHost(nil), state.DockerHosts...),- RemovedDockerHosts: append([]models.RemovedDockerHost(nil), state.RemovedDockerHosts...),- KubernetesClusters: kubernetesClusters,- RemovedKubernetesClusters: append([]models.RemovedKubernetesCluster(nil), state.RemovedKubernetesClusters...),- Hosts: append([]models.Host(nil), state.Hosts...),- RemovedHostAgents: append([]models.RemovedHostAgent(nil), state.RemovedHostAgents...),- PMGInstances: append([]models.PMGInstance(nil), state.PMGInstances...),- Storage: append([]models.Storage(nil), state.Storage...),- CephClusters: append([]models.CephCluster(nil), state.CephClusters...),- PhysicalDisks: append([]models.PhysicalDisk(nil), state.PhysicalDisks...),- PBSInstances: append([]models.PBSInstance(nil), state.PBSInstances...),- PBSBackups: append([]models.PBSBackup(nil), state.PBSBackups...),- PMGBackups: append([]models.PMGBackup(nil), state.PMGBackups...),- ReplicationJobs: append([]models.ReplicationJob(nil), state.ReplicationJobs...),- Metrics: append([]models.Metric(nil), state.Metrics...),- Performance: state.Performance,- Stats: state.Stats,- ActiveAlerts: append([]models.Alert(nil), state.ActiveAlerts...),- RecentlyResolved: append([]models.ResolvedAlert(nil), state.RecentlyResolved...),- LastUpdate: state.LastUpdate,- ConnectionHealth: make(map[string]bool, len(state.ConnectionHealth)),- }- copyState.NormalizeCollections()-- copyState.PVEBackups = models.PVEBackups{- BackupTasks: append([]models.BackupTask(nil), state.PVEBackups.BackupTasks...),- StorageBackups: append([]models.StorageBackup(nil), state.PVEBackups.StorageBackups...),- GuestSnapshots: append([]models.GuestSnapshot(nil), state.PVEBackups.GuestSnapshots...),- }- copyState.Backups = models.Backups{- PVE: models.PVEBackups{- BackupTasks: append([]models.BackupTask(nil), state.Backups.PVE.BackupTasks...),- StorageBackups: append([]models.StorageBackup(nil), state.Backups.PVE.StorageBackups...),- GuestSnapshots: append([]models.GuestSnapshot(nil), state.Backups.PVE.GuestSnapshots...),- },- PBS: append([]models.PBSBackup(nil), state.Backups.PBS...),- PMG: append([]models.PMGBackup(nil), state.Backups.PMG...),- }-- for k, v := range state.ConnectionHealth {- copyState.ConnectionHealth[k] = v- }-- return copyState+ return state.Clone()}diff --git a/internal/mock/recovery_points_test.go b/internal/mock/recovery_points_test.goindex fb7af29a93..73ee5f2193 100644--- a/internal/mock/recovery_points_test.go+++ b/internal/mock/recovery_points_test.go@@ -23,9 +23,33 @@ func TestCurrentFixtureGraphReturnsDefensiveCopies(t *testing.T) {originalNodeName := graph.State.Nodes[0].NameoriginalHostName := graph.PlatformFixtures.VMware.Hosts[0].Name+ var (+ originalDockerLabelKey string+ originalDockerLabel string+ originalDockerMount string+ )+ if len(graph.State.DockerHosts) > 0 && len(graph.State.DockerHosts[0].Containers) > 0 {+ for key, value := range graph.State.DockerHosts[0].Containers[0].Labels {+ originalDockerLabelKey = key+ originalDockerLabel = value+ break+ }+ if len(graph.State.DockerHosts[0].Containers[0].Mounts) > 0 {+ originalDockerMount = graph.State.DockerHosts[0].Containers[0].Mounts[0].Destination+ }+ }graph.State.Nodes[0].Name = "mutated-node"graph.PlatformFixtures.VMware.Hosts[0].Name = "mutated-host"+ if len(graph.State.DockerHosts) > 0 && len(graph.State.DockerHosts[0].Containers) > 0 {+ for key := range graph.State.DockerHosts[0].Containers[0].Labels {+ graph.State.DockerHosts[0].Containers[0].Labels[key] = "mutated-container"+ break+ }+ if len(graph.State.DockerHosts[0].Containers[0].Mounts) > 0 {+ graph.State.DockerHosts[0].Containers[0].Mounts[0].Destination = "/mutated"+ }+ }if len(graph.AlertHistory) > 0 {graph.AlertHistory[0].ID = "mutated-alert"}@@ -37,6 +61,15 @@ func TestCurrentFixtureGraphReturnsDefensiveCopies(t *testing.T) {if current.PlatformFixtures.VMware.Hosts[0].Name != originalHostName {t.Fatalf("expected canonical graph to protect platform fixtures, got %q", current.PlatformFixtures.VMware.Hosts[0].Name)}+ if originalDockerLabelKey != "" && current.State.DockerHosts[0].Containers[0].Labels[originalDockerLabelKey] != originalDockerLabel {+ t.Fatalf(+ "expected canonical graph to protect nested docker container labels, got %q",+ current.State.DockerHosts[0].Containers[0].Labels[originalDockerLabelKey],+ )+ }+ if originalDockerMount != "" && current.State.DockerHosts[0].Containers[0].Mounts[0].Destination != originalDockerMount {+ t.Fatalf("expected canonical graph to protect nested docker container mounts, got %q", current.State.DockerHosts[0].Containers[0].Mounts[0].Destination)+ }if len(graph.AlertHistory) > 0 && len(current.AlertHistory) > 0 && current.AlertHistory[0].ID == "mutated-alert" {t.Fatal("expected canonical graph to protect alert history")}diff --git a/internal/models/state_snapshot.go b/internal/models/state_snapshot.goindex c653db198f..2ffb5a1908 100644--- a/internal/models/state_snapshot.go+++ b/internal/models/state_snapshot.go@@ -149,6 +149,49 @@ func (s *StateSnapshot) NormalizeCollections() {s.Performance = s.Performance.NormalizeCollections()}+// Clone returns a deep copy of the snapshot so callers can safely hold a+// detached view without sharing nested collection state.+func (s StateSnapshot) Clone() StateSnapshot {+ pbsBackups := clonePBSBackups(s.PBSBackups)+ pmgBackups := clonePMGBackups(s.PMGBackups)+ pveBackups := clonePVEBackups(s.PVEBackups)++ snapshot := StateSnapshot{+ Nodes: cloneNodes(s.Nodes),+ VMs: cloneVMs(s.VMs),+ Containers: cloneContainers(s.Containers),+ DockerHosts: cloneDockerHosts(s.DockerHosts),+ RemovedDockerHosts: append([]RemovedDockerHost(nil), s.RemovedDockerHosts...),+ KubernetesClusters: cloneKubernetesClusters(s.KubernetesClusters),+ RemovedKubernetesClusters: append([]RemovedKubernetesCluster(nil), s.RemovedKubernetesClusters...),+ Hosts: cloneHosts(s.Hosts),+ RemovedHostAgents: append([]RemovedHostAgent(nil), s.RemovedHostAgents...),+ Storage: cloneStorages(s.Storage),+ CephClusters: cloneCephClusters(s.CephClusters),+ PhysicalDisks: clonePhysicalDisks(s.PhysicalDisks),+ PBSInstances: clonePBSInstances(s.PBSInstances),+ PMGInstances: clonePMGInstances(s.PMGInstances),+ PBSBackups: pbsBackups,+ PMGBackups: pmgBackups,+ Backups: Backups{PVE: pveBackups, PBS: pbsBackups, PMG: pmgBackups},+ ReplicationJobs: cloneReplicationJobs(s.ReplicationJobs),+ Metrics: cloneMetrics(s.Metrics),+ PVEBackups: pveBackups,+ Performance: clonePerformance(s.Performance),+ ConnectionHealth: make(map[string]bool, len(s.ConnectionHealth)),+ Stats: s.Stats,+ ActiveAlerts: cloneAlerts(s.ActiveAlerts),+ RecentlyResolved: cloneResolvedAlerts(s.RecentlyResolved),+ LastUpdate: s.LastUpdate,+ TemperatureMonitoringEnabled: s.TemperatureMonitoringEnabled,+ }+ for key, healthy := range s.ConnectionHealth {+ snapshot.ConnectionHealth[key] = healthy+ }+ snapshot.NormalizeCollections()+ return snapshot+}+// GetSnapshot returns a snapshot of the current state without mutexfunc (s *State) GetSnapshot() StateSnapshot {s.mu.RLock()diff --git a/internal/models/state_snapshot_additional_test.go b/internal/models/state_snapshot_additional_test.goindex babfa05f1e..5f029f2a8c 100644--- a/internal/models/state_snapshot_additional_test.go+++ b/internal/models/state_snapshot_additional_test.go@@ -310,6 +310,66 @@ func TestEmptyStateSnapshotReturnsNormalizedZeroSnapshot(t *testing.T) {}}+func TestStateSnapshotCloneDeepCopiesNestedCollections(t *testing.T) {+ snapshot := StateSnapshot{+ DockerHosts: []DockerHost{{+ ID: "docker-1",+ LoadAverage: []float64{0.1, 0.2, 0.3},+ NetworkInterfaces: []HostNetworkInterface{{Name: "eth0", Addresses: []string{"10.0.0.10"}}},+ Containers: []DockerContainer{{+ ID: "container-1",+ Labels: map[string]string{"app": "api"},+ Networks: []DockerContainerNetworkLink{{Name: "default"}},+ Mounts: []DockerContainerMount{{Source: "/data", Destination: "/srv/data"}},+ }},+ }},+ KubernetesClusters: []KubernetesCluster{{+ ID: "cluster-1",+ Pods: []KubernetesPod{{+ UID: "pod-1",+ Labels: map[string]string{"tier": "backend"},+ Containers: []KubernetesPodContainer{{Name: "api"}},+ }},+ }},+ ConnectionHealth: map[string]bool{"vmware": true},+ }++ cloned := snapshot.Clone()+ cloned.DockerHosts[0].LoadAverage[0] = 9.9+ cloned.DockerHosts[0].NetworkInterfaces[0].Addresses[0] = "10.0.0.99"+ cloned.DockerHosts[0].Containers[0].Labels["app"] = "mutated"+ cloned.DockerHosts[0].Containers[0].Networks[0].Name = "mutated"+ cloned.DockerHosts[0].Containers[0].Mounts[0].Destination = "/mutated"+ cloned.KubernetesClusters[0].Pods[0].Labels["tier"] = "mutated"+ cloned.KubernetesClusters[0].Pods[0].Containers[0].Name = "mutated"+ cloned.ConnectionHealth["vmware"] = false++ if snapshot.DockerHosts[0].LoadAverage[0] != 0.1 {+ t.Fatal("expected Clone to deep-copy docker host load averages")+ }+ if snapshot.DockerHosts[0].NetworkInterfaces[0].Addresses[0] != "10.0.0.10" {+ t.Fatal("expected Clone to deep-copy docker host network addresses")+ }+ if snapshot.DockerHosts[0].Containers[0].Labels["app"] != "api" {+ t.Fatal("expected Clone to deep-copy docker container labels")+ }+ if snapshot.DockerHosts[0].Containers[0].Networks[0].Name != "default" {+ t.Fatal("expected Clone to deep-copy docker container networks")+ }+ if snapshot.DockerHosts[0].Containers[0].Mounts[0].Destination != "/srv/data" {+ t.Fatal("expected Clone to deep-copy docker container mounts")+ }+ if snapshot.KubernetesClusters[0].Pods[0].Labels["tier"] != "backend" {+ t.Fatal("expected Clone to deep-copy kubernetes pod labels")+ }+ if snapshot.KubernetesClusters[0].Pods[0].Containers[0].Name != "api" {+ t.Fatal("expected Clone to deep-copy kubernetes pod containers")+ }+ if !snapshot.ConnectionHealth["vmware"] {+ t.Fatal("expected Clone to deep-copy connection health")+ }+}+func TestStateSnapshotNormalizeCollectionsNormalizesNestedResourceCollections(t *testing.T) {snapshot := StateSnapshot{Nodes: []Node{{diff --git a/internal/monitoring/mock_metrics_history_test.go b/internal/monitoring/mock_metrics_history_test.goindex 9bbf8f4d44..eb57d14164 100644--- a/internal/monitoring/mock_metrics_history_test.go+++ b/internal/monitoring/mock_metrics_history_test.go@@ -642,15 +642,16 @@ func TestSeedMockMetricsHistory_UsesCanonicalMockFixtureGraphForLegacyAndProvideif len(graph.PlatformFixtures.VMware.Hosts) == 0 {t.Fatal("expected canonical mock graph to include VMware fixtures")}+ mock.SetEnabled(false)now := time.Now()seedDuration := 7 * 24 * time.HoursampleInterval := time.MinutehistoryRetention := 7 * 24 * time.Hourif raceEnabled {- seedDuration = 2 * time.Hour- sampleInterval = 30 * time.Minute- historyRetention = 2 * time.Hour+ seedDuration = 5 * time.Minute+ sampleInterval = time.Minute+ historyRetention = 10 * time.Minute}cfg := metrics.DefaultConfig(t.TempDir())diff --git a/internal/relay/client_test.go b/internal/relay/client_test.goindex bbb5632537..44b4544e03 100644--- a/internal/relay/client_test.go+++ b/internal/relay/client_test.go@@ -9,6 +9,7 @@ import ("encoding/json""encoding/pem""fmt"+ "io""net/http""net/http/httptest""os"@@ -968,7 +969,7 @@ func TestClient_EncryptedChannelLifecycle(t *testing.T) {}func TestClient_HandleDataDecryptsBeforeReturning(t *testing.T) {- logger := zerolog.New(zerolog.NewTestWriter(t))+ logger := zerolog.New(io.Discard)mockAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {w.WriteHeader(http.StatusNoContent)