From 94e2ccc2d592eb7e4cf5038c5409d3bb6b7704e5 Mon Sep 17 00:00:00 2001 From: Peteris Rudzusiks Date: Thu, 21 Sep 2023 00:33:59 +0200 Subject: [PATCH] runtime: fix reading cgroup stats of sandboxes The cgroup stats come from resourcecontrol package in the form of pointers to structs. The sandbox Stat() method incorrectly was expecting structs. This caused the cpu and memory stats to always be 0, which in turn caused incorrect pod overhead metrics. Fixes #8035 Signed-off-by: Peteris Rudzusiks --- src/runtime/virtcontainers/sandbox.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index 9d46f66cdf..a8c3bc5d04 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -1742,12 +1742,14 @@ func (s *Sandbox) Stats(ctx context.Context) (SandboxStats, error) { // TODO Do we want to aggregate the overhead cgroup stats to the sandbox ones? switch mt := metrics.(type) { - case v1.Metrics: + case *v1.Metrics: stats.CgroupStats.CPUStats.CPUUsage.TotalUsage = mt.CPU.Usage.Total stats.CgroupStats.MemoryStats.Usage.Usage = mt.Memory.Usage.Usage - case v2.Metrics: + case *v2.Metrics: stats.CgroupStats.CPUStats.CPUUsage.TotalUsage = mt.CPU.UsageUsec stats.CgroupStats.MemoryStats.Usage.Usage = mt.Memory.Usage + default: + return SandboxStats{}, fmt.Errorf("unknown metrics type %T", mt) } tids, err := s.hypervisor.GetThreadIDs(ctx)