Skip to content

fix(shim): return cgroup v2 stats on unified hierarchy#12807

Open
a7i wants to merge 1 commit intogoogle:masterfrom
a7i:fix/shim-stats-cgroup-v2-type
Open

fix(shim): return cgroup v2 stats on unified hierarchy#12807
a7i wants to merge 1 commit intogoogle:masterfrom
a7i:fix/shim-stats-cgroup-v2-type

Conversation

@a7i
Copy link
Copy Markdown
Contributor

@a7i a7i commented Mar 28, 2026

Problem

On cgroup v2 (unified) hosts, containerd unmarshals task Stats as io.containerd.cgroups.v2.Metrics. The runsc v2 shim was choosing v1 vs v2 protobuf layout only from systemd-cgroup, so with cgroupfs (systemd-cgroup false) it returned v1 metrics and containerd logged errors such as:

can't unmarshal type "io.containerd.cgroups.v1.Metrics" to output "io.containerd.cgroups.v2.Metrics" 

I also realized that I hadn't set system-cgroup in the config so alternatively that would have fixed it

Fix

Use cgroups.Mode() == cgroups.Unified (same signal as OOM / cgroup load in this package) to pick getV2Stats vs getV1Stats.

Tests

  • TestTaskStatsProtobufTypeURLs asserts v1 and v2 marshal to distinct type URLs containing cgroups.v1 / cgroups.v2.

Risk

Low: stats wire format only; behavior aligns with host cgroup mode and containerd expectations.

Workaround (before this lands)

Run runsc with systemd-cgroup=true so the previous logic returns v2-shaped stats on affected nodes.

Task Stats must marshal io.containerd.cgroups.v2.Metrics when the host uses unified cgroup v2, even if runsc uses cgroupfs (systemd-cgroup false). Otherwise containerd logs unmarshal v1.Metrics to v2.Metrics errors. Use cgroups.Mode() == Unified, consistent with OOM/cgroup setup in the same package. Add a test that v1 and v2 stats Any type URLs differ.
@a7i a7i marked this pull request as ready for review March 28, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant