netsec(collector): gzip on rotate so 960 MiB holds ~72-100 h of flows #71

Merged
sirius merged 1 commit from wt/t_cfea18ac-gzip-rotate into master 2026-11-27 06:10:19 +00:00
Owner

What

Rotate-time gzip for netsec/hubble-flow-collector. No record-schema change, no filter change, no DaemonSet argument change (the DS diff is two comment lines; MAX_FILE_BYTES/MAX_FILES/MAX_TOTAL_BYTES values are untouched).

  • live file stays plain flows-<ts>-<n>.jsonl
  • on rotation the closed file becomes .jsonl.gz via temp name + atomic rename, in the background (never stalls the flow reader)
  • prune bounds the whole directory (archives + in-flight .gz.tmp) at 960 MiB, oldest first, and never reaps the live file or a file whose gzip is running
  • MAX_FILES now bounds plain files only

Why

The cap was fine; the retention was not. Measured 2026-11-27 on siriussec: 3.38-4.28 MB/min (4.5-6.2 GB/day) of filtered JSONL, i.e. ~4-5 h inside 960 MiB. Real-data ratio is 18.53x at gzip -9 (17.85x at -6):

rate 960 MiB holds
6.16 GB/day (60 s CI burst) 72.6 h
4.87 GB/day (card sample) 92.0 h
4.48 GB/day (55-min average) 99.9 h

Verification (offline, before merge)

  • five-scenario harness with a fake hubble: 13 rotations -> 13 archives, every archive gzip -t clean, every line complete JSON with the flow.* shape and newline-terminated, live file plain, dir under cap, oldest-first prune, live-file and in-flight protection proven by removing the marker and watching the same file get reaped
  • the same script run inside the real cilium image under dash with a replaying fake: 23 rotations -> 23 archives, all gzip -t OK, no plain-without-archive left behind
  • filter.awk untouched; sensor (sirius/netsec-agent) globs *.jsonl and already forgets rotated-away files, so it keeps reading; worst case it loses the tail written since its last 5-minute tick in the file that rotates
## What Rotate-time gzip for `netsec/hubble-flow-collector`. No record-schema change, no filter change, no DaemonSet argument change (the DS diff is two comment lines; `MAX_FILE_BYTES`/`MAX_FILES`/`MAX_TOTAL_BYTES` values are untouched). * live file stays plain `flows-<ts>-<n>.jsonl` * on rotation the closed file becomes `.jsonl.gz` via temp name + atomic rename, in the background (never stalls the flow reader) * prune bounds the whole directory (archives + in-flight `.gz.tmp`) at 960 MiB, oldest first, and never reaps the live file or a file whose gzip is running * `MAX_FILES` now bounds plain files only ## Why The cap was fine; the retention was not. Measured 2026-11-27 on siriussec: 3.38-4.28 MB/min (4.5-6.2 GB/day) of filtered JSONL, i.e. ~4-5 h inside 960 MiB. Real-data ratio is 18.53x at gzip -9 (17.85x at -6): | rate | 960 MiB holds | |---|---| | 6.16 GB/day (60 s CI burst) | 72.6 h | | 4.87 GB/day (card sample) | 92.0 h | | 4.48 GB/day (55-min average) | 99.9 h | ## Verification (offline, before merge) * five-scenario harness with a fake `hubble`: 13 rotations -> 13 archives, every archive `gzip -t` clean, every line complete JSON with the `flow.*` shape and newline-terminated, live file plain, dir under cap, oldest-first prune, live-file and in-flight protection proven by removing the marker and watching the same file get reaped * the same script run **inside the real cilium image under dash** with a replaying fake: 23 rotations -> 23 archives, all `gzip -t` OK, no plain-without-archive left behind * `filter.awk` untouched; sensor (`sirius/netsec-agent`) globs `*.jsonl` and already forgets rotated-away files, so it keeps reading; worst case it loses the tail written since its last 5-minute tick in the file that rotates
The collector wrote 150 MiB plaintext files into a directory capped at 960 MiB,
which bought only ~4-5 h of retention at the measured 4.5-6.2 GB/day
(3380-4280 kB/min) of filtered Hubble JSONL — the cap was sized for a forensic
window, not for hours.

Compress on rotate; no schema change, no filter change, no DS argument change:

* the file being appended stays plain `flows-<ts>-<n>.jsonl` (one file for a
  reader to tail);
* on rotation the closed file is gzip'd to `.jsonl.gz` through a temp name +
  atomic rename, in the background, so a reader never sees a partial archive and
  the flow reader never stalls (stalling it makes the agent drop events);
* prune bounds the WHOLE directory at MAX_TOTAL_BYTES = 960 MiB — archives and
  in-flight `.gz.tmp` included — deleting oldest first, and never reaps the live
  file nor a file whose gzip is still running (that would discard the archive
  and lose the entire file);
* MAX_FILES now bounds plain files only. Applying it to the archives is exactly
  what would keep retention at a few hours.

Measured on this node's live data 2026-11-27: 18.53x ratio at gzip -9
(17.85x at -6), i.e. 960 MiB holds 72.6 h at the 6.16 GB/day burst sample,
92 h at 4.87 GB/day and ~100 h at the 4.48 GB/day 55-minute average.

Verified offline against a replaying fake `hubble` (rotation->archive parity,
gzip -t on every archive, atomicity, oldest-first prune, live-file and in-flight
protection) and inside the real cilium image under dash (23 rotations -> 23
valid archives, no loss).
sirius merged commit 0fdd918875 into master 2026-11-27 06:10:19 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/homek8s!71
No description provided.