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.

Wire tenant resource provider at startup

rcourtmand07c567b46d4
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 318cf7a47d..e7d435e7cf 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -103,6 +103,9 @@ fleet-continuity ownership instead of re-deriving resource history locally.
Invalid `sourceAdapter` values are rejected at the API boundary, so the fleet
lane continues to consume only the canonical adapter set rather than
introducing a broader compatibility escape hatch.
+The router now wires the tenant resource state provider during initial setup
+when a multi-tenant monitor is present, so tenant-scoped fleet pages do not
+trip a missing-provider 500 before the monitor has finished initializing.
The dedicated profile client now also routes list, schema, and validation
parsing through shared response helpers in `frontend-modern/src/api/agentProfiles.ts`,
so profile transport stays aligned with the governed API contract instead of
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index dfd0c01083..2b4440c9bd 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -148,6 +148,10 @@ unified-resource seeds end to end: `internal/api/resources.go`,
`internal/api/router_helpers.go`, and `internal/api/state_provider.go` no
longer treat raw tenant `StateSnapshot` data as a live registry-seeding owner
once `UnifiedResourceSnapshotForTenant` is available.
+The router now wires the tenant resource state provider during initial setup
+when a multi-tenant monitor is present, so non-default org resource list and
+facet reads do not fall back to a missing-provider 500 during normal tenant
+requests.
The unified agent settings surface now also follows an explicit shared
boundary with agent-lifecycle. Changes to
`frontend-modern/src/components/Settings/InfrastructureOperationsController.tsx` must carry this
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 94ba38ff70..cb04ecea96 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -127,6 +127,9 @@ canonical history contract without re-deriving their own timeline slices.
Invalid `sourceAdapter` values are rejected at the API boundary, which keeps
storage and recovery reads aligned with the canonical adapter set instead of
turning the timeline filter into an arbitrary free-text escape hatch.
+The router now wires the tenant resource state provider during initial setup
+when a multi-tenant monitor is present, so tenant-scoped storage and recovery
+pages do not hit a missing-provider 500 before the monitor is fully wired.
The shared unified-resource consumer hook now also preserves `capabilities`,
`relationships`, `recentChanges`, `facetCounts`, `policy`, and `aiSafeSummary`
fields when storage and recovery surfaces read unified resources, so those
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index bb4b0f64dd..0094b48cc7 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -3580,6 +3580,23 @@ func TestContract_ResourceListCarriesTimelineAndCapabilityContracts(t *testing.T
assertJSONSnapshot(t, got, want)
}
+func TestContract_ResourceListUsesTenantStateProviderAtStartup(t *testing.T) {
+ cfg := &config.Config{
+ DataPath: t.TempDir(),
+ ConfigPath: t.TempDir(),
+ }
+ router := NewRouter(cfg, nil, &monitoring.MultiTenantMonitor{}, nil, nil, "1.0.0")
+
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest(http.MethodGet, "/api/resources?page=1&limit=100", nil)
+ req = req.WithContext(context.WithValue(req.Context(), OrgIDContextKey, "tenant-a"))
+
+ router.resourceHandlers.HandleListResources(rec, req)
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())
+ }
+}
+
func TestContract_ResourceCapabilitiesJSONSnapshot(t *testing.T) {
payload := struct {
ResourceID string `json:"resourceId"`
diff --git a/internal/api/multi_tenant_setters_additional_test.go b/internal/api/multi_tenant_setters_additional_test.go
index 3df21f9b17..b20e5a14f6 100644
--- a/internal/api/multi_tenant_setters_additional_test.go
+++ b/internal/api/multi_tenant_setters_additional_test.go
@@ -1,6 +1,14 @@
package api
-import "testing"
+import (
+ "context"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/config"
+ "github.com/rcourtman/pulse-go-rewrite/internal/monitoring"
+)
func TestConfigHandlersSetMultiTenantMonitor(t *testing.T) {
handler := &ConfigHandlers{}
@@ -30,3 +38,37 @@ func TestRouterSetMultiTenantMonitor(t *testing.T) {
t.Fatalf("tenantStateProvider should be set on resource handlers")
}
}
+
+func TestNewRouterWiresTenantResourceStateProvider(t *testing.T) {
+ cfg := &config.Config{
+ DataPath: t.TempDir(),
+ ConfigPath: t.TempDir(),
+ }
+ mtm := &monitoring.MultiTenantMonitor{}
+
+ router := NewRouter(cfg, nil, mtm, nil, nil, "1.0.0")
+ if router.resourceHandlers == nil {
+ t.Fatal("expected resource handlers to be initialized")
+ }
+ if router.resourceHandlers.tenantStateProvider == nil {
+ t.Fatal("expected NewRouter to wire the tenant resource state provider when a multi-tenant monitor is provided")
+ }
+}
+
+func TestNewRouterServesTenantResourceListWithMultiTenantMonitor(t *testing.T) {
+ cfg := &config.Config{
+ DataPath: t.TempDir(),
+ ConfigPath: t.TempDir(),
+ }
+ mtm := &monitoring.MultiTenantMonitor{}
+ router := NewRouter(cfg, nil, mtm, nil, nil, "1.0.0")
+
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest(http.MethodGet, "/api/resources?page=1&limit=100", nil)
+ req = req.WithContext(context.WithValue(req.Context(), OrgIDContextKey, "tenant-a"))
+
+ router.resourceHandlers.HandleListResources(rec, req)
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())
+ }
+}
diff --git a/internal/api/router.go b/internal/api/router.go
index b49f9cbf00..e75a3dc56a 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -377,6 +377,9 @@ func (r *Router) setupRoutes() {
r.resourceHandlers.SetStateProvider(r.monitor)
}
}
+ if r.mtMonitor != nil && r.resourceHandlers != nil {
+ r.resourceHandlers.SetTenantStateProvider(NewMultiTenantStateProvider(r.mtMonitor, r.monitor))
+ }
if r.mtMonitor != nil {
r.mtMonitor.SetMonitorInitializer(r.configureMonitorDependencies)
}