cgroups: register sub-cgroup inodes for DogStatsD origin detection on cgroupv2
Summary
On AL2023/CRI-O with cgroupv2 and cgroup namespace isolation, DogStatsD origin detection silently drops all pod-level tags for every metric. This PR fixes the root cause.
Root cause
CRI-O creates cgroups with this layout:
/sys/fs/cgroup/kubepods/.../crio-<HASH>.scope/ ← inode A (registered)
/sys/fs/cgroup/kubepods/.../crio-<HASH>.scope/container/ ← inode B (skipped)
When a container process runs inside a cgroup namespace, its namespace root is the container/ subdirectory. The DogStatsD client reports inode B via |c:in-<inode>. However, readerV2.parseCgroups() uses WalkDir which visits .scope/ first and registers inode A. The existing overwrite guard (if _, exists := res[id]; !exists) then skips container/, so inode B is never entered into cgroupByInode. Every origin detection lookup misses, and GetCgroupByInode returns nil — silently, with no logging at any level.
Fix
Return a second value map[uint64]string (sub-cgroup inode → container ID) from parseCgroups(). When the overwrite guard fires on a duplicate container ID, record the sub-directory's inode in this map instead of discarding it. In RefreshCgroups, register both the primary inode and all sub-cgroup inodes in cgroupByInode, both pointing to the same Cgroup. Stats collection is unaffected (still uses the parent .scope/ path); only inode-based origin detection gains the extra entries.
Validation
Validated on a Kubernetes cluster running AL2023 + CRI-O + cgroupv2 with cgroup namespace isolation enabled. Before the fix, GetCgroupByInode returned nil for every DogStatsD packet. After the fix, lookups resolve correctly and pod-level tags (pod_name, kube_namespace, etc.) appear on all metrics.
Diff
pkg/util/cgroups/reader.go | changed readerImpl interface, updated RefreshCgroups
pkg/util/cgroups/readerv1.go | updated signature to return nil for sub-inodes (cgroupv1 unaffected)
pkg/util/cgroups/readerv2.go | collect sub-cgroup inodes during WalkDir
3 files changed, 33 insertions(+), 9 deletions(-)
All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.
I have read the CLA Document and I hereby sign the CLA
Oops, closure was accidental, ignore.
@frank-spano I'm not sure how we got into this state, but it looke like it needs another stamp from you?
Bump on this :)