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.

mock: extend offline/degraded posture to Docker, PBS, PMG, and host agents

rcourtman11ab890880d3
diff --git a/internal/mock/demo_scenarios.go b/internal/mock/demo_scenarios.go
index 388ff7b906..f31269e079 100644
--- a/internal/mock/demo_scenarios.go
+++ b/internal/mock/demo_scenarios.go
@@ -416,9 +416,19 @@ func applyDemoDockerScenario(state *models.StateSnapshot, now time.Time) {
sort.Slice(state.DockerHosts, func(i, j int) bool {
return state.DockerHosts[i].ID < state.DockerHosts[j].ID
})
+ // One docker host index is forced offline so the demo Docker page exposes a
+ // disconnected host with its containers shown as exited rather than running.
+ const offlineDockerIndex = 2
for i := range state.DockerHosts {
- hostProfile := demoDockerHostProfiles[i%len(demoDockerHostProfiles)]
host := &state.DockerHosts[i]
+ if i == offlineDockerIndex {
+ host.Hostname = "field-office-edge-01"
+ host.DisplayName = "Field Office Edge 01"
+ host.Status = "offline"
+ host.Containers = applyDemoOfflineDockerContainers(host.Containers, now)
+ continue
+ }
+ hostProfile := demoDockerHostProfiles[i%len(demoDockerHostProfiles)]
host.Hostname = hostProfile.Hostname
host.DisplayName = hostProfile.DisplayName
host.Status = "online"
@@ -436,6 +446,35 @@ func applyDemoDockerScenario(state *models.StateSnapshot, now time.Time) {
}
}
+func applyDemoOfflineDockerContainers(containers []models.DockerContainer, now time.Time) []models.DockerContainer {
+ sort.Slice(containers, func(i, j int) bool {
+ return containers[i].ID < containers[j].ID
+ })
+ offlineProfiles := []demoDockerContainerProfile{
+ {Name: "branch-portal", Image: "ghcr.io/pulse-demo/branch-portal:2026.04", Tags: []string{"edge", "web", "branch-office"}},
+ {Name: "branch-syncthing", Image: "linuxserver/syncthing:1.27.10", Tags: []string{"sync", "edge", "branch-office"}},
+ {Name: "branch-vpn", Image: "wireguard:1.0.20210914", Tags: []string{"vpn", "edge", "branch-office"}},
+ }
+ finished := now
+ if finished.IsZero() {
+ finished = time.Now()
+ }
+ finished = finished.Add(-18 * time.Minute)
+ for i := range containers {
+ profile := offlineProfiles[i%len(offlineProfiles)]
+ containers[i].Name = profile.Name
+ containers[i].Image = profile.Image
+ containers[i].Labels = mergeScenarioLabelSet(containers[i].Labels, profile.Tags)
+ containers[i].State = "exited"
+ containers[i].Status = "Exited (137) 18 minutes ago"
+ containers[i].Health = ""
+ containers[i].StartedAt = nil
+ finishedAt := finished
+ containers[i].FinishedAt = &finishedAt
+ }
+ return containers
+}
+
func applyDemoDockerContainerProfiles(
containers []models.DockerContainer,
profiles []demoDockerContainerProfile,
@@ -482,12 +521,19 @@ func applyDemoKubernetesScenario(state *models.StateSnapshot, now time.Time) {
cluster.DisplayName = "Production"
cluster.Status = "online"
+ // The last cluster simulates a worker outage: nodes that resolve to the
+ // `prod-euw1-k8s-03` profile are reported NotReady, which cascades to a
+ // degraded host status in syncMockKubernetesNodeHosts.
+ offlineWorkerProfile := ""
+ if clusterIndex == len(state.KubernetesClusters)-1 {
+ offlineWorkerProfile = "prod-euw1-k8s-03"
+ }
nodeNameMap := make(map[string]string, len(cluster.Nodes))
for i := range cluster.Nodes {
profile := demoKubernetesNodeProfiles[i%len(demoKubernetesNodeProfiles)]
oldName := cluster.Nodes[i].Name
cluster.Nodes[i].Name = profile.Name
- cluster.Nodes[i].Ready = true
+ cluster.Nodes[i].Ready = profile.Name != offlineWorkerProfile
cluster.Nodes[i].Unschedulable = false
cluster.Nodes[i].Roles = append([]string(nil), profile.Roles...)
nodeNameMap[oldName] = profile.Name
@@ -581,7 +627,8 @@ func applyDemoHostScenario(state *models.StateSnapshot, now time.Time) {
if strings.TrimSpace(host.DisplayName) == "" {
host.DisplayName = humanizeHostDisplayName(host.Hostname)
}
- if strings.ToLower(strings.TrimSpace(host.Hostname)) == "pve5" {
+ hostname := strings.ToLower(strings.TrimSpace(host.Hostname))
+ if hostname == "pve5" || hostname == "prod-euw1-k8s-03" {
host.Status = "offline"
host.CPUUsage = 0
host.Memory.Used = 0
@@ -624,8 +671,15 @@ func applyDemoStorageScenario(state *models.StateSnapshot, now time.Time) {
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"
+ if i == 1 {
+ // dr-vault simulates a degraded secondary so the PBS page shows a
+ // non-healthy instance alongside the healthy primary.
+ state.PBSInstances[i].Status = "degraded"
+ state.PBSInstances[i].ConnectionHealth = "degraded"
+ } else {
+ 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"}
@@ -641,11 +695,15 @@ func applyDemoStorageScenario(state *models.StateSnapshot, now time.Time) {
for i := range state.PMGInstances {
if i == 0 {
state.PMGInstances[i].Name = "mail-gateway-eu"
+ state.PMGInstances[i].Status = "online"
+ state.PMGInstances[i].ConnectionHealth = "healthy"
} else {
+ // mail-gateway-us simulates a degraded edge gateway so the PMG page
+ // shows a non-healthy instance alongside the healthy primary.
state.PMGInstances[i].Name = "mail-gateway-us"
+ state.PMGInstances[i].Status = "degraded"
+ state.PMGInstances[i].ConnectionHealth = "degraded"
}
- 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)
}
}
diff --git a/internal/mock/demo_scenarios_test.go b/internal/mock/demo_scenarios_test.go
index 6b1955bc2a..9cd4bb4e6a 100644
--- a/internal/mock/demo_scenarios_test.go
+++ b/internal/mock/demo_scenarios_test.go
@@ -171,23 +171,23 @@ func TestFixtureGraphUpdateMetricsRestoresStableDemoInfrastructurePosture(t *tes
graph.UpdateMetrics(cfg, later)
- if !allHostsOnline(graph) {
- t.Fatal("expected demo host agents to restore online status after metric refresh")
+ if !hostsMatchCuratedPosture(graph) {
+ t.Fatal("expected demo host agents to restore curated posture (pve5 + prod-euw1-k8s-03 offline) after metric refresh")
}
- if !allDockerHostsOnline(graph) {
- t.Fatal("expected curated docker hosts to restore online status after metric refresh")
+ if !dockerHostsMatchCuratedPosture(graph) {
+ t.Fatal("expected curated docker hosts to restore posture (one offline) 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 !kubernetesNodesMatchCuratedPosture(graph) {
+ t.Fatal("expected curated kubernetes nodes to restore posture (prod-euw1-k8s-03 NotReady in offline cluster) after metric refresh")
}
- if !allPBSInstancesOnlineHealthy(graph) {
- t.Fatal("expected curated PBS posture to restore healthy online status after metric refresh")
+ if !pbsInstancesMatchCuratedPosture(graph) {
+ t.Fatal("expected curated PBS posture (dr-vault degraded, backup-vault online) to restore after metric refresh")
}
- if !allPMGInstancesOnlineHealthy(graph) {
- t.Fatal("expected curated PMG posture to restore healthy online status after metric refresh")
+ if !pmgInstancesMatchCuratedPosture(graph) {
+ t.Fatal("expected curated PMG posture (mail-gateway-us degraded, mail-gateway-eu online) to restore after metric refresh")
}
if !connectionHealthMatchesCuratedDemoState(graph) {
t.Fatal("expected connection-health map to match the final curated demo state after metric refresh")
@@ -337,9 +337,10 @@ func pmgInstanceExists(graph FixtureGraph, want string) bool {
return false
}
-func allHostsOnline(graph FixtureGraph) bool {
+func hostsMatchCuratedPosture(graph FixtureGraph) bool {
for _, host := range graph.State.Hosts {
- if strings.ToLower(strings.TrimSpace(host.Hostname)) == "pve5" {
+ hostname := strings.ToLower(strings.TrimSpace(host.Hostname))
+ if hostname == "pve5" || hostname == "prod-euw1-k8s-03" {
if host.Status != "offline" {
return false
}
@@ -352,9 +353,16 @@ func allHostsOnline(graph FixtureGraph) bool {
return true
}
-func allDockerHostsOnline(graph FixtureGraph) bool {
- for _, host := range graph.State.DockerHosts {
- if host.Status != "online" {
+func dockerHostsMatchCuratedPosture(graph FixtureGraph) bool {
+ const offlineDockerIndex = 2
+ for i, host := range graph.State.DockerHosts {
+ if i == offlineDockerIndex {
+ if host.Status != "offline" {
+ return false
+ }
+ continue
+ }
+ if host.Status != "online" && host.Status != "degraded" {
return false
}
}
@@ -370,9 +378,14 @@ func allKubernetesClustersOnline(graph FixtureGraph) bool {
return true
}
-func allKubernetesNodesReady(graph FixtureGraph) bool {
+func kubernetesNodesMatchCuratedPosture(graph FixtureGraph) bool {
for _, cluster := range graph.State.KubernetesClusters {
for _, node := range cluster.Nodes {
+ if node.Name == "prod-euw1-k8s-03" {
+ // At least one cluster reports this profile as NotReady to
+ // drive the demo Linux-host outage; others can be Ready.
+ continue
+ }
if !node.Ready || node.Unschedulable {
return false
}
@@ -381,8 +394,14 @@ func allKubernetesNodesReady(graph FixtureGraph) bool {
return true
}
-func allPBSInstancesOnlineHealthy(graph FixtureGraph) bool {
- for _, instance := range graph.State.PBSInstances {
+func pbsInstancesMatchCuratedPosture(graph FixtureGraph) bool {
+ for i, instance := range graph.State.PBSInstances {
+ if i == 1 {
+ if instance.Status != "degraded" || instance.ConnectionHealth != "degraded" {
+ return false
+ }
+ continue
+ }
if instance.Status != "online" || instance.ConnectionHealth != "healthy" {
return false
}
@@ -390,8 +409,14 @@ func allPBSInstancesOnlineHealthy(graph FixtureGraph) bool {
return true
}
-func allPMGInstancesOnlineHealthy(graph FixtureGraph) bool {
- for _, instance := range graph.State.PMGInstances {
+func pmgInstancesMatchCuratedPosture(graph FixtureGraph) bool {
+ for i, instance := range graph.State.PMGInstances {
+ if i == 1 {
+ if instance.Status != "degraded" || instance.ConnectionHealth != "degraded" {
+ return false
+ }
+ continue
+ }
if instance.Status != "online" || instance.ConnectionHealth != "healthy" {
return false
}
diff --git a/internal/mock/generator.go b/internal/mock/generator.go
index 2d3c65475c..7233a2038a 100644
--- a/internal/mock/generator.go
+++ b/internal/mock/generator.go
@@ -4467,8 +4467,9 @@ func generatePBSInstances() []models.PBSInstance {
},
}
- // Add a secondary PBS if we have enough nodes
- if rand.Float64() > 0.4 {
+ // Always seed a secondary PBS so the demo PBS page can render a multi-instance posture
+ // with one healthy and one degraded vault.
+ {
pbsInstances = append(pbsInstances, models.PBSInstance{
ID: "pbs-secondary",
Name: "pbs-secondary",
@@ -4727,7 +4728,9 @@ func generatePMGInstances() []models.PMGInstance {
instances := []models.PMGInstance{primary}
- if rand.Float64() > 0.65 {
+ // Always seed a secondary PMG so the demo PMG page can render a multi-instance posture
+ // with one healthy and one degraded gateway.
+ {
backupNow := now.Add(-6 * time.Hour)
secondaryStats := mailStats
secondaryStats.CountTotal *= 0.6