mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-24 12:42:49 +00:00
0abe518219
Every accepted agent report refreshed the canonical resource store, and every refresh covers the whole estate, so refresh work grew with agent count × estate size (#2199). #2235 made each pass linear and cheaper. This PR bounds how many passes reports can trigger. **Behaviour.** Accepted host, Docker and Kubernetes reports, including rejected-report liveness, refresh through `refreshUnifiedResourceStoreAfterAgentReport`: - The first report after a quiet window is published before its handler returns, the same as today. - Reports within 2 s of the previous refresh fold into one trailing refresh at the window's end. It reads the latest state and broadcasts it to websocket clients. - 2 s matches `readPathRegistryFreshness`, the staleness the read paths already accept. - Agent removal and host-agent evaluation still refresh immediately, so removed inventory retires at once. - `Monitor.Stop` cancels a pending trailing refresh and waits for a running one before closing stores. - Monitors built without `New` keep a zero window and refresh on every report. **Cost bound.** At 2,080 resources one refresh costs about 82 ms (after #2235). 200 agents reporting every 30 s drive 6.7 refreshes/s, roughly 55% of a core; coalesced, reports trigger at most one refresh per 2 s, about 4%, however many agents report. **Contract change.** The agent-lifecycle contract promised that an accepted report is visible when its handler returns. It is now visible within the 2 s window. The founder approved that trade on 24 September 2026, and the contract records it. **Tests** - `TestAgentReportRefreshFoldsReportsWithinWindow`: the leading report is published synchronously; a burst inside the window is deferred; one trailing refresh publishes the burst's latest value; after a quiet window the next report is synchronous again. It fails when the throttle is removed. - `TestStopCancelsPendingAgentReportRefresh`: fails if stop does not cancel the pending refresh. - The issue-1753 end-to-end test posts two reports back to back, so it now waits for the published rows instead of reading them at once. **Verification on pulse-dev** - `internal/monitoring` runs in 112 s against 107 s on #2235's head. No test is slower by more than 1.2 s. - `internal/unifiedresources`, `internal/websocket` and `internal/api/...` pass. `TestServerInfoEndpointReportsDevelopment` fails in that source export with and without this change, because the export has no git checkout. Refs #2199