Memory table now uses the 34 min steady-state sample (333.8/297.1/213.1 MiB against 330.2/309.1/194.5 before the roll), and the verification block carries the actual 30 min window result: rate and increase both 0 on all three nodes, counters flat at 31/31/30 for 30 min with the linode and siriussec rings 100% full.
182 lines
8.8 KiB
Markdown
182 lines
8.8 KiB
Markdown
# Hubble event loss: why the counter was climbing and the gate on it
|
||
|
||
Finding **F10** of the [2026-11-27 cluster network-security audit](2026-11-27-cluster-netsec-audit.md).
|
||
Written up here because the number looked like data loss and was not, and because the
|
||
detector contract that came out of it outlives this particular fix.
|
||
|
||
## What was observed
|
||
|
||
```
|
||
$ promq 'sum by (node,source) (rate(hubble_lost_events_total[30m]))'
|
||
0.0966 node=linode source=hubble_ring_buffer
|
||
0.6821 node=siriussec source=hubble_ring_buffer
|
||
0.0050 node=rpi source=hubble_ring_buffer
|
||
$ promq 'sum by (node) (hubble_lost_events_total)'
|
||
23787 linode / 72529 siriussec / 156 rpi (2026-11-27T05:16Z)
|
||
```
|
||
|
||
`source` was always `hubble_ring_buffer`; `perf_event_ring_buffer` and
|
||
`observer_events_queue` were 0 on all three nodes the whole time, i.e. the BPF
|
||
perf ring (the only place events can genuinely be lost on the way in) never
|
||
dropped anything, and the metrics exporter never fell behind.
|
||
|
||
## Root cause — a measurement artefact, not dropped flows
|
||
|
||
`Ring.read()` (`pkg/hubble/container/ring.go`) synthesises a
|
||
`LostEvent{source: HUBBLE_RING_BUFFER}` **and increments the metric** whenever a
|
||
read falls outside the valid window — including the "reader behind writer" case
|
||
at the ring's read boundary. `getFlowRate()` (`pkg/hubble/observer/local_observer.go`)
|
||
walks the ring *backwards* over a full minute on every `ServerStatus` call, and
|
||
`ServerStatus` is called by:
|
||
|
||
* the agent's own hubble health probe, every **5 s** (12/min, constantly),
|
||
* every `hubble status` (including the one in `cilium-dbg status` and the Hubble UI's status panel),
|
||
* every UI/relay status request.
|
||
|
||
When the ring holds **less than one minute of flows**, that walk hits the
|
||
boundary, so each probe adds exactly 1 to the loss counter. Cilium's own tracker
|
||
is cilium#46584 (`hubble_ring_buffer` lost metric increments even when no events
|
||
are actually lost); upstream fixed it by counting only on forward reads, which
|
||
is not in the 1.20.1 build deployed here.
|
||
|
||
Measured proof on this cluster (2026-11-27T05:13Z):
|
||
|
||
| node | ring | flows/s | 10 back-to-back `hubble status` | +21 s idle |
|
||
|---|---|---|---|---|
|
||
| siriussec | 4095 (100 %) | ~80 | **+11** | +12 |
|
||
| linode | 4095 (100 %) | ~20 | **0** (40 calls) | 0 |
|
||
|
||
siriussec's ring held ~51 s at 80 flows/s → every probe hit the boundary.
|
||
linode's held ~200 s → the walk stopped on the timestamp check and nothing was
|
||
counted. That is the whole of the "0.68/s" on siriussec and the bursty ~4/min on
|
||
linode (during linode's ingest bursts the ring briefly held <60 s).
|
||
|
||
The cumulative 72,529 was therefore the counter counting reads, not losses.
|
||
No flow was actually dropped: with no client attached the ring only has to hold
|
||
history, and `Ring.Write()` never discards — it overwrites, and loss is only
|
||
ever reported at read time.
|
||
|
||
## The change
|
||
|
||
`infrastructure/networking/cilium/values.yaml` (Flux → HelmRelease `kube-system/cilium`):
|
||
|
||
```yaml
|
||
hubble:
|
||
eventBufferCapacity: "16383" # was the chart default, 4095
|
||
```
|
||
|
||
The ring must hold **>= 60 s at peak** so the backward walk exits on the
|
||
timestamp check instead of the boundary. 24 h peak flow rates measured in
|
||
Prometheus (`max_over_time(sum by (node)(rate(hubble_flows_processed_total[1m]))[24h:1m])`):
|
||
|
||
| node | 24 h peak flows/s | 16383 events = | 4095 events = |
|
||
|---|---|---|---|
|
||
| linode | 195.8 | 84 s | 21 s |
|
||
| siriussec | 101.5 | 161 s | 40 s |
|
||
| rpi | 38.4 | 427 s | 107 s |
|
||
|
||
16383 is the smallest ring that covers the 60 s walk on **every** node: at
|
||
linode's peak 8191 would hold 41 s (still under a minute, still hitting the
|
||
boundary), 16383 holds 84 s. 32767 is the next allowed step and doubles the
|
||
memory for headroom the 24 h peak does not justify. The ring only accepts
|
||
`2^n - 1` (1, 3, 7 … 4095, 8191, 16383, 32767, 65535).
|
||
|
||
### Memory cost per node (measured, not assumed)
|
||
|
||
The ring stores `*v1.Event` pointers and keeps the events themselves alive; the
|
||
delta is bounded by `(16383 - 4095) × retained bytes per event`. Measured with
|
||
`container_memory_working_set_bytes{pod=~"cilium-.*",container="cilium-agent"}`,
|
||
averaged over the 30 min before the roll (old 4095 agents) against a 34 min
|
||
uptime sample after all three agents restarted onto the new config:
|
||
|
||
| node | before (4095) | after (16383) | delta |
|
||
|---|---|---|---|
|
||
| siriussec | 330.2 MiB | 333.8 MiB | +3.6 MiB |
|
||
| linode | 309.1 MiB | 297.1 MiB | -12.0 MiB |
|
||
| rpi | 194.5 MiB | 213.1 MiB | +18.6 MiB |
|
||
|
||
The deltas straddle zero, i.e. the 12288 extra retained events are inside the
|
||
process's own allocation noise at this event size (they are pointers plus the
|
||
payloads that were already being allocated; the ring only delays their free).
|
||
The honest statement is: **no measurable growth; the Pi, the node with the
|
||
least headroom after linode, is +18.6 MiB.** Rejected alternative: 65535 "to be
|
||
safe" is 4x this for headroom the 24 h peak does not justify.
|
||
|
||
### Rollout
|
||
|
||
Config-only change: the chart does not put a configmap checksum on the
|
||
DaemonSet pod template, so the Helm upgrade updated `cilium-config` without
|
||
rolling the agents. The agents were restarted **one node at a time** (rpi →
|
||
linode → siriussec), each with the datapath checked before moving on:
|
||
|
||
* `hubble status` → `Current/Max Flows: … /16,383`
|
||
* pod↔pod across the mesh: linode → `forgejo.forgejo.svc:3000`, siriussec →
|
||
`osint-nats.osint.svc:8222`, rpi host → `10.10.0.2:8080` (gateway origin)
|
||
* linode pod → internet (masquerade) `https://data.gdeltproject.org/...`
|
||
* all three nodes `Ready`, `cilium` DaemonSet 3/3
|
||
|
||
Rollback: set `eventBufferCapacity` back to the default (delete the key) and
|
||
restart the agents, the same way. Nothing else changed — L7 is still on
|
||
(`enable-l7-proxy=true`), `hubble-metrics` still carries `flow`, no retention
|
||
change.
|
||
|
||
## The gate (this is the durable part)
|
||
|
||
A deeper ring removes *this* artefact. It does not make the stream
|
||
unconditionally complete — a genuinely overloaded agent, or a Hubble client that
|
||
cannot keep up with a follow stream, still loses events, and that failure is
|
||
silent. So the sensor contract is:
|
||
|
||
> **A 30-minute window with any lost event may not be reported as clean.**
|
||
|
||
Threshold and enforcement:
|
||
|
||
| rule | expression | meaning |
|
||
|---|---|---|
|
||
| `hubble:lost_events_increase_30m` (recorder) | `sum by (node) (increase(hubble_lost_events_total{source="hubble_ring_buffer"}[30m]))` | the gate value: any non-zero → window incomplete |
|
||
| `hubble:flows_processed_increase_30m` (recorder) | `sum by (node) (increase(hubble_flows_processed_total{type="Trace"}[30m]))` | denominator for the ratio |
|
||
| `HubbleFlowWindowIncomplete` (warning) | `hubble:lost_events_increase_30m > 0` for 10 m | a flow-shaped detector may not call this window clean |
|
||
| `HubbleFlowLossMaterial` (critical) | `lost / processed > 0.001` for 15 m | loss that is material, not a boundary artefact |
|
||
| `HubbleFlowSensorMissing` (critical) | `absent(hubble:flows_processed_increase_30m)` for 15 m | no input at all; the gate cannot even be evaluated |
|
||
|
||
All four live in `monitoring/controllers/home/hubble-loss-gate.yaml`
|
||
(Flux → `monitoring` Kustomization), so they evaluate against the same
|
||
Prometheus the detectors read and route to Alertmanager.
|
||
|
||
**How a detector must use it:** evaluate the traffic window and the gate value
|
||
over the *same* range; if `hubble:lost_events_increase_30m > 0` for the node(s)
|
||
in scope, the result is `incomplete` — never "no anomalous traffic". Alerting on
|
||
silence (absence of an expected event) is the case that matters most: a lossy
|
||
window produces false silence, not false noise.
|
||
|
||
## Verification (live, 2026-11-27)
|
||
|
||
```
|
||
# acceptance 1: 30 min window, after the last agent restart (05:19:48Z), read 05:53Z
|
||
$ promq 'sum by (node) (rate(hubble_lost_events_total{source="hubble_ring_buffer"}[30m]))'
|
||
0 node=rpi / 0 node=linode / 0 node=siriussec
|
||
$ promq 'sum by (node) (increase(hubble_lost_events_total{source="hubble_ring_buffer"}[30m]))'
|
||
0 node=rpi / 0 node=linode / 0 node=siriussec
|
||
|
||
# counter stops climbing — flat for 30 min, with both big rings 100 % full
|
||
$ promq 'sum by (node) (hubble_lost_events_total{source="hubble_ring_buffer"})'
|
||
31 rpi / 31 linode / 30 siriussec (05:23:47Z)
|
||
31 rpi / 31 linode / 30 siriussec (05:53:47Z)
|
||
|
||
# ...and the depth is what holds it there, not luck:
|
||
# siriussec Current/Max Flows 16,383/16,383, linode 16,383/16,383, rpi 10,685/16,383
|
||
|
||
# the artefact is gone: 20 status calls + 20 s idle move nothing
|
||
siriussec before: 30 after 20 status: 30 after +20s idle: 30
|
||
|
||
# flows still flow, L7 still on
|
||
$ hubble observe --last 3 # each of the three agents returns flows, incl. http-request
|
||
|
||
# scrape targets
|
||
hubble-metrics 10.10.0.1:9965 up / 10.10.0.2:9965 up / 10.10.0.5:9965 up
|
||
```
|
||
|
||
The ~30 events on the counter after each restart are the ring's own cold-start:
|
||
while the ring is still filling, a backward walk passes nil slots and each one
|
||
counts. It is a one-off per agent start, not a rate, and it ages out of the
|
||
30-minute window.
|