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 RC backend test contracts

rcourtman51b494b137f8
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index 7ee0652c67..04c4f42bba 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -204,6 +204,13 @@ The alerts schedule surface now also routes quiet-hour suppress-category card
styling through `frontend-modern/src/utils/alertSchedulePresentation.ts`
instead of leaving that selectable-card presentation inline in
`frontend-modern/src/pages/Alerts.tsx`.
+That same schedule/runtime boundary also owns quiet-hours clock semantics.
+Backend quiet hours are minute-granular user input, so runtime evaluation must
+treat the configured start minute and end minute as inclusive and therefore
+keep schedules such as `00:00` to `23:59` active through the full final
+minute instead of expiring at `23:59:00`. Alert quiet-hours proofs should
+control time through the alert manager clock hook instead of depending on wall
+clock execution at whatever second the test runner happens to hit.
That schedule surface now also follows the same shell/runtime split as the
other feature tabs: `frontend-modern/src/features/alerts/tabs/ScheduleTab.tsx`
stays the render shell, while
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 548711f2ac..a6172cb582 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -196,6 +196,12 @@ window instead of stitching a second live tail onto the end of seeded
sparklines. Monitoring must not let any mock-owned resource receive a
duplicate generic unified-resource writer that appends a divergent recent tail
after the canonical mock sampler has already seeded and extended that series.
+That same sampler-owned boundary also owns seeding cost. Historical mock
+seeding runs synchronously on monitor startup and in package proofs, so it
+must stay deterministic and bounded by fixture size instead of carrying
+per-resource pacing sleeps or other wall-clock throttles that can exhaust the
+package-level `go test -race -timeout 10m` budget on hosted runners before
+canonical mock history has even finished initializing.
The seed path must therefore include the canonical terminal `now` sample on
its tiered timeline and anchor seeded series to the canonical metric model at
that timestamp instead of to mutable state fields, so historical charts match
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index b920054a4f..8e728cf9f5 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -1190,6 +1190,11 @@ side: `frontend-modern/src/pages/Dashboard.tsx`,
explicit direct dashboard/storage proof routing instead of borrowing release-
control coverage only from the broader storage page, component, and model
surfaces.
+That same dashboard storage surface must also render its capacity meter through
+the shared `frontend-modern/src/components/shared/ProgressBar.tsx` primitive
+and attribute-driven fill geometry instead of owner-local inline width styles,
+so the live dashboard remains CSP-safe while still reporting the canonical
+storage summary.
That route shell now also composes the recent-alerts widget directly from the
alert-owned `frontend-modern/src/components/Alerts/RecentAlertsPanel.tsx`
surface instead of via a dashboard-panels-local alert implementation, so the
diff --git a/frontend-modern/src/components/Storage/DashboardStoragePanel.tsx b/frontend-modern/src/components/Storage/DashboardStoragePanel.tsx
index 06fa6d9626..05e98dd222 100644
--- a/frontend-modern/src/components/Storage/DashboardStoragePanel.tsx
+++ b/frontend-modern/src/components/Storage/DashboardStoragePanel.tsx
@@ -1,4 +1,5 @@
import { Match, Switch } from 'solid-js';
+import { ProgressBar } from '@/components/shared/ProgressBar';
import { Card } from '@/components/shared/Card';
import { buildStoragePath } from '@/routing/resourceLinks';
import {
@@ -57,12 +58,11 @@ export function DashboardStoragePanel(props: DashboardStoragePanelProps) {
</span>
</div>
- <div class="h-2 overflow-hidden rounded bg-surface-alt">
- <div
- class={`h-full rounded ${getDashboardStorageCapacityBarClass(capacityPercent())}`}
- style={{ width: `${capacityPercent()}%` }}
- />
- </div>
+ <ProgressBar
+ value={capacityPercent()}
+ class="h-2"
+ fillClass={getDashboardStorageCapacityBarClass(capacityPercent())}
+ />
<div class="flex flex-wrap items-center gap-3 text-xs">
{getDashboardStorageIssueBadges(props.storage).map((badge) => (
diff --git a/frontend-modern/src/components/Storage/__tests__/DashboardStoragePanel.test.tsx b/frontend-modern/src/components/Storage/__tests__/DashboardStoragePanel.test.tsx
index f1267017f6..d8418a4a42 100644
--- a/frontend-modern/src/components/Storage/__tests__/DashboardStoragePanel.test.tsx
+++ b/frontend-modern/src/components/Storage/__tests__/DashboardStoragePanel.test.tsx
@@ -46,4 +46,22 @@ describe('DashboardStoragePanel', () => {
expect(screen.getByText('1 critical')).toBeInTheDocument();
expect(screen.getByText('24h: +10.0%')).toBeInTheDocument();
});
+
+ it('renders the capacity bar through the shared progress primitive without inline styles', () => {
+ const storage: DashboardOverview['storage'] = {
+ total: 1,
+ totalCapacity: 4000,
+ totalUsed: 1540,
+ warningCount: 0,
+ criticalCount: 0,
+ };
+
+ const result = render(() => (
+ <DashboardStoragePanel storage={storage} storageTrend={null} loading={false} />
+ ));
+
+ const fill = result.container.querySelector('[data-progress-fill="true"]');
+ expect(fill).toHaveAttribute('width', '38.5');
+ expect(result.container.querySelector('[style]')).toBeNull();
+ });
});
diff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.go
index e8196ab199..368ec4d66a 100644
--- a/internal/alerts/alerts.go
+++ b/internal/alerts/alerts.go
@@ -592,6 +592,7 @@ type Manager struct {
// Cached timezone for quiet hours
quietHoursLoc *time.Location
+ now func() time.Time
stopOnce sync.Once
}
@@ -657,6 +658,7 @@ func NewManagerWithDataDir(dataDir string) *Manager {
hostAgentHostnames: make(map[string]struct{}),
nodeDisplayNames: make(map[string]string),
instanceNodeDisplayNames: make(map[string]string),
+ now: time.Now,
config: AlertConfig{
Enabled: true,
ActivationState: ActivationPending,
@@ -2393,7 +2395,11 @@ func (m *Manager) isInQuietHours() bool {
m.quietHoursLoc = loc
}
- now := time.Now().In(loc)
+ nowFn := m.now
+ if nowFn == nil {
+ nowFn = time.Now
+ }
+ now := nowFn().In(loc).Truncate(time.Minute)
dayName := strings.ToLower(now.Format("Monday"))
// Check if today is enabled for quiet hours
@@ -2418,15 +2424,17 @@ func (m *Manager) isInQuietHours() bool {
startTime = time.Date(now.Year(), now.Month(), now.Day(), startTime.Hour(), startTime.Minute(), 0, 0, loc)
endTime = time.Date(now.Year(), now.Month(), now.Day(), endTime.Hour(), endTime.Minute(), 0, 0, loc)
+ // Quiet hours are configured with minute precision, so treat the start and
+ // end minute as inclusive for user-facing schedules such as 00:00-23:59.
+ endExclusive := endTime.Add(time.Minute)
+
// Handle overnight quiet hours (e.g., 22:00 to 08:00)
if endTime.Before(startTime) {
- // If we're past the start time or before the end time
- if now.After(startTime) || now.Before(endTime) {
+ if !now.Before(startTime) || now.Before(endExclusive) {
return true
}
} else {
- // Normal case (e.g., 08:00 to 17:00)
- if now.After(startTime) && now.Before(endTime) {
+ if !now.Before(startTime) && now.Before(endExclusive) {
return true
}
}
diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.go
index df9772f240..8e2d99e941 100644
--- a/internal/alerts/alerts_test.go
+++ b/internal/alerts/alerts_test.go
@@ -279,6 +279,31 @@ func TestQuietHoursCategoryForResourceIncidentUsesIncidentCategoryMetadata(t *te
}
}
+func TestShouldSuppressNotificationTreatsQuietHoursEndMinuteAsInclusive(t *testing.T) {
+ m := fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 23, 59, 31, 0, time.UTC),
+ QuietHours{
+ Enabled: true,
+ Start: "00:00",
+ End: "23:59",
+ Timezone: "UTC",
+ Days: map[string]bool{
+ "monday": true, "tuesday": true, "wednesday": true,
+ "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ },
+ },
+ )
+
+ suppressed, reason := m.shouldSuppressNotification(&Alert{
+ ID: "warn",
+ Type: "cpu",
+ Level: AlertLevelWarning,
+ })
+ if !suppressed || reason != "non-critical" {
+ t.Fatalf("expected warning alert to stay inside quiet hours through 23:59, got suppressed=%t reason=%q", suppressed, reason)
+ }
+}
+
func TestCheckGuestSkipsAlertsWhenMetricDisabled(t *testing.T) {
m := newTestManager(t)
diff --git a/internal/alerts/quiet_hours_test.go b/internal/alerts/quiet_hours_test.go
index 3416dac8cb..5e54a4dc9b 100644
--- a/internal/alerts/quiet_hours_test.go
+++ b/internal/alerts/quiet_hours_test.go
@@ -5,27 +5,35 @@ import (
"time"
)
-func newManagerWithQuietHoursSuppress(s QuietHoursSuppression) *Manager {
+func fixedQuietHoursTestManager(now time.Time, quietHours QuietHours) *Manager {
m := NewManager()
- m.config.Schedule.QuietHours = QuietHours{
- Enabled: true,
- Start: "00:00",
- End: "23:59",
- Timezone: "UTC",
- Days: map[string]bool{
- "monday": true,
- "tuesday": true,
- "wednesday": true,
- "thursday": true,
- "friday": true,
- "saturday": true,
- "sunday": true,
- },
- Suppress: s,
- }
+ m.now = func() time.Time { return now }
+ m.config.Schedule.QuietHours = quietHours
return m
}
+func newManagerWithQuietHoursSuppress(s QuietHoursSuppression) *Manager {
+ return fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 12, 0, 0, 0, time.UTC),
+ QuietHours{
+ Enabled: true,
+ Start: "00:00",
+ End: "23:59",
+ Timezone: "UTC",
+ Days: map[string]bool{
+ "monday": true,
+ "tuesday": true,
+ "wednesday": true,
+ "thursday": true,
+ "friday": true,
+ "saturday": true,
+ "sunday": true,
+ },
+ Suppress: s,
+ },
+ )
+}
+
func TestShouldSuppressNotificationQuietHours(t *testing.T) {
t.Run("non-critical alerts suppressed by default", func(t *testing.T) {
m := newManagerWithQuietHoursSuppress(QuietHoursSuppression{})
@@ -77,15 +85,11 @@ func TestIsInQuietHours(t *testing.T) {
// t.Parallel()
t.Run("disabled returns false", func(t *testing.T) {
- // t.Parallel()
- m := NewManager()
- m.mu.Lock()
- m.config.Schedule.QuietHours.Enabled = false
- m.mu.Unlock()
-
- m.mu.RLock()
+ m := fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 12, 0, 0, 0, time.UTC),
+ QuietHours{Enabled: false},
+ )
result := m.isInQuietHours()
- m.mu.RUnlock()
if result {
t.Errorf("isInQuietHours() = true, want false when disabled")
@@ -93,51 +97,37 @@ func TestIsInQuietHours(t *testing.T) {
})
t.Run("invalid timezone falls back to local", func(t *testing.T) {
- // t.Parallel()
- m := NewManager()
- m.mu.Lock()
- m.config.Schedule.QuietHours = QuietHours{
- Enabled: true,
- Start: "00:00",
- End: "23:59",
- Timezone: "Invalid/Timezone",
- Days: map[string]bool{
- "monday": true, "tuesday": true, "wednesday": true,
- "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ m := fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 12, 0, 0, 0, time.Local),
+ QuietHours{
+ Enabled: true,
+ Start: "00:00",
+ End: "23:59",
+ Timezone: "Invalid/Timezone",
+ Days: map[string]bool{
+ "monday": true, "tuesday": true, "wednesday": true,
+ "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ },
},
- }
- m.mu.Unlock()
+ )
- // Should not panic, should fall back to local time
- m.mu.RLock()
result := m.isInQuietHours()
- m.mu.RUnlock()
-
- // With all days enabled and 00:00-23:59, it should be true
if !result {
t.Errorf("isInQuietHours() = false, want true (invalid timezone should fall back to local)")
}
})
t.Run("day not enabled returns false", func(t *testing.T) {
- // t.Parallel()
- m := NewManager()
- now := time.Now()
+ now := time.Date(2026, time.April, 13, 12, 0, 0, 0, time.UTC)
currentDay := now.Format("Monday")
-
- m.mu.Lock()
- m.config.Schedule.QuietHours = QuietHours{
+ m := fixedQuietHoursTestManager(now, QuietHours{
Enabled: true,
Start: "00:00",
End: "23:59",
Timezone: "UTC",
Days: map[string]bool{}, // No days enabled
- }
- m.mu.Unlock()
-
- m.mu.RLock()
+ })
result := m.isInQuietHours()
- m.mu.RUnlock()
if result {
t.Errorf("isInQuietHours() = true, want false (day %s not enabled)", currentDay)
@@ -145,25 +135,20 @@ func TestIsInQuietHours(t *testing.T) {
})
t.Run("invalid start time returns false", func(t *testing.T) {
- // t.Parallel()
- m := NewManager()
-
- m.mu.Lock()
- m.config.Schedule.QuietHours = QuietHours{
- Enabled: true,
- Start: "invalid",
- End: "23:59",
- Timezone: "UTC",
- Days: map[string]bool{
- "monday": true, "tuesday": true, "wednesday": true,
- "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ m := fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 12, 0, 0, 0, time.UTC),
+ QuietHours{
+ Enabled: true,
+ Start: "invalid",
+ End: "23:59",
+ Timezone: "UTC",
+ Days: map[string]bool{
+ "monday": true, "tuesday": true, "wednesday": true,
+ "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ },
},
- }
- m.mu.Unlock()
-
- m.mu.RLock()
+ )
result := m.isInQuietHours()
- m.mu.RUnlock()
if result {
t.Errorf("isInQuietHours() = true, want false (invalid start time)")
@@ -171,25 +156,20 @@ func TestIsInQuietHours(t *testing.T) {
})
t.Run("invalid end time returns false", func(t *testing.T) {
- // t.Parallel()
- m := NewManager()
-
- m.mu.Lock()
- m.config.Schedule.QuietHours = QuietHours{
- Enabled: true,
- Start: "00:00",
- End: "invalid",
- Timezone: "UTC",
- Days: map[string]bool{
- "monday": true, "tuesday": true, "wednesday": true,
- "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ m := fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 12, 0, 0, 0, time.UTC),
+ QuietHours{
+ Enabled: true,
+ Start: "00:00",
+ End: "invalid",
+ Timezone: "UTC",
+ Days: map[string]bool{
+ "monday": true, "tuesday": true, "wednesday": true,
+ "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ },
},
- }
- m.mu.Unlock()
-
- m.mu.RLock()
+ )
result := m.isInQuietHours()
- m.mu.RUnlock()
if result {
t.Errorf("isInQuietHours() = true, want false (invalid end time)")
@@ -197,79 +177,79 @@ func TestIsInQuietHours(t *testing.T) {
})
t.Run("overnight quiet hours spanning midnight", func(t *testing.T) {
- // t.Parallel()
- m := NewManager()
-
- // Set up overnight quiet hours (22:00 to 06:00)
- m.mu.Lock()
- m.config.Schedule.QuietHours = QuietHours{
- Enabled: true,
- Start: "22:00",
- End: "06:00", // End before start = overnight
- Timezone: "UTC",
- Days: map[string]bool{
- "monday": true, "tuesday": true, "wednesday": true,
- "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ m := fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 23, 30, 0, 0, time.UTC),
+ QuietHours{
+ Enabled: true,
+ Start: "22:00",
+ End: "06:00", // End before start = overnight
+ Timezone: "UTC",
+ Days: map[string]bool{
+ "monday": true, "tuesday": true, "wednesday": true,
+ "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ },
},
+ )
+ if !m.isInQuietHours() {
+ t.Errorf("isInQuietHours() = false, want true for overnight quiet hours")
}
- m.mu.Unlock()
-
- // This tests the overnight branch - exact result depends on current time
- // but should not panic
- m.mu.RLock()
- _ = m.isInQuietHours()
- m.mu.RUnlock()
})
t.Run("normal daytime quiet hours", func(t *testing.T) {
- // t.Parallel()
- m := NewManager()
-
- // Set up daytime quiet hours (09:00 to 17:00)
- m.mu.Lock()
- m.config.Schedule.QuietHours = QuietHours{
- Enabled: true,
- Start: "09:00",
- End: "17:00",
- Timezone: "UTC",
- Days: map[string]bool{
- "monday": true, "tuesday": true, "wednesday": true,
- "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ m := fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 10, 0, 0, 0, time.UTC),
+ QuietHours{
+ Enabled: true,
+ Start: "09:00",
+ End: "17:00",
+ Timezone: "UTC",
+ Days: map[string]bool{
+ "monday": true, "tuesday": true, "wednesday": true,
+ "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ },
},
+ )
+ if !m.isInQuietHours() {
+ t.Errorf("isInQuietHours() = false, want true for daytime quiet hours")
}
- m.mu.Unlock()
-
- // Should not panic, result depends on current time
- m.mu.RLock()
- _ = m.isInQuietHours()
- m.mu.RUnlock()
})
t.Run("outside quiet hours window", func(t *testing.T) {
- // t.Parallel()
- m := NewManager()
-
- // Use a time window that's definitely not now (narrow window in far past/future time)
- // This creates a window from 03:00-03:01 which is unlikely to match current time
- m.mu.Lock()
- m.config.Schedule.QuietHours = QuietHours{
- Enabled: true,
- Start: "03:00",
- End: "03:01", // 1 minute window
- Timezone: "UTC",
- Days: map[string]bool{
- "monday": true, "tuesday": true, "wednesday": true,
- "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ m := fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 4, 0, 0, 0, time.UTC),
+ QuietHours{
+ Enabled: true,
+ Start: "03:00",
+ End: "03:01",
+ Timezone: "UTC",
+ Days: map[string]bool{
+ "monday": true, "tuesday": true, "wednesday": true,
+ "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ },
},
- }
- m.mu.Unlock()
-
- m.mu.RLock()
+ )
result := m.isInQuietHours()
- m.mu.RUnlock()
+ if result {
+ t.Errorf("isInQuietHours() = true, want false outside the configured window")
+ }
+ })
- // Very narrow window, likely false but depends on exact test execution time
- // Main purpose is to exercise the "outside window" return false path
- _ = result
+ t.Run("end minute remains inclusive", func(t *testing.T) {
+ m := fixedQuietHoursTestManager(
+ time.Date(2026, time.April, 12, 23, 59, 31, 0, time.UTC),
+ QuietHours{
+ Enabled: true,
+ Start: "00:00",
+ End: "23:59",
+ Timezone: "UTC",
+ Days: map[string]bool{
+ "monday": true, "tuesday": true, "wednesday": true,
+ "thursday": true, "friday": true, "saturday": true, "sunday": true,
+ },
+ },
+ )
+ if !m.isInQuietHours() {
+ t.Errorf("isInQuietHours() = false, want true through the configured end minute")
+ }
})
}
diff --git a/internal/api/main_test.go b/internal/api/main_test.go
index 8e71cb2e56..caea54ef56 100644
--- a/internal/api/main_test.go
+++ b/internal/api/main_test.go
@@ -5,6 +5,8 @@ import (
"strconv"
"testing"
+ "github.com/rs/zerolog"
+ "github.com/rs/zerolog/log"
"golang.org/x/crypto/bcrypt"
)
@@ -12,5 +14,6 @@ func TestMain(m *testing.M) {
_ = os.Setenv("PULSE_TEST_BCRYPT_COST", strconv.Itoa(bcrypt.MinCost))
_ = os.Setenv("PULSE_UPDATE_SERVER", "http://127.0.0.1:1")
allowLoopbackSSOFetch = true
+ log.Logger = zerolog.Nop()
os.Exit(m.Run())
}
diff --git a/internal/api/slo_bench_test.go b/internal/api/slo_bench_test.go
index 66837f66b9..ba6053c681 100644
--- a/internal/api/slo_bench_test.go
+++ b/internal/api/slo_bench_test.go
@@ -17,8 +17,6 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/models"
"github.com/rcourtman/pulse-go-rewrite/internal/monitoring"
"github.com/rcourtman/pulse-go-rewrite/pkg/metrics"
- "github.com/rs/zerolog"
- "github.com/rs/zerolog/log"
)
const (
@@ -47,12 +45,11 @@ const (
sloWorkloadsSummaryChartsGitHubActionsP95 = sloWorkloadChartsGitHubActionsP95
)
-// suppressTestLogs disables zerolog for the duration of a test.
+// suppressTestLogs is kept as a call-site marker for noisy integration-style
+// proofs. TestMain installs a package-wide nop logger so -race does not trip
+// over concurrent mutations of the global zerolog logger.
func suppressTestLogs(t *testing.T) {
t.Helper()
- orig := log.Logger
- log.Logger = zerolog.Nop()
- t.Cleanup(func() { log.Logger = orig })
}
// setTestUnexportedField sets an unexported field on a struct via reflection.
diff --git a/internal/monitoring/mock_metrics_history.go b/internal/monitoring/mock_metrics_history.go
index 4e5ecfd2b3..9978262b5a 100644
--- a/internal/monitoring/mock_metrics_history.go
+++ b/internal/monitoring/mock_metrics_history.go
@@ -591,7 +591,6 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
log.Debug().Int("count", len(state.Nodes)).Msg("mock seeding: processing nodes")
for _, node := range state.Nodes {
recordNode(node)
- time.Sleep(50 * time.Millisecond) // Reduced from 200ms for faster startup
}
runningVMs := 0
@@ -603,7 +602,6 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
log.Debug().Int("total", len(state.VMs)).Int("running", runningVMs).Msg("mock seeding: processing VMs (including stopped)")
for _, vm := range state.VMs {
recordGuest([]string{vm.ID}, "vm", vm.ID, true, true, true)
- time.Sleep(50 * time.Millisecond) // Reduced from 200ms for faster startup
}
runningContainers := 0
@@ -615,7 +613,6 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
log.Debug().Int("total", len(state.Containers)).Int("running", runningContainers).Msg("mock seeding: processing containers (including stopped)")
for _, ct := range state.Containers {
recordGuest([]string{ct.ID}, "container", ct.ID, true, true, true)
- time.Sleep(50 * time.Millisecond) // Reduced from 200ms for faster startup
}
k8sNodeCount := 0
@@ -671,7 +668,6 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
}
recordGuest([]string{metricID}, "k8s", metricID, true, true, true)
}
- time.Sleep(30 * time.Millisecond)
}
log.Debug().Int("count", len(state.Storage)).Msg("mock seeding: processing storage")
@@ -681,7 +677,6 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
}
_, _, total, _ := normalizedStorageCapacityMetrics(storage.Total, storage.Used, storage.Free, storage.Usage)
recordStorageTimeline(storage.ID, total)
- time.Sleep(50 * time.Millisecond) // Reduced from 200ms for faster startup
}
log.Debug().Int("count", len(state.PhysicalDisks)).Msg("mock seeding: processing physical disks")
@@ -761,7 +756,6 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
false,
)
}
- time.Sleep(50 * time.Millisecond) // Add delay for docker hosts
}
log.Debug().Int("count", len(state.Hosts)).Msg("mock seeding: processing host agents")
@@ -778,7 +772,6 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
true,
true,
)
- time.Sleep(50 * time.Millisecond)
}
platformFixtures := graph.PlatformFixtures
diff --git a/internal/monitoring/mock_metrics_history_test.go b/internal/monitoring/mock_metrics_history_test.go
index 060d888dec..7649371e42 100644
--- a/internal/monitoring/mock_metrics_history_test.go
+++ b/internal/monitoring/mock_metrics_history_test.go
@@ -25,6 +25,22 @@ func setMockSamplerTestEnv(t *testing.T, seedDuration, sampleInterval time.Durat
t.Setenv("PULSE_MOCK_TRENDS_SAMPLE_INTERVAL", sampleInterval.String())
}
+func compactMockFixtureConfig() mock.MockConfig {
+ cfg := mock.DefaultConfig
+ cfg.NodeCount = 1
+ cfg.VMsPerNode = 0
+ cfg.LXCsPerNode = 0
+ cfg.DockerHostCount = 0
+ cfg.DockerContainersPerHost = 0
+ cfg.GenericHostCount = 0
+ cfg.K8sClusterCount = 0
+ cfg.K8sNodesPerCluster = 0
+ cfg.K8sPodsPerCluster = 0
+ cfg.K8sDeploymentsPerCluster = 0
+ cfg.RandomMetrics = false
+ return cfg
+}
+
func TestBuildTieredTimestamps_IncludesCanonicalTerminalNow(t *testing.T) {
now := time.Date(2026, time.March, 31, 12, 0, 0, 0, time.UTC)
@@ -624,18 +640,8 @@ func TestSeedMockMetricsHistory_UsesCanonicalMockFixtureGraphForLegacyAndProvide
}
})
- t.Setenv("PULSE_MOCK_NODES", "1")
- t.Setenv("PULSE_MOCK_VMS_PER_NODE", "0")
- t.Setenv("PULSE_MOCK_LXCS_PER_NODE", "0")
- t.Setenv("PULSE_MOCK_DOCKER_HOSTS", "0")
- t.Setenv("PULSE_MOCK_DOCKER_CONTAINERS", "0")
- t.Setenv("PULSE_MOCK_GENERIC_HOSTS", "0")
- t.Setenv("PULSE_MOCK_K8S_CLUSTERS", "0")
- t.Setenv("PULSE_MOCK_K8S_NODES", "0")
- t.Setenv("PULSE_MOCK_K8S_PODS", "0")
- t.Setenv("PULSE_MOCK_K8S_DEPLOYMENTS", "0")
-
mock.SetEnabled(false)
+ mock.SetMockConfig(compactMockFixtureConfig())
mock.SetEnabled(true)
graph := mock.CurrentFixtureGraph()
@@ -703,18 +709,19 @@ func TestSeedMockMetricsHistory_UsesCanonicalMockFixtureGraphForLegacyAndProvide
}
func TestStartMockMetricsSampler_DoesNotClearExistingMetricsStoreData(t *testing.T) {
- t.Setenv("PULSE_MOCK_NODES", "1")
- t.Setenv("PULSE_MOCK_VMS_PER_NODE", "0")
- t.Setenv("PULSE_MOCK_LXCS_PER_NODE", "0")
- t.Setenv("PULSE_MOCK_DOCKER_HOSTS", "0")
- t.Setenv("PULSE_MOCK_DOCKER_CONTAINERS", "0")
- t.Setenv("PULSE_MOCK_GENERIC_HOSTS", "0")
- t.Setenv("PULSE_MOCK_K8S_CLUSTERS", "0")
- t.Setenv("PULSE_MOCK_K8S_NODES", "0")
- t.Setenv("PULSE_MOCK_K8S_PODS", "0")
- t.Setenv("PULSE_MOCK_K8S_DEPLOYMENTS", "0")
setMockSamplerTestEnv(t, time.Hour, 5*time.Minute)
+ previousEnabled := mock.IsMockEnabled()
+ previousConfig := mock.GetConfig()
+ t.Cleanup(func() {
+ mock.SetEnabled(false)
+ mock.SetMockConfig(previousConfig)
+ if previousEnabled {
+ mock.SetEnabled(true)
+ mock.SetMockConfig(previousConfig)
+ }
+ })
+
cfg := metrics.DefaultConfig(t.TempDir())
cfg.RetentionRaw = 90 * 24 * time.Hour
cfg.RetentionMinute = 90 * 24 * time.Hour
@@ -740,8 +747,9 @@ func TestStartMockMetricsSampler_DoesNotClearExistingMetricsStoreData(t *testing
},
})
+ mock.SetEnabled(false)
+ mock.SetMockConfig(compactMockFixtureConfig())
mock.SetEnabled(true)
- t.Cleanup(func() { mock.SetEnabled(false) })
monitor := &Monitor{
metricsHistory: NewMetricsHistory(1000, 24*time.Hour),