{"record":{"id":"dd943668802438ec","repo":"containerd/containerd","slug":"failed-decoding-metrics-for-sandbox-s-w","errorCode":null,"errorMessage":"failed decoding metrics for sandbox %s: %w","messagePattern":"failed decoding metrics for sandbox (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cri/server/sandbox_stats_linux.go","lineNumber":56,"sourceCode":"\tctx context.Context,\n\tsandbox sandboxstore.Sandbox) (*runtime.PodSandboxStats, error) {\n\tmeta := sandbox.Metadata\n\n\tif sandbox.Status.Get().State != sandboxstore.StateReady {\n\t\treturn nil, fmt.Errorf(\"failed to get pod sandbox stats since sandbox container %q is not in ready state: %w\", meta.ID, errdefs.ErrUnavailable)\n\t}\n\n\tctrl, err := c.sandboxService.SandboxController(sandbox.Sandboxer)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get controller for sandbox %s: %w\", sandbox.ID, err)\n\t}\n\tmetric, err := ctrl.Metrics(ctx, sandbox.ID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed getting metrics for sandbox %s: %w\", sandbox.ID, err)\n\t}\n\tstats, err := decodeSandboxCgroupMetrics(metric)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed decoding metrics for sandbox %s: %w\", sandbox.ID, err)\n\t}\n\n\tpodSandboxStats := &runtime.PodSandboxStats{\n\t\tLinux: &runtime.LinuxPodSandboxStats{},\n\t\tAttributes: &runtime.PodSandboxAttributes{\n\t\t\tId:          meta.ID,\n\t\t\tMetadata:    meta.Config.GetMetadata(),\n\t\t\tLabels:      meta.Config.GetLabels(),\n\t\t\tAnnotations: meta.Config.GetAnnotations(),\n\t\t},\n\t}\n\n\ttimestamp := time.Now()\n\n\tcpuStats, err := c.cpuContainerStats(*stats, timestamp)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to obtain cpu stats: %w\", err)\n\t}","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/containerd/containerd/blob/4246446a2bf7d03837b0244118d858799393bd80/internal/cri/server/sandbox_stats_linux.go#L38-L74","documentation":"decodeSandboxCgroupMetrics failed to parse the metrics returned by the controller into the expected cgroupMetrics structure. The controller responded, but the payload was empty, malformed, or in an unexpected schema version.","triggerScenarios":"decodeSandboxCgroupMetrics receives a *types.Metric that cannot be unmarshaled/mapped into cgroupMetrics (nil fields, cgroup v1 vs v2 field mismatches, truncated metrics blob).","commonSituations":"Mismatched containerd/shim versions producing differing metrics schemas; sandbox metrics returned before the cgroup is populated (all zeros/nil); custom shims emitting nonstandard metrics.","solutions":["Align containerd, shim, and runtime versions so the metrics schema matches what decodeSandboxCgroupMetrics expects","Log/dump the raw metric payload on failure to spot nil or unexpected fields","Check cgroup version (v1 vs v2) support on the host matches what the decoder anticipates","If the sandbox just started, retry once the cgroup is fully populated"],"exampleFix":"// before: decoding immediately after start\nmetric, _ := ctrl.Metrics(ctx, id)\nstats, err := decodeSandboxCgroupMetrics(metric) // fails on fresh sandbox\n// after: guard empty payload\nif metric == nil || metric.Data == nil { return nil, errdefs.ErrUnavailable }\nstats, err := decodeSandboxCgroupMetrics(metric)","handlingStrategy":"try-catch","validationCode":"// guard payload shape before decoding\nif metric == nil || metric.GetData() == nil {\n    return errdefs.ErrUnavailable // nothing to decode\n}","typeGuard":"func decodableMetric(m *types.Metric) bool {\n    return m != nil && m.Data != nil && len(m.Data) > 0\n}","tryCatchPattern":"stats, err := decodeSandboxCgroupMetrics(metric)\nif err != nil {\n    log.Printf(\"sandbox %s metrics undecodable (schema/version mismatch): %v\", sb.ID, err)\n    return nil // skip this sample rather than failing the pipeline\n}","preventionTips":["Pin matching containerd/shim/runtime versions so metrics schemas agree","Verify cgroup v1/v2 mode matches decoder expectations on every node","Log raw metrics payloads when decoding fails to diagnose schema drift","Skip-and-retry individual samples instead of aborting stats collection"],"tags":["cri","metrics","cgroup","decoding"],"backgroundTag":"metrics-decode-failed","analyzedSha":"4246446a2bf7d03837b0244118d858799393bd80","analyzedAt":"2026-09-02T00:14:43.053Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}