Commit fbf2954
committed
feat(mgmt): add SSE endpoint for live cluster topology events
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.1 parent 4e27345 commit fbf2954
11 files changed
Lines changed: 1307 additions & 15 deletions
File tree
- internal
- cluster
- eventbus
- pkg/backend
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
11 | 41 | | |
12 | 42 | | |
13 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| |||
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| 85 | + | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| |||
230 | 233 | | |
231 | 234 | | |
232 | 235 | | |
| 236 | + | |
| 237 | + | |
233 | 238 | | |
234 | 239 | | |
235 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
9 | 28 | | |
10 | 29 | | |
11 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
10 | 24 | | |
11 | 25 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
16 | 31 | | |
17 | 32 | | |
18 | 33 | | |
19 | 34 | | |
20 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
21 | 58 | | |
22 | 59 | | |
23 | 60 | | |
| |||
32 | 69 | | |
33 | 70 | | |
34 | 71 | | |
35 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
36 | 76 | | |
37 | 77 | | |
38 | 78 | | |
| 79 | + | |
39 | 80 | | |
40 | 81 | | |
41 | 82 | | |
| |||
80 | 121 | | |
81 | 122 | | |
82 | 123 | | |
83 | | - | |
| 124 | + | |
| 125 | + | |
84 | 126 | | |
85 | 127 | | |
86 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
87 | 133 | | |
88 | 134 | | |
89 | 135 | | |
| |||
93 | 139 | | |
94 | 140 | | |
95 | 141 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 142 | + | |
| 143 | + | |
101 | 144 | | |
102 | | - | |
| 145 | + | |
103 | 146 | | |
104 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
105 | 156 | | |
106 | 157 | | |
107 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
108 | 170 | | |
109 | 171 | | |
110 | 172 | | |
| |||
0 commit comments