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
test: add soak test with runtime instrumentation (Phase 2 Task 9d)
rcourtman14d06a1654c7
diff --git a/.gitignore b/.gitignoreindex deed813d58..abf9781ffe 100644--- a/.gitignore+++ b/.gitignore@@ -80,7 +80,8 @@ RELEASE_CHECKLIST.mdDOCKER_PUSH_INSTRUCTIONS.md# Testing and temporary files-testing-tools/+testing-tools/*+!testing-tools/run_adaptive_soak.shmanual-test*.mdverify-*.mdtest-*.mddiff --git a/internal/monitoring/harness_integration.go b/internal/monitoring/harness_integration.goindex 12ccfc0a6f..932cd4ae23 100644--- a/internal/monitoring/harness_integration.go+++ b/internal/monitoring/harness_integration.go@@ -72,16 +72,22 @@ type ResourceStats struct {GoroutinesEnd intHeapAllocStart uint64HeapAllocEnd uint64+ StackInuseStart uint64+ StackInuseEnd uint64+ GCCountStart uint32+ GCCountEnd uint32}// HarnessReport is returned after a harness run completes.type HarnessReport struct {- PerInstanceStats map[string]InstanceStats- QueueStats QueueStats- StalenessStats StalenessStats- ResourceStats ResourceStats- Health SchedulerHealthResponse- MaxStaleness time.Duration+ Scenario HarnessScenario+ PerInstanceStats map[string]InstanceStats+ QueueStats QueueStats+ StalenessStats StalenessStats+ ResourceStats ResourceStats+ Health SchedulerHealthResponse+ MaxStaleness time.Duration+ RuntimeSamples []runtimeSnapshot}// Harness orchestrates the integration run.@@ -95,6 +101,9 @@ type Harness struct {queueSum intqueueSamples intmaxStaleness time.Duration+ sampleEvery time.Duration+ runtimeSamples []runtimeSnapshot+ lastRuntimeSample time.Time}// NewHarness constructs a harness configured for the provided scenario.@@ -154,12 +163,16 @@ func NewHarness(scenario HarnessScenario) *Harness {scenario: scenario,dataPath: tempDir,maxStaleness: cfg.AdaptivePollingMaxInterval,+ sampleEvery: 15 * time.Second,}}// Run executes the scenario and returns a report of collected statistics.func (h *Harness) Run(ctx context.Context) HarnessReport {+ h.runtimeSamples = nilruntimeStart := sampleRuntime()+ h.runtimeSamples = append(h.runtimeSamples, runtimeStart)+ h.lastRuntimeSample = runtimeStart.TimestamprunCtx, cancel := context.WithCancel(ctx)h.cancel = cancel@@ -185,6 +198,9 @@ loop:case <-ticker.C:now := time.Now()h.schedule(now)+ if h.sampleEvery > 0 && time.Since(h.lastRuntimeSample) >= h.sampleEvery {+ h.recordRuntimeSample()+ }if now.After(runEnd) {cancel()}@@ -203,12 +219,20 @@ loop:finalQueueDepth := h.Monitor.taskQueue.Size()health := h.Monitor.SchedulerHealth()runtimeEnd := sampleRuntime()+ h.runtimeSamples = append(h.runtimeSamples, runtimeEnd)staleness := computeStalenessStats(h.Monitor)h.Monitor.Stop()+ runtimeSamplesCopy := append([]runtimeSnapshot(nil), h.runtimeSamples...)h.cleanup()+ if len(runtimeSamplesCopy) == 0 {+ runtimeSamplesCopy = append(runtimeSamplesCopy, runtimeStart, runtimeEnd)+ }+ startSample := runtimeSamplesCopy[0]+ endSample := runtimeSamplesCopy[len(runtimeSamplesCopy)-1]report := HarnessReport{+ Scenario: h.scenario,PerInstanceStats: instanceStats,QueueStats: QueueStats{MaxDepth: h.queueMax,@@ -218,16 +242,21 @@ loop:},StalenessStats: staleness,ResourceStats: ResourceStats{- GoroutinesStart: runtimeStart.Goroutines,- GoroutinesEnd: runtimeEnd.Goroutines,- HeapAllocStart: runtimeStart.HeapAlloc,- HeapAllocEnd: runtimeEnd.HeapAlloc,+ GoroutinesStart: startSample.Goroutines,+ GoroutinesEnd: endSample.Goroutines,+ HeapAllocStart: startSample.HeapAlloc,+ HeapAllocEnd: endSample.HeapAlloc,+ StackInuseStart: startSample.StackInuse,+ StackInuseEnd: endSample.StackInuse,+ GCCountStart: startSample.NumGC,+ GCCountEnd: endSample.NumGC,},- Health: health,- MaxStaleness: h.maxStaleness,+ Health: health,+ MaxStaleness: h.maxStaleness,+ RuntimeSamples: runtimeSamplesCopy,}- return report+ return report}func (h *Harness) schedule(now time.Time) {@@ -265,11 +294,19 @@ func (h *Harness) recordQueueDepth(depth int) {}}+func (h *Harness) recordRuntimeSample() {+ snap := sampleRuntime()+ h.runtimeSamples = append(h.runtimeSamples, snap)+ h.lastRuntimeSample = snap.Timestamp+}+func (h *Harness) cleanup() {if h.cancel != nil {h.cancel()h.cancel = nil}+ h.runtimeSamples = nil+ h.lastRuntimeSample = time.Time{}if h.dataPath != "" {_ = os.RemoveAll(h.dataPath)h.dataPath = ""@@ -277,16 +314,22 @@ func (h *Harness) cleanup() {}type runtimeSnapshot struct {+ Timestamp time.TimeGoroutines intHeapAlloc uint64+ StackInuse uint64+ NumGC uint32}func sampleRuntime() runtimeSnapshot {var ms runtime.MemStatsruntime.ReadMemStats(&ms)return runtimeSnapshot{+ Timestamp: time.Now(),Goroutines: runtime.NumGoroutine(),HeapAlloc: ms.HeapAlloc,+ StackInuse: ms.StackInuse,+ NumGC: ms.NumGC,}}diff --git a/internal/monitoring/integration_integration_test.go b/internal/monitoring/integration_integration_test.goindex 1d28677695..b6eb06904a 100644--- a/internal/monitoring/integration_integration_test.go+++ b/internal/monitoring/integration_integration_test.go@@ -4,12 +4,18 @@ package monitoringimport ("context"+ "flag""fmt""math"+ "os"+ "strconv"+ "strings""testing""time")+var soakFlag = flag.Bool("soak", false, "run adaptive polling soak test")+func TestAdaptiveSchedulerIntegration(t *testing.T) {scenario := HarnessScenario{Duration: 45 * time.Second,@@ -98,6 +104,20 @@ func TestAdaptiveSchedulerIntegration(t *testing.T) {t.Fatalf("health queue depth %d exceeds observed max %d", report.Health.Queue.Depth, report.QueueStats.MaxDepth)}+ if len(report.RuntimeSamples) >= 2 {+ startSample := report.RuntimeSamples[0]+ finalSample := report.RuntimeSamples[len(report.RuntimeSamples)-1]+ if startSample.HeapAlloc > 0 {+ growthRatio := float64(finalSample.HeapAlloc) / float64(startSample.HeapAlloc)+ if growthRatio > 1.25 && finalSample.HeapAlloc > startSample.HeapAlloc+5*1024*1024 {+ t.Fatalf("heap allocation grew too much: start=%d final=%d ratio=%.2f", startSample.HeapAlloc, finalSample.HeapAlloc, growthRatio)+ }+ }+ if finalSample.Goroutines > startSample.Goroutines+20 {+ t.Fatalf("goroutine count grew too much: start=%d final=%d", startSample.Goroutines, finalSample.Goroutines)+ }+ }+maxStaleness := report.MaxStalenessif maxStaleness <= 0 {t.Fatalf("invalid max staleness value: %v", maxStaleness)@@ -143,9 +163,12 @@ func TestAdaptiveSchedulerIntegration(t *testing.T) {t.Fatalf("expected transient instance to recover with successes, got 0")}- dlqKeys := map[string]struct{}{}- for _, task := range report.Health.DeadLetter.Tasks {- dlqKeys[instanceKey(task.Type, task.Instance)] = struct{}{}+ dlqKeys := map[string]struct{}{}+ for _, task := range report.Health.DeadLetter.Tasks {+ dlqKeys[instanceKey(task.Type, task.Instance)] = struct{}{}+ }+ if len(report.Health.Breakers) > len(dlqKeys) {+ t.Fatalf("unexpected number of circuit breaker entries: got %d want <= %d", len(report.Health.Breakers), len(dlqKeys))}for _, breaker := range report.Health.Breakers {key := instanceKey(breaker.Type, breaker.Instance)@@ -188,3 +211,131 @@ func TestAdaptiveSchedulerIntegration(t *testing.T) {t.Fatal("expected adaptive polling to be enabled in scheduler health response")}}++func TestAdaptiveSchedulerSoak(t *testing.T) {+ minutesEnv := os.Getenv("HARNESS_SOAK_MINUTES")+ if !*soakFlag && minutesEnv == "" {+ t.Skip("skipping soak test (enable with -soak or HARNESS_SOAK_MINUTES)")+ }++ minutes := 15+ if minutesEnv != "" {+ if parsed, err := strconv.Atoi(minutesEnv); err == nil && parsed > 0 {+ minutes = parsed+ }+ }++ duration := time.Duration(minutes) * time.Minute+ warmup := 2 * time.Minute+ scenario := HarnessScenario{Duration: duration, WarmupDuration: warmup}++ for i := 0; i < 60; i++ {+ scenario.Instances = append(scenario.Instances, InstanceConfig{+ Type: "pve",+ Name: fmt.Sprintf("soak-healthy-%02d", i),+ SuccessRate: 0.98,+ BaseLatency: 200 * time.Millisecond,+ })+ }++ for i := 0; i < 15; i++ {+ scenario.Instances = append(scenario.Instances, InstanceConfig{+ Type: "pve",+ Name: fmt.Sprintf("soak-transient-%02d", i),+ SuccessRate: 0.85,+ FailureSeq: []FailureType{+ FailureTransient,+ FailureTransient,+ FailureNone,+ FailureTransient,+ FailureNone,+ },+ BaseLatency: 220 * time.Millisecond,+ })+ }++ permanentCount := 5+ for i := 0; i < permanentCount; i++ {+ scenario.Instances = append(scenario.Instances, InstanceConfig{+ Type: "pve",+ Name: fmt.Sprintf("soak-permanent-%02d", i),+ SuccessRate: 0,+ FailureSeq: []FailureType{+ FailureTransient,+ FailureTransient,+ FailurePermanent,+ },+ BaseLatency: 250 * time.Millisecond,+ })+ }++ harness := NewHarness(scenario)+ ctx, cancel := context.WithTimeout(context.Background(), duration+warmup+5*time.Minute)+ defer cancel()++ report := harness.Run(ctx)++ if len(report.RuntimeSamples) < 2 {+ t.Fatalf("expected runtime samples, got %d", len(report.RuntimeSamples))+ }++ startSample := report.RuntimeSamples[0]+ warmupEnd := startSample.Timestamp.Add(report.Scenario.WarmupDuration)+ baseline := startSample+ for _, sample := range report.RuntimeSamples {+ if !sample.Timestamp.Before(warmupEnd) {+ baseline = sample+ break+ }+ }+ finalSample := report.RuntimeSamples[len(report.RuntimeSamples)-1]++ if baseline.HeapAlloc > 0 {+ allowed := float64(baseline.HeapAlloc)*1.10 + 10*1024*1024+ if float64(finalSample.HeapAlloc) > allowed {+ t.Fatalf("heap allocation grew too much: baseline=%d final=%d", baseline.HeapAlloc, finalSample.HeapAlloc)+ }+ }+ if finalSample.Goroutines > baseline.Goroutines+20 {+ t.Fatalf("goroutine count grew too much: baseline=%d final=%d", baseline.Goroutines, finalSample.Goroutines)+ }++ if report.QueueStats.FinalDepth > len(scenario.Instances) {+ t.Fatalf("final queue depth %d exceeds instance count %d", report.QueueStats.FinalDepth, len(scenario.Instances))+ }++ healthyThreshold := 45 * time.Second+ for key, stats := range report.PerInstanceStats {+ if stats.Successes == 0 || stats.PermanentFailures > 0 {+ continue+ }+ if stats.LastSuccessAt.IsZero() {+ t.Fatalf("missing last success timestamp for %s", key)+ }+ age := time.Since(stats.LastSuccessAt)+ if age > healthyThreshold {+ t.Fatalf("instance %s staleness age %v exceeds threshold %v", key, age, healthyThreshold)+ }+ }++ if len(report.Health.DeadLetter.Tasks) != permanentCount {+ t.Fatalf("expected %d dead-letter tasks, got %d", permanentCount, len(report.Health.DeadLetter.Tasks))+ }++ for name, stats := range report.PerInstanceStats {+ if strings.Contains(name, "transient") {+ if stats.TransientFailures == 0 {+ t.Fatalf("expected transient failures for %s", name)+ }+ if stats.Successes == 0 {+ t.Fatalf("expected recoveries for %s", name)+ }+ }+ }++ if !report.Health.Enabled {+ t.Fatal("expected adaptive polling to be enabled during soak run")+ }++ t.Logf("soak run complete: instances=%d duration=%v samples=%d heap(start=%d end=%d) goroutines(start=%d end=%d)", len(scenario.Instances), duration, len(report.RuntimeSamples), baseline.HeapAlloc, finalSample.HeapAlloc, baseline.Goroutines, finalSample.Goroutines)+}diff --git a/testing-tools/run_adaptive_soak.sh b/testing-tools/run_adaptive_soak.shnew file mode 100755index 0000000000..af9af8a22f--- /dev/null+++ b/testing-tools/run_adaptive_soak.sh@@ -0,0 +1,29 @@+#!/usr/bin/env bash+set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"++if [[ ${1-} ]]; then+ export HARNESS_SOAK_MINUTES="$1"+elif [[ -z "${HARNESS_SOAK_MINUTES-}" ]]; then+ export HARNESS_SOAK_MINUTES=15+fi++SOAK_MINUTES="${HARNESS_SOAK_MINUTES}"+if ! [[ "$SOAK_MINUTES" =~ ^[0-9]+$ ]]; then+ echo "HARNESS_SOAK_MINUTES must be an integer number of minutes" >&2+ exit 1+fi++TIMEOUT_MINUTES=$(( SOAK_MINUTES + 5 ))+LOG_DIR="${REPO_ROOT}/tmp"+mkdir -p "${LOG_DIR}"+LOG_FILE="${LOG_DIR}/adaptive_soak_$(date +%Y%m%d_%H%M%S).log"++echo "Running adaptive polling soak test for ${SOAK_MINUTES} minute(s)..."+set -o pipefail+go test -tags=integration ./internal/monitoring -run TestAdaptiveSchedulerSoak -soak -timeout "${TIMEOUT_MINUTES}m" 2>&1 | tee "${LOG_FILE}"+STATUS=${PIPESTATUS[0]}+echo "Soak test log saved to ${LOG_FILE}"+exit ${STATUS}