Skip to content

feat(mgmt): add SSE endpoint for live cluster topology events#119

Merged
hyp3rd merged 1 commit into
mainfrom
feat/dist-mem-cache
May 9, 2026
Merged

feat(mgmt): add SSE endpoint for live cluster topology events#119
hyp3rd merged 1 commit into
mainfrom
feat/dist-mem-cache

Conversation

@hyp3rd
Copy link
Copy Markdown
Owner

@hyp3rd hyp3rd commented May 9, 2026

Introduce GET /cluster/events on the management HTTP port, streaming members and heartbeat Server-Sent Events to subscribers in real time, replacing the monitor's 2-second poll cadence with a push-based model.

Key changes:

  • New internal/eventbus package: in-process fan-out broadcaster with drop-on-full semantics (slow consumers never backpressure the SWIM heartbeat loop) and context-driven subscription reaping.
  • Membership.OnStateChange observer hook fires after every mutation (Upsert/Mark/Remove) with the lock already released, publishing a full membership snapshot onto the event bus.
  • 1 Hz heartbeat event publisher aligned with the SWIM interval.
  • defaultWriteTimeout changed from 5s to 0 on the mgmt server to prevent fasthttp from force-closing the long-lived SSE stream.
  • HyperCache.EventBus() accessor exposes the bus to the SSE handler; non-distributed backends return nil (503 fallback).
  • Connect-time frames deliver current snapshots so fresh subscribers see topology immediately without waiting for the next mutation.

Includes unit tests for eventbus and membership observers, plus an integration test (TestManagementHTTP_ClusterEvents) that reads frames for 6s past the historic 5s WriteTimeout deadline to pin the regression.

Introduce `GET /cluster/events` on the management HTTP port, streaming
`members` and `heartbeat` Server-Sent Events to subscribers in real time,
replacing the monitor's 2-second poll cadence with a push-based model.

Key changes:
- New `internal/eventbus` package: in-process fan-out broadcaster with
  drop-on-full semantics (slow consumers never backpressure the SWIM
  heartbeat loop) and context-driven subscription reaping.
- `Membership.OnStateChange` observer hook fires after every mutation
  (Upsert/Mark/Remove) with the lock already released, publishing a
  full membership snapshot onto the event bus.
- 1 Hz heartbeat event publisher aligned with the SWIM interval.
- `defaultWriteTimeout` changed from 5s to 0 on the mgmt server to
  prevent fasthttp from force-closing the long-lived SSE stream.
- `HyperCache.EventBus()` accessor exposes the bus to the SSE handler;
  non-distributed backends return nil (503 fallback).
- Connect-time frames deliver current snapshots so fresh subscribers
  see topology immediately without waiting for the next mutation.

Includes unit tests for eventbus and membership observers, plus an
integration test (`TestManagementHTTP_ClusterEvents`) that reads frames
for 6s past the historic 5s WriteTimeout deadline to pin the regression.
@hyp3rd hyp3rd merged commit b394cee into main May 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant