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.

Make agent report refreshes linear and clone the registry once

rcourtman522926b0f817
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 776c588425..2dc2cee1e4 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -53,6 +53,20 @@ is exposed as unavailable, rather than replaced with a synthetic healthy state.
Delivery-log diagnostic text is a notification-attempt projection, not an agent admission or liveness verdict. Masking embedded destination credentials preserves failure context without changing agent identities, credentials, session replacement or removal policy. Consumers must use the retained failureClass and outcome as delivery evidence only; a transport error does not establish that the monitored agent is offline.
+### Accepted reports refresh the canonical store synchronously — issue #2199
+
+An accepted host, Docker or Kubernetes report, and an agent removal, refresh the
+canonical resource store before the handler returns, so ReadState consumers see
+agent-backed truth without waiting for a broadcast. The #2199 reductions keep
+that contract: they make each refresh pass cheaper (node-indexed guest parents
+in the unified-resources contract, one registry snapshot per pass in the
+monitoring contract) without deferring or coalescing reports. A pass is still
+estate-wide, so its cost scales with agent report volume times estate size;
+coalescing reports would trade this immediate visibility and needs its own
+decision here first.
+
+### Canonical Patrol and Assistant continuation, 2026-09-07
+
### Canonical Patrol and Assistant continuation, 2026-09-07
Patrol planning uses the canonical action broker's plan-only boundary. Policy
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 8b37947170..314c5786fe 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -30,6 +30,22 @@ of an unchanged snapshot must not append duplicate change records.
cover the publish and blocked-persistence boundaries. Synthetic performance
improvement alone does not establish field CPU relief.
+### One registry snapshot per store refresh pass — issue #2199
+
+Each store refresh pass (`updateResourceStore`, its read-path twin, and so
+every accepted agent report) ran five metric syncs and the alert sync, and each
+cloned the whole registry through `GetAll`. A pass now wraps the store in
+`resourceSnapshotStore`, which clones once and forwards metrics-target
+resolution, so every consumer of the pass reads one generation. Stores without
+metrics-target resolution pass through unwrapped, keeping the syncs' capability
+checks unchanged. `TestAgentReportRefreshClonesRegistryOnce` requires one clone
+per agent-report refresh and `TestResourceSnapshotStoreClonesOncePerPass` pins
+the wrapper. With node-indexed guest parents, a synthetic agent-report refresh
+at 2,080 resources moved from 188 to 82 ms; the pass still covers the whole
+estate, and it stays synchronous (see the agent-lifecycle contract).
+
+### Linked Pulse agent memory for Proxmox LXC — issue #2148 (22 September 2026)
+
### Linked Pulse agent memory for Proxmox LXC — issue #2148 (22 September 2026)
Both LXC memory paths (the efficient `cluster/resources` builder and the
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 0717837694..71e1c5d1c7 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -38,6 +38,26 @@ compares the old and new paths, while
boundary. The 1,000-resource benchmark is component evidence, not installed
fleet CPU attribution or a release acceptance claim.
+### Node-indexed guest parent resolution during ingest — issue #2199
+
+Guest ingest resolves each Proxmox guest's parent node, and that lookup can
+fall back to scanning for agent candidates by node name. Walking every resource
+for every guest made each snapshot rebuild quadratic in the estate. Every
+agent-producing source is ingested before the VM and container loops, so the
+registry buckets agents by lowercased node name for those loops, reusing
+`agentNodeScanIndex` from `buildChildCounts`. `ingestRecord` rebuilds a live
+index whenever an ingest yields an agent, and the indexed walk skips entries
+that are no longer the registry's current object for their ID, so resolution
+matches the full scan exactly. `TestGuestIngestParentsMatchFullAgentScan`
+compares every guest's ingest-time parent with the full scan, including a
+cluster whose guests are reachable only through the scan, and
+`TestAgentNodeScanIndexTracksAgentsIngestedWhileLive` pins the rebuild. On a
+synthetic estate of 8-node clusters the rebuild moved from 74 to 42 ms at 2,080
+resources and now grows linearly; that is component evidence, not installed
+fleet CPU attribution.
+
+### Bounded incident-history selection
+
Canonical frontend memory withdrawal is explicit: when a resource snapshot omits the canonical memory metric and its Proxmox memory facet marks usageUnavailable, the display merge must clear any previous metric. Plain partial omission remains compatible with richer REST state, and an incoming canonical metric (including measured zero) takes precedence over unavailable raw evidence. The adapter transition tests pin withdrawal and recovery; the hybrid-memory Chromium fixture exercises the rendered table and drawer at 1280px and 390px. Workload details remain canonical-only: withdrawal shows N/A in the table and removes the Memory section rather than manufacturing a raw-facet total; measured-zero recovery restores Total and Free, with screenshot positioning above fixed navigation. This does not change agent-only or arbitrary field-deletion semantics.
**VM-linked agent memory read — issue #1962 (7 September 2026)**
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 1f33ab3d3c..76c58be0f9 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -5110,6 +5110,7 @@ func (m *Monitor) updateResourceStoreForRead(state models.StateSnapshot) {
return
}
recordSupplementalResourceChanges(store, m.collectSupplementalChanges())
+ store = newResourceSnapshotStore(store)
m.syncAllUnifiedMetrics(store)
m.syncUnifiedResourceAlertsToState(store.GetAll())
}
@@ -5157,6 +5158,7 @@ func (m *Monitor) updateResourceStore(state models.StateSnapshot) {
if atomicStore, ok := store.(AtomicSnapshotResourceStore); ok {
atomicStore.PopulateSnapshotAndSupplemental(snapshotForStore, recordsBySource)
recordSupplementalResourceChanges(store, supplementalChanges)
+ store = newResourceSnapshotStore(store)
m.syncAllUnifiedMetrics(store)
for source, records := range recordsBySource {
if len(records) == 0 {
@@ -5188,10 +5190,52 @@ func (m *Monitor) updateResourceStore(state models.StateSnapshot) {
}
recordSupplementalResourceChanges(store, supplementalChanges)
+ store = newResourceSnapshotStore(store)
m.syncAllUnifiedMetrics(store)
m.syncUnifiedResourceAlertsToState(store.GetAll())
}
+// resourceSnapshotStore serves one GetAll clone to every consumer of a single
+// store-refresh pass. The metric syncs and the alert sync each cloned the
+// whole registry for themselves, up to six clones for every accepted agent
+// report (#2199). Consumers of a pass only read, so they can share one
+// generation.
+type resourceSnapshotStore struct {
+ ResourceStoreInterface
+ targets MetricsTargetResourceStore
+ resources []unifiedresources.Resource
+ listed bool
+}
+
+// newResourceSnapshotStore wraps store for one refresh pass. A store that
+// cannot resolve metrics targets is returned as is, so the metric syncs'
+// capability checks see exactly what they would without the wrapper.
+func newResourceSnapshotStore(store ResourceStoreInterface) ResourceStoreInterface {
+ if store == nil {
+ return nil
+ }
+ if _, ok := store.(*resourceSnapshotStore); ok {
+ return store
+ }
+ targets, ok := store.(MetricsTargetResourceStore)
+ if !ok {
+ return store
+ }
+ return &resourceSnapshotStore{ResourceStoreInterface: store, targets: targets}
+}
+
+func (s *resourceSnapshotStore) GetAll() []unifiedresources.Resource {
+ if !s.listed {
+ s.resources = s.ResourceStoreInterface.GetAll()
+ s.listed = true
+ }
+ return s.resources
+}
+
+func (s *resourceSnapshotStore) MetricsTargetForResource(resourceID string) *unifiedresources.MetricsTarget {
+ return s.targets.MetricsTargetForResource(resourceID)
+}
+
// refreshUnifiedResourceStoreAfterAgentStateChange makes accepted agent
// ingest and removal immediately visible to canonical ReadState consumers.
// WebSocket broadcasts may also rebuild the store for their own hydrate path,
diff --git a/internal/monitoring/monitor_host_agents_test.go b/internal/monitoring/monitor_host_agents_test.go
index 909933c9be..db06f95852 100644
--- a/internal/monitoring/monitor_host_agents_test.go
+++ b/internal/monitoring/monitor_host_agents_test.go
@@ -6408,3 +6408,79 @@ func TestApplyHostReportHonoursRemovalBlockWhenIdentityWouldFork(t *testing.T) {
t.Fatalf("expected removal block to be cleared, still have %+v", monitor.state.GetRemovedHostAgents())
}
}
+
+// countingResourceStore counts registry clones handed out by the live store.
+type countingResourceStore struct {
+ *unifiedresources.MonitorAdapter
+ getAll int
+}
+
+func (c *countingResourceStore) GetAll() []unifiedresources.Resource {
+ c.getAll++
+ return c.MonitorAdapter.GetAll()
+}
+
+// plainResourceStore lacks metrics-target resolution.
+type plainResourceStore struct {
+ ResourceStoreInterface
+}
+
+func TestResourceSnapshotStoreClonesOncePerPass(t *testing.T) {
+ now := time.Now().UTC()
+ adapter := unifiedresources.NewMonitorAdapter(unifiedresources.NewRegistry(nil))
+ adapter.PopulateFromSnapshot(models.StateSnapshot{
+ LastUpdate: now,
+ VMs: []models.VM{{
+ ID: "lab:pve1:101", VMID: 101, Name: "db", Node: "pve1", Instance: "lab",
+ Status: "running", Type: "qemu", LastSeen: now,
+ }},
+ })
+ counting := &countingResourceStore{MonitorAdapter: adapter}
+
+ store := newResourceSnapshotStore(counting)
+ first := store.GetAll()
+ second := store.GetAll()
+ if counting.getAll != 1 {
+ t.Fatalf("underlying GetAll calls = %d, want 1", counting.getAll)
+ }
+ if len(first) != 1 || len(second) != 1 || &first[0] != &second[0] {
+ t.Fatalf("pass consumers did not share one snapshot: %d and %d resources", len(first), len(second))
+ }
+ resolver, ok := store.(MetricsTargetResourceStore)
+ if !ok || resolver.MetricsTargetForResource(first[0].ID) == nil {
+ t.Fatal("snapshot store does not forward metrics-target resolution")
+ }
+ if again := newResourceSnapshotStore(store); again != store {
+ t.Fatal("wrapping a pass snapshot again must reuse it")
+ }
+
+ plain := plainResourceStore{ResourceStoreInterface: adapter}
+ if wrapped := newResourceSnapshotStore(plain); wrapped != ResourceStoreInterface(plain) {
+ t.Fatal("a store without metrics-target resolution must pass through unwrapped")
+ }
+}
+
+// An accepted agent report refreshes the store once. Every metric sync and the
+// alert sync in that pass must share a single registry clone (#2199).
+func TestAgentReportRefreshClonesRegistryOnce(t *testing.T) {
+ now := time.Now().UTC()
+ state := models.NewState()
+ state.UpdateNodes([]models.Node{{ID: "lab-pve1", Name: "pve1", Instance: "lab", Status: "online", Type: "node", LastSeen: now}})
+ state.UpdateVMs([]models.VM{{
+ ID: "lab:pve1:101", VMID: 101, Name: "db", Node: "pve1", Instance: "lab",
+ Status: "running", Type: "qemu", CPU: 0.2, LastSeen: now,
+ }})
+ state.UpsertHost(models.Host{ID: "agent-1", Hostname: "pve1.example", Status: "online", CPUUsage: 3, LastSeen: now})
+
+ counting := &countingResourceStore{MonitorAdapter: unifiedresources.NewMonitorAdapter(unifiedresources.NewRegistry(nil))}
+ m := &Monitor{
+ state: state,
+ resourceStore: counting,
+ metricsHistory: NewMetricsHistory(32, time.Hour),
+ }
+
+ m.refreshUnifiedResourceStoreAfterAgentStateChange()
+ if counting.getAll != 1 {
+ t.Fatalf("registry clones for one agent report refresh = %d, want 1", counting.getAll)
+ }
+}
diff --git a/internal/unifiedresources/registry.go b/internal/unifiedresources/registry.go
index 69003927fd..80146cd2f7 100644
--- a/internal/unifiedresources/registry.go
+++ b/internal/unifiedresources/registry.go
@@ -126,12 +126,13 @@ type ResourceRegistry struct {
// viewsDirty is false, like every other cached field above.
cachedSourceTargets map[string][]SourceTarget
- // agentNodeScanIndex buckets agent resources by lowercased node name for
- // the duration of one buildChildCounts pass, where the agent-parent
- // fallback would otherwise scan every resource once per guest. Only that
- // pass sets it; nil means callers take the full scan. Bucket membership
- // is fixed for the pass (Type and NodeName are never mutated mid-pass)
- // while scores stay live through the shared pointers.
+ // agentNodeScanIndex buckets agent resources by lowercased node name
+ // while guests are ingested and during one buildChildCounts pass, where
+ // the agent-parent fallback would otherwise scan every resource once per
+ // guest. nil means callers take the full scan. ingestRecord rebuilds it
+ // whenever an ingest yields an agent, so bucket membership always matches
+ // what the full scan would see; scores stay live through the shared
+ // pointers.
agentNodeScanIndex map[string][]agentNodeCandidate
}
@@ -268,12 +269,23 @@ func (rr *ResourceRegistry) ingestSnapshot(snapshot models.StateSnapshot, thresh
rr.ingestPMGInstance(instance)
}
var guestSuccessions []CanonicalIDSuccession
+ // Every guest resolves its parent node, which can fall back to a scan of
+ // every resource. Each agent-producing source is ingested above, so bucket
+ // agents by node once for the guest loops instead of walking the registry
+ // per guest: that walk made every agent report's rebuild quadratic in the
+ // estate (#2199).
+ rr.mu.Lock()
+ rr.agentNodeScanIndex = rr.buildAgentNodeScanIndexLocked()
+ rr.mu.Unlock()
for _, vm := range snapshot.VMs {
guestSuccessions = append(guestSuccessions, rr.ingestVM(vm, clusterByInstance, nodeNamesByInstance)...)
}
for _, ct := range snapshot.Containers {
guestSuccessions = append(guestSuccessions, rr.ingestContainer(ct, clusterByInstance, nodeNamesByInstance)...)
}
+ rr.mu.Lock()
+ rr.agentNodeScanIndex = nil
+ rr.mu.Unlock()
rr.applyRecordSuccessions(guestSuccessions)
for _, storage := range snapshot.Storage {
rr.ingestStorage(storage)
@@ -2658,9 +2670,12 @@ func (rr *ResourceRegistry) ingest(source DataSource, sourceID string, resource
// normal canonical matching rules, but may only introduce absent resources.
// Returning an empty ID also prevents a skipped record from attaching retired
// identities or migrating operator-owned state onto the current resource.
-func (rr *ResourceRegistry) ingestRecord(source DataSource, sourceID string, resource Resource, identity ResourceIdentity, onlyMissing bool) string {
+func (rr *ResourceRegistry) ingestRecord(source DataSource, sourceID string, resource Resource, identity ResourceIdentity, onlyMissing bool) (ingestedID string) {
rr.mu.Lock()
defer rr.mu.Unlock()
+ if rr.agentNodeScanIndex != nil {
+ defer func() { rr.refreshAgentNodeScanIndexLocked(ingestedID) }()
+ }
rr.invalidateSourceTargetsLocked()
sourceID = normalizeSourceID(sourceID)
if sourceID == "" {
@@ -4549,6 +4564,11 @@ func (rr *ResourceRegistry) proxmoxNodeParentIDFromResourcesLocked(instance, clu
// buildChildCounts is mid-pass: only this node's agent candidates
// can match, so skip the full walk.
for _, candidate := range rr.agentNodeScanIndex[strings.ToLower(nodeName)] {
+ // A merge since indexing may have replaced or removed the entry;
+ // the full scan would only see the registry's current object.
+ if rr.resources[candidate.id] != candidate.resource {
+ continue
+ }
consider(candidate.id, candidate.resource)
}
return bestID
@@ -4601,11 +4621,10 @@ func proxmoxNodeParentScopeScore(instance, clusterName string, parent *ProxmoxDa
}
}
-func (rr *ResourceRegistry) buildChildCounts() {
- // The parent-resolution loop below may hit the agent fallback scan once
- // per guest. Bucketing agents by node name up front turns each of those
- // scans into a lookup over that node's few candidates.
- rr.agentNodeScanIndex = make(map[string][]agentNodeCandidate)
+// buildAgentNodeScanIndexLocked buckets agent resources by lowercased node
+// name. The caller holds rr.mu for writing.
+func (rr *ResourceRegistry) buildAgentNodeScanIndexLocked() map[string][]agentNodeCandidate {
+ index := make(map[string][]agentNodeCandidate)
for id, r := range rr.resources {
if r == nil || r.Proxmox == nil || CanonicalResourceType(r.Type) != ResourceTypeAgent {
continue
@@ -4614,8 +4633,30 @@ func (rr *ResourceRegistry) buildChildCounts() {
if nodeName == "" {
continue
}
- rr.agentNodeScanIndex[nodeName] = append(rr.agentNodeScanIndex[nodeName], agentNodeCandidate{id: id, resource: r})
+ index[nodeName] = append(index[nodeName], agentNodeCandidate{id: id, resource: r})
}
+ return index
+}
+
+// refreshAgentNodeScanIndexLocked rebuilds a live index after an ingest
+// yields an agent, whose node name may be new to the buckets. Guest ingests,
+// the common case while the index is live, leave it untouched.
+func (rr *ResourceRegistry) refreshAgentNodeScanIndexLocked(resourceID string) {
+ if rr.agentNodeScanIndex == nil {
+ return
+ }
+ resource := rr.resources[CanonicalResourceID(resourceID)]
+ if resource == nil || resource.Proxmox == nil || CanonicalResourceType(resource.Type) != ResourceTypeAgent {
+ return
+ }
+ rr.agentNodeScanIndex = rr.buildAgentNodeScanIndexLocked()
+}
+
+func (rr *ResourceRegistry) buildChildCounts() {
+ // The parent-resolution loop below may hit the agent fallback scan once
+ // per guest. Bucketing agents by node name up front turns each of those
+ // scans into a lookup over that node's few candidates.
+ rr.agentNodeScanIndex = rr.buildAgentNodeScanIndexLocked()
defer func() { rr.agentNodeScanIndex = nil }()
// ChildCount and ParentName are derived fields. Clear prior values before
diff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.go
index 9d05b7d728..ea5104982a 100644
--- a/internal/unifiedresources/registry_test.go
+++ b/internal/unifiedresources/registry_test.go
@@ -6650,3 +6650,132 @@ func TestIssue2076USBLinkedDiskAmbiguity(t *testing.T) {
})
}
}
+
+// Guest ingest resolves each guest's parent node, which can fall back to a
+// scan of every agent. The guest pass answers that fallback from
+// agentNodeScanIndex, so the index must resolve exactly what the scan would.
+
+// agentNodeScanFixture spans three clusters that reuse node names, so a
+// by-name bucket holds candidates from every cluster and scope scoring has to
+// pick the right one. Every other node runs a linked host agent. A fourth
+// cluster's nodes are keyed by their endpoint instance while its guests report
+// the cluster name, so no direct source mapping reaches their parent and only
+// the agent scan resolves it.
+func agentNodeScanFixture(now time.Time) models.StateSnapshot {
+ snapshot := models.StateSnapshot{LastUpdate: now}
+ for n := 0; n < 2; n++ {
+ nodeName := fmt.Sprintf("pve%d", n)
+ snapshot.Nodes = append(snapshot.Nodes, models.Node{
+ ID: "ep-" + nodeName, Name: nodeName, Instance: "ep", ClusterName: "prod",
+ Status: "online", Type: "node", LastSeen: now,
+ })
+ vmid := 900 + n
+ snapshot.VMs = append(snapshot.VMs, models.VM{
+ ID: fmt.Sprintf("prod:%s:%d", nodeName, vmid), VMID: vmid,
+ Name: fmt.Sprintf("vm-%d", vmid), Node: nodeName, Instance: "prod",
+ Status: "running", Type: "qemu", LastSeen: now,
+ })
+ }
+ for cluster := 0; cluster < 3; cluster++ {
+ instance := fmt.Sprintf("lab%d", cluster)
+ for n := 0; n < 4; n++ {
+ nodeName := fmt.Sprintf("pve%d", n)
+ nodeID := instance + "-" + nodeName
+ node := models.Node{
+ ID: nodeID,
+ Name: nodeName,
+ Instance: instance,
+ Status: "online",
+ Type: "node",
+ LastSeen: now,
+ }
+ if n%2 == 0 {
+ hostID := fmt.Sprintf("agent-%s-%s", instance, nodeName)
+ node.LinkedAgentID = hostID
+ snapshot.Hosts = append(snapshot.Hosts, models.Host{
+ ID: hostID,
+ Hostname: fmt.Sprintf("%s.%s.example", nodeName, instance),
+ Status: "online",
+ LastSeen: now,
+ LinkedNodeID: nodeID,
+ })
+ }
+ snapshot.Nodes = append(snapshot.Nodes, node)
+ for g := 0; g < 3; g++ {
+ vmid := 100 + cluster*100 + n*10 + g
+ snapshot.VMs = append(snapshot.VMs, models.VM{
+ ID: fmt.Sprintf("%s:%s:%d", instance, nodeName, vmid), VMID: vmid,
+ Name: fmt.Sprintf("vm-%d", vmid), Node: nodeName, Instance: instance,
+ Status: "running", Type: "qemu", LastSeen: now,
+ })
+ ctid := 5000 + vmid
+ snapshot.Containers = append(snapshot.Containers, models.Container{
+ ID: fmt.Sprintf("%s:%s:%d", instance, nodeName, ctid), VMID: ctid,
+ Name: fmt.Sprintf("ct-%d", ctid), Node: nodeName, Instance: instance,
+ Status: "running", Type: "lxc", LastSeen: now,
+ })
+ }
+ }
+ }
+ return snapshot
+}
+
+func TestGuestIngestParentsMatchFullAgentScan(t *testing.T) {
+ snapshot := agentNodeScanFixture(time.Now().UTC())
+ rr := NewRegistry(nil)
+ rr.IngestSnapshot(snapshot)
+
+ rr.mu.RLock()
+ defer rr.mu.RUnlock()
+ if rr.agentNodeScanIndex != nil {
+ t.Fatal("agent node index outlived the ingest pass")
+ }
+ checked := 0
+ for id, resource := range rr.resources {
+ if resource.Type != ResourceTypeVM && resource.Type != ResourceTypeSystemContainer {
+ continue
+ }
+ if resource.Proxmox == nil {
+ t.Fatalf("guest %s has no Proxmox data", id)
+ }
+ // With the index nil this resolves through the full scan.
+ want := rr.proxmoxNodeParentIDLocked(resource.Proxmox.Instance, resource.Proxmox.ClusterName, resource.Proxmox.NodeName, "")
+ if want == "" {
+ t.Fatalf("full scan found no parent for guest %s on %s/%s", id, resource.Proxmox.Instance, resource.Proxmox.NodeName)
+ }
+ if got := CanonicalResourceID(resource.parentBySource[SourceProxmox]); got != want {
+ t.Fatalf("guest %s on %s/%s: ingest parent %q, full scan %q", id, resource.Proxmox.Instance, resource.Proxmox.NodeName, got, want)
+ }
+ checked++
+ }
+ if want := len(snapshot.VMs) + len(snapshot.Containers); checked != want {
+ t.Fatalf("checked %d guests, want %d", checked, want)
+ }
+}
+
+func TestAgentNodeScanIndexTracksAgentsIngestedWhileLive(t *testing.T) {
+ now := time.Now().UTC()
+ rr := NewRegistry(nil)
+ rr.IngestSnapshot(models.StateSnapshot{
+ LastUpdate: now,
+ Nodes: []models.Node{{ID: "lab-pve1", Name: "pve1", Instance: "lab", Status: "online", Type: "node", LastSeen: now}},
+ })
+
+ rr.mu.Lock()
+ rr.agentNodeScanIndex = rr.buildAgentNodeScanIndexLocked()
+ rr.mu.Unlock()
+ defer func() {
+ rr.mu.Lock()
+ rr.agentNodeScanIndex = nil
+ rr.mu.Unlock()
+ }()
+
+ rr.ingestProxmoxNode(models.Node{ID: "lab-pve2", Name: "pve2", Instance: "lab", Status: "online", Type: "node", LastSeen: now}, nil)
+
+ rr.mu.RLock()
+ defer rr.mu.RUnlock()
+ candidates := rr.agentNodeScanIndex["pve2"]
+ if len(candidates) != 1 || rr.resources[candidates[0].id] != candidates[0].resource {
+ t.Fatalf("index bucket for an agent ingested while live = %+v, want its registry entry", candidates)
+ }
+}