Skip to content

fix(node-metrics): one snoopy per pod, graceful stop, eBPF-attached fallback - #1439

Merged
beneiltis merged 1 commit into
mainfrom
perf/node-metrics-snoopy-per-pod
Nov 13, 2026
Merged

beneiltis merged 1 commit into
mainfrom
perf/node-metrics-snoopy-per-pod

Conversation

@beneiltis

Copy link
Copy Markdown
Contributor

Context

While measuring node-metrics on homeserver (k3s, kernel 6.8) it turned out that snoopy has not loaded a single eBPF program since v0.4.0; every pod's traffic came from the /proc/net/dev fallback. That is fixed in mogenius/snoopy#172. This PR is the operator side; it works with the current snoopy v0.4.37 (behaves as today) and with the fixed one.

Changes

  • One snoopy per pod instead of per container (snoopy.go, podinfo.go): all containers of a pod share the sandbox netns. Extra instances stacked one more TC program per container on every packet, and Metrics() flipped between the handles in random map order, producing wrong deltas for multi-container pods. The container to enter is picked in stable order, skipping first processes that already vanished. The procdev reader (networkstatsreader.go) also reported a pod once per container; it now tracks one entry per pod.
  • SIGTERM first, SIGKILL after 5 s: gives snoopy the chance to detach. On kernels without tcx (<6.6) netlink TC filters outlive a killed process and pile up on pod netns that survive container restarts.
  • eBPF values once attached, even while zero: the old "all-zero → read /proc/net/dev" rule read procdev every second for every idle pod. Now the fallback is used only until snoopy reports both counters attached. lo is skipped (it was never reported).
  • Snoopy status: Status() hands out a copy (the handler mutated the slices in place while the collector marshaled them); replaced stale handles are removed from the status; failures carry the error text instead of {}; status:<node>:snoopy is written on change plus every 5 min instead of every second.
  • Traffic deltas keyed by namespace/pod (dbstats.go): equal pod names in different namespaces (e.g. postgres-0) mixed their counters.

Measurements (homeserver)

  • today: 62 snoopy processes, ~29 MB PSS, 0 eBPF programs loaded
  • with fix: load eBPF counters again, count with TC only and skip lo snoopy#172 (60 instances, 2 veths each): 10.3 MB PSS, TC only, TSO on the peer stays on
  • multi-container pods are rare on our clusters (68 → 67 snoopy processes), so the per-pod change matters mostly for sidecar-heavy installations; the correctness fixes apply everywhere

Verification

go build ./..., go vet, existing unit tests and golangci-lint clean. Not yet deployed to a cluster.

🤖 Generated with Claude Code

…allback

- start one snoopy per pod instead of per container: all containers of a
  pod share the sandbox netns, so extra instances stacked a TC program
  per container on every packet and Metrics() flipped between handles in
  random map order; the procdev reader also reported a pod once per
  container
- stop snoopy with SIGTERM and only SIGKILL after 5s, so it can detach
  its programs (netlink TC filters outlive a killed process on <6.6)
- read eBPF values once snoopy attached both counters, even while zero;
  the all-zero heuristic read /proc/net/dev every second for every idle
  pod, and lo is no longer read at all
- hand out a copy of the snoopy status: the handler mutated the slices
  in place while the collector marshaled them; stale handles are now
  removed from the status and errors are stored as text instead of {}
- write status:<node>:snoopy on change (refresh every 5 min) instead of
  every second
- key traffic deltas by namespace/pod: equal pod names in different
  namespaces mixed their counters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@beneiltis
beneiltis merged commit 38c6f31 into main Nov 13, 2026
3 checks passed
@beneiltis
beneiltis deleted the perf/node-metrics-snoopy-per-pod branch November 13, 2026 11:40
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