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.

Stabilize demo infrastructure mock posture

rcourtmana4bbea9ed9b8
diff --git a/internal/mock/demo_scenarios.go b/internal/mock/demo_scenarios.go
index e7571e7d22..722fda8948 100644
--- a/internal/mock/demo_scenarios.go
+++ b/internal/mock/demo_scenarios.go
@@ -153,8 +153,10 @@ func applyDemoScenarioGraph(graph *FixtureGraph, now time.Time) {
containerNames := applyDemoContainerScenario(graph.State.Containers, demoContainerProfiles, now)
applyDemoDockerScenario(&graph.State, now)
applyDemoKubernetesScenario(&graph.State, now)
- applyDemoStorageScenario(&graph.State)
+ applyDemoHostScenario(&graph.State, now)
+ applyDemoStorageScenario(&graph.State, now)
applyDemoBackupScenario(&graph.State, vmNames, containerNames, now)
+ syncDemoConnectionHealth(&graph.State)
}
func applyDemoPlatformScenario(fixtures *PlatformFixtures) {
@@ -514,7 +516,27 @@ func applyDemoKubernetesScenario(state *models.StateSnapshot, now time.Time) {
syncMockKubernetesNodeHosts(state)
}
-func applyDemoStorageScenario(state *models.StateSnapshot) {
+func applyDemoHostScenario(state *models.StateSnapshot, now time.Time) {
+ if state == nil {
+ return
+ }
+
+ for i := range state.Hosts {
+ host := &state.Hosts[i]
+ host.Status = "online"
+ if strings.TrimSpace(host.DisplayName) == "" {
+ host.DisplayName = humanizeHostDisplayName(host.Hostname)
+ }
+ if now.IsZero() {
+ continue
+ }
+ if host.LastSeen.IsZero() || host.LastSeen.Before(now.Add(-2*time.Minute)) || host.LastSeen.After(now) {
+ host.LastSeen = demoRecentSeenAt(now, "host", host.ID, host.Hostname)
+ }
+ }
+}
+
+func applyDemoStorageScenario(state *models.StateSnapshot, now time.Time) {
if state == nil {
return
}
@@ -529,6 +551,9 @@ func applyDemoStorageScenario(state *models.StateSnapshot) {
for i := range state.PBSInstances {
state.PBSInstances[i].Name = []string{"backup-vault", "dr-vault"}[minInt(i, 1)]
+ state.PBSInstances[i].Status = "online"
+ state.PBSInstances[i].ConnectionHealth = "healthy"
+ state.PBSInstances[i].LastSeen = demoRecentSeenAt(now, "pbs", state.PBSInstances[i].ID, state.PBSInstances[i].Name)
if len(state.PBSInstances[i].Datastores) > 0 {
datastoreNames := []string{"primary-vault", "offsite-vault", "replica-vault"}
for j := range state.PBSInstances[i].Datastores {
@@ -546,7 +571,70 @@ func applyDemoStorageScenario(state *models.StateSnapshot) {
} else {
state.PMGInstances[i].Name = "mail-gateway-us"
}
+ state.PMGInstances[i].Status = "online"
+ state.PMGInstances[i].ConnectionHealth = "healthy"
+ state.PMGInstances[i].LastSeen = demoRecentSeenAt(now, "pmg", state.PMGInstances[i].ID, state.PMGInstances[i].Name)
+ }
+}
+
+func syncDemoConnectionHealth(state *models.StateSnapshot) {
+ if state == nil {
+ return
+ }
+ if state.ConnectionHealth == nil {
+ state.ConnectionHealth = make(map[string]bool)
+ }
+
+ for key := range state.ConnectionHealth {
+ switch {
+ case strings.HasPrefix(key, "docker-"),
+ strings.HasPrefix(key, "kubernetes-"),
+ strings.HasPrefix(key, "host-"),
+ strings.HasPrefix(key, "pbs-"),
+ strings.HasPrefix(key, "pmg-"),
+ strings.HasPrefix(key, "pve-"):
+ delete(state.ConnectionHealth, key)
+ }
+ }
+
+ for _, node := range state.Nodes {
+ if name := strings.TrimSpace(node.Name); name != "" {
+ state.ConnectionHealth["pve-"+name] = !strings.EqualFold(strings.TrimSpace(node.Status), "offline")
+ }
+ }
+ for _, host := range state.DockerHosts {
+ if id := strings.TrimSpace(host.ID); id != "" {
+ state.ConnectionHealth[dockerConnectionPrefix+id] = !strings.EqualFold(strings.TrimSpace(host.Status), "offline")
+ }
+ }
+ for _, cluster := range state.KubernetesClusters {
+ if id := strings.TrimSpace(cluster.ID); id != "" {
+ state.ConnectionHealth[kubernetesConnectionPrefix+id] = !strings.EqualFold(strings.TrimSpace(cluster.Status), "offline")
+ }
+ }
+ for _, host := range state.Hosts {
+ if id := strings.TrimSpace(host.ID); id != "" {
+ state.ConnectionHealth[hostConnectionPrefix+id] = !strings.EqualFold(strings.TrimSpace(host.Status), "offline")
+ }
+ }
+ for _, inst := range state.PBSInstances {
+ if name := strings.TrimSpace(inst.Name); name != "" {
+ state.ConnectionHealth["pbs-"+name] = !strings.EqualFold(strings.TrimSpace(inst.Status), "offline")
+ }
+ }
+ for _, inst := range state.PMGInstances {
+ if name := strings.TrimSpace(inst.Name); name != "" {
+ state.ConnectionHealth["pmg-"+name] = !strings.EqualFold(strings.TrimSpace(inst.Status), "offline")
+ }
+ }
+}
+
+func demoRecentSeenAt(now time.Time, parts ...string) time.Time {
+ if now.IsZero() {
+ now = time.Now().UTC()
}
+ offsetSeconds := 4 + mockStableChoice(15, parts...)
+ return now.UTC().Add(-time.Duration(offsetSeconds) * time.Second)
}
func applyDemoBackupScenario(
diff --git a/internal/mock/demo_scenarios_test.go b/internal/mock/demo_scenarios_test.go
index 68f6a41810..fa63abe32b 100644
--- a/internal/mock/demo_scenarios_test.go
+++ b/internal/mock/demo_scenarios_test.go
@@ -112,6 +112,91 @@ func TestFixtureGraphUpdateMetricsPreservesCuratedDemoScenario(t *testing.T) {
}
}
+func TestFixtureGraphUpdateMetricsRestoresStableDemoInfrastructurePosture(t *testing.T) {
+ cfg := DefaultConfig
+ cfg.RandomMetrics = true
+
+ start := time.Date(2026, time.April, 1, 12, 0, 0, 0, time.UTC)
+ later := start.Add(45 * time.Minute)
+
+ graph := buildFixtureGraph(cfg, start)
+
+ for i := range graph.State.Hosts {
+ graph.State.Hosts[i].Status = "offline"
+ graph.State.Hosts[i].LastSeen = time.Time{}
+ }
+ for i := range graph.State.DockerHosts {
+ graph.State.DockerHosts[i].Status = "offline"
+ }
+ for i := range graph.State.KubernetesClusters {
+ graph.State.KubernetesClusters[i].Status = "offline"
+ for j := range graph.State.KubernetesClusters[i].Nodes {
+ graph.State.KubernetesClusters[i].Nodes[j].Ready = false
+ graph.State.KubernetesClusters[i].Nodes[j].Unschedulable = true
+ }
+ }
+ for i := range graph.State.PBSInstances {
+ graph.State.PBSInstances[i].Status = "offline"
+ graph.State.PBSInstances[i].ConnectionHealth = "error"
+ graph.State.PBSInstances[i].LastSeen = time.Time{}
+ }
+ for i := range graph.State.PMGInstances {
+ graph.State.PMGInstances[i].Status = "offline"
+ graph.State.PMGInstances[i].ConnectionHealth = "error"
+ graph.State.PMGInstances[i].LastSeen = time.Time{}
+ }
+ graph.State.ConnectionHealth = map[string]bool{
+ "docker-stale": false,
+ "kubernetes-stale": false,
+ "host-stale": false,
+ "pbs-stale": false,
+ "pmg-stale": false,
+ "pve-stale": false,
+ }
+
+ graph.UpdateMetrics(cfg, later)
+
+ if !allHostsOnline(graph) {
+ t.Fatal("expected demo host agents to restore online status after metric refresh")
+ }
+ if !allDockerHostsOnline(graph) {
+ t.Fatal("expected curated docker hosts to restore online status after metric refresh")
+ }
+ if !allKubernetesClustersOnline(graph) {
+ t.Fatal("expected curated kubernetes clusters to restore online status after metric refresh")
+ }
+ if !allKubernetesNodesReady(graph) {
+ t.Fatal("expected curated kubernetes nodes to restore ready status after metric refresh")
+ }
+ if !allPBSInstancesOnlineHealthy(graph) {
+ t.Fatal("expected curated PBS posture to restore healthy online status after metric refresh")
+ }
+ if !allPMGInstancesOnlineHealthy(graph) {
+ t.Fatal("expected curated PMG posture to restore healthy online status after metric refresh")
+ }
+ if !connectionHealthMatchesCuratedDemoState(graph) {
+ t.Fatal("expected connection-health map to match the final curated demo state after metric refresh")
+ }
+ if _, ok := graph.State.ConnectionHealth["docker-stale"]; ok {
+ t.Fatal("expected stale docker connection-health keys to be cleared")
+ }
+ if _, ok := graph.State.ConnectionHealth["kubernetes-stale"]; ok {
+ t.Fatal("expected stale kubernetes connection-health keys to be cleared")
+ }
+ if _, ok := graph.State.ConnectionHealth["host-stale"]; ok {
+ t.Fatal("expected stale host-agent connection-health keys to be cleared")
+ }
+ if _, ok := graph.State.ConnectionHealth["pbs-stale"]; ok {
+ t.Fatal("expected stale PBS connection-health keys to be cleared")
+ }
+ if _, ok := graph.State.ConnectionHealth["pmg-stale"]; ok {
+ t.Fatal("expected stale PMG connection-health keys to be cleared")
+ }
+ if _, ok := graph.State.ConnectionHealth["pve-stale"]; ok {
+ t.Fatal("expected stale PVE connection-health keys to be cleared")
+ }
+}
+
func vmNameExists(graph FixtureGraph, want string) bool {
for _, vm := range graph.State.VMs {
if vm.Name == want {
@@ -237,6 +322,114 @@ func pmgInstanceExists(graph FixtureGraph, want string) bool {
return false
}
+func allHostsOnline(graph FixtureGraph) bool {
+ for _, host := range graph.State.Hosts {
+ if host.Status != "online" {
+ return false
+ }
+ }
+ return true
+}
+
+func allDockerHostsOnline(graph FixtureGraph) bool {
+ for _, host := range graph.State.DockerHosts {
+ if host.Status != "online" {
+ return false
+ }
+ }
+ return true
+}
+
+func allKubernetesClustersOnline(graph FixtureGraph) bool {
+ for _, cluster := range graph.State.KubernetesClusters {
+ if cluster.Status != "online" {
+ return false
+ }
+ }
+ return true
+}
+
+func allKubernetesNodesReady(graph FixtureGraph) bool {
+ for _, cluster := range graph.State.KubernetesClusters {
+ for _, node := range cluster.Nodes {
+ if !node.Ready || node.Unschedulable {
+ return false
+ }
+ }
+ }
+ return true
+}
+
+func allPBSInstancesOnlineHealthy(graph FixtureGraph) bool {
+ for _, instance := range graph.State.PBSInstances {
+ if instance.Status != "online" || instance.ConnectionHealth != "healthy" {
+ return false
+ }
+ }
+ return true
+}
+
+func allPMGInstancesOnlineHealthy(graph FixtureGraph) bool {
+ for _, instance := range graph.State.PMGInstances {
+ if instance.Status != "online" || instance.ConnectionHealth != "healthy" {
+ return false
+ }
+ }
+ return true
+}
+
+func connectionHealthMatchesCuratedDemoState(graph FixtureGraph) bool {
+ for _, node := range graph.State.Nodes {
+ key := "pve-" + strings.TrimSpace(node.Name)
+ expected := !strings.EqualFold(strings.TrimSpace(node.Status), "offline")
+ healthy, ok := graph.State.ConnectionHealth[key]
+ if key == "pve-" || !ok || healthy != expected {
+ return false
+ }
+ }
+ for _, host := range graph.State.DockerHosts {
+ key := "docker-" + strings.TrimSpace(host.ID)
+ expected := !strings.EqualFold(strings.TrimSpace(host.Status), "offline")
+ healthy, ok := graph.State.ConnectionHealth[key]
+ if key == "docker-" || !ok || healthy != expected {
+ return false
+ }
+ }
+ for _, cluster := range graph.State.KubernetesClusters {
+ key := "kubernetes-" + strings.TrimSpace(cluster.ID)
+ expected := !strings.EqualFold(strings.TrimSpace(cluster.Status), "offline")
+ healthy, ok := graph.State.ConnectionHealth[key]
+ if key == "kubernetes-" || !ok || healthy != expected {
+ return false
+ }
+ }
+ for _, host := range graph.State.Hosts {
+ key := "host-" + strings.TrimSpace(host.ID)
+ expected := !strings.EqualFold(strings.TrimSpace(host.Status), "offline")
+ healthy, ok := graph.State.ConnectionHealth[key]
+ if key == "host-" || !ok || healthy != expected {
+ return false
+ }
+ }
+ for _, instance := range graph.State.PBSInstances {
+ key := "pbs-" + strings.TrimSpace(instance.Name)
+ expected := !strings.EqualFold(strings.TrimSpace(instance.Status), "offline")
+ healthy, ok := graph.State.ConnectionHealth[key]
+ if key == "pbs-" || !ok || healthy != expected {
+ return false
+ }
+ }
+ for _, instance := range graph.State.PMGInstances {
+ key := "pmg-" + strings.TrimSpace(instance.Name)
+ expected := !strings.EqualFold(strings.TrimSpace(instance.Status), "offline")
+ healthy, ok := graph.State.ConnectionHealth[key]
+ if key == "pmg-" || !ok || healthy != expected {
+ return false
+ }
+ }
+ return true
+}
+
func firstLegacyMockClusterLeak(graph FixtureGraph) string {
for _, node := range graph.State.Nodes {
if strings.EqualFold(node.Instance, "mock-cluster") || strings.EqualFold(node.ClusterName, "mock-cluster") {