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.

test(pbs): cover malformed metrics through webhook recovery lifecycle

pulse-triage[bot]6ed8c05c6b22
diff --git a/internal/monitoring/monitor_pbs_health_authority_test.go b/internal/monitoring/monitor_pbs_health_authority_test.go
index 3ff3e99244..da9e26a717 100644
--- a/internal/monitoring/monitor_pbs_health_authority_test.go
+++ b/internal/monitoring/monitor_pbs_health_authority_test.go
@@ -28,6 +28,10 @@ const (
pbsHealthTestLowMemory
pbsHealthTestNullNodeStatus
pbsHealthTestIncompleteNodeStatus
+ pbsHealthTestNegativeCPU
+ pbsHealthTestZeroMemoryTotal
+ pbsHealthTestWrongMemoryType
+ pbsHealthTestZeroUsage
)
type pbsHealthTestServer struct {
@@ -68,6 +72,20 @@ func newPBSHealthTestServer(t *testing.T) *pbsHealthTestServer {
"data": map[string]any{"version": "3.4.2"},
})
case "/api2/json/nodes/localhost/status":
+ switch mode {
+ case pbsHealthTestNegativeCPU:
+ _, _ = w.Write([]byte(`{"data":{"cpu":-1,"memory":{"used":0,"total":1024}}}`))
+ return
+ case pbsHealthTestZeroMemoryTotal:
+ _, _ = w.Write([]byte(`{"data":{"cpu":0,"memory":{"used":0,"total":0}}}`))
+ return
+ case pbsHealthTestWrongMemoryType:
+ _, _ = w.Write([]byte(`{"data":{"cpu":0,"memory":{"used":"0","total":1024}}}`))
+ return
+ case pbsHealthTestZeroUsage:
+ _, _ = w.Write([]byte(`{"data":{"cpu":0,"memory":{"used":0,"total":1024}}}`))
+ return
+ }
if mode == pbsHealthTestIncompleteNodeStatus {
_, _ = w.Write([]byte(`{"data":{"cpu":0.15,"memory":{"total":1024}}}`))
return
diff --git a/internal/monitoring/monitor_pbs_webhook_test.go b/internal/monitoring/monitor_pbs_webhook_test.go
index 19ebe7c198..707fb5d72f 100644
--- a/internal/monitoring/monitor_pbs_webhook_test.go
+++ b/internal/monitoring/monitor_pbs_webhook_test.go
@@ -16,6 +16,21 @@ import (
// This is local integration proof, not installed-artifact or off-host delivery
// qualification. Both the synthetic PBS and receiver live in this test process.
func TestPBSPartialMetricsWebhookLifecycle(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ mode pbsHealthTestMode
+ }{
+ {"low usage", pbsHealthTestLowMemory},
+ {"measured zero", pbsHealthTestZeroUsage},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ testPBSPartialMetricsWebhookLifecycle(t, tc.mode)
+ })
+ }
+}
+
+func testPBSPartialMetricsWebhookLifecycle(t *testing.T, recoveryMode pbsHealthTestMode) {
+ t.Helper()
type payload struct {
Event string `json:"event"`
Alerts []alerts.Alert `json:"alerts"`
@@ -98,7 +113,8 @@ func TestPBSPartialMetricsWebhookLifecycle(t *testing.T) {
}
incident := firing.Alerts[0]
waitSent(1)
- for _, mode := range []pbsHealthTestMode{pbsHealthTestNodeDenied, pbsHealthTestNodeGatewayFailure, pbsHealthTestNullNodeStatus, pbsHealthTestIncompleteNodeStatus} {
+ for _, mode := range []pbsHealthTestMode{pbsHealthTestNodeDenied, pbsHealthTestNodeGatewayFailure, pbsHealthTestNullNodeStatus, pbsHealthTestIncompleteNodeStatus,
+ pbsHealthTestNegativeCPU, pbsHealthTestZeroMemoryTotal, pbsHealthTestWrongMemoryType} {
fixture.setMode(mode)
for range 5 {
poll()
@@ -120,7 +136,8 @@ func TestPBSPartialMetricsWebhookLifecycle(t *testing.T) {
case <-time.After(150 * time.Millisecond):
}
}
- fixture.setMode(pbsHealthTestLowMemory)
+ // A measured zero is valid recovery, unlike missing or malformed numbers.
+ fixture.setMode(recoveryMode)
for range 5 {
poll()
}