Skip to content

cri: skip failed container instead of dropping entire sandbox metrics - #13896

Merged
mikebrow merged 1 commit into
containerd:mainfrom
dgrisonnet:fix-sandbox-metrics-return-nil
Aug 3, 2026
Merged

mikebrow merged 1 commit into
containerd:mainfrom
dgrisonnet:fix-sandbox-metrics-return-nil

Conversation

@dgrisonnet

@dgrisonnet dgrisonnet commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

In ListPodSandboxMetrics, when collectContainerMetrics fails for any
container in a sandbox, the goroutine uses return nil to handle the error.
This exits the goroutine entirely, so the sandbox's metrics (including
pod-level network metrics and any successfully collected container metrics)
are never appended to the response. The comments say "just log and continue"
but return nil does not continue the loop.

This causes entire pods to silently disappear from /metrics/cadvisor when
the kubelet uses the PodAndContainerStatsFromCRI feature gate. A single
container whose task is momentarily unavailable (e.g., during a restart)
drops all metrics for the pod.

This was observed in kubernetes/kubernetes#140786
where a CRI container metrics e2e test failed because all container-level
metrics were missing for the test pods.

The containerd.log
from the CI run shows 23 occurrences of this error, each one causing the
entire sandbox's metrics to be dropped:

Jul 31 17:53:39 containerd[1296]: level=error msg="failed to get container metrics, this is likely a transient error"
    containerid=f033200dbd4c error="failed to get task for container f033200dbd4c: no running task found:
    task f033200dbd4c not found" podsandboxid=02fb600b65eb

Jul 31 17:53:39 containerd[1296]: level=error msg="failed to get container metrics, this is likely a transient error"
    containerid=aca1b703f6ce error="failed to get task for container aca1b703f6ce: no running task found:
    task aca1b703f6ce not found" podsandboxid=92c225bdb4e5

Jul 31 17:54:25 containerd[1296]: level=error msg="failed to get container metrics, this is likely a transient error"
    containerid=c4a42ecea761 error="failed to get task for container c4a42ecea761: no running task found:
    container not created: not found" podsandboxid=9bb8daab77e6

Each of these errors triggers return nil, which exits the sandbox's
goroutine before appending sandboxMetrics to the response. The test
retried for 60 seconds and never saw the pods' metrics appear.

Full CI logs: pull-kubernetes-node-e2e-containerd-alpha-features #2083246937322033152

The fix replaces return nil with continue in the two affected error
cases (IsUnavailable/IsNotFound and default), so that individual
container failures skip only that container. The IsCanceled case is left
unchanged since cancellation should stop the goroutine.

Avoid dropping pod sandbox metrics when collecting metrics for an individual container fails

When collectContainerMetrics fails for a single container, the
goroutine was returning nil which exited the loop entirely. The
sandbox metrics, including pod-level network metrics and any
successfully collected container metrics, were never appended to
the response.

Replace return nil with continue so that individual container
failures only skip that container.

Signed-off-by: Damien Grisonnet <[email protected]>
Copilot AI review requested due to automatic review settings August 3, 2026 08:41
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Aug 3, 2026
@dgrisonnet

Copy link
Copy Markdown
Contributor Author

/cc @dims

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Not ready to approve

There are unresolved review items around errgroup context propagation for container metrics collection and adding regression test coverage for the fixed behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Fixes CRI ListPodSandboxMetrics so a transient failure collecting metrics for an individual container does not cause the entire sandbox’s metrics (pod-level + any successful container metrics) to be dropped, which prevents pods from disappearing from /metrics/cadvisor under PodAndContainerStatsFromCRI.

Changes:

  • Replace return nil with continue for per-container metrics collection errors (except IsCanceled) so collection proceeds for the rest of the sandbox.
  • Preserve cancellation behavior by still returning on errdefs.IsCanceled(err).
File summaries
File Description
internal/cri/server/list_pod_sandbox_metrics_linux.go Adjusts per-container error handling in sandbox metrics collection to avoid dropping whole-sandbox metrics on single-container failures.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@dims

dims commented Aug 3, 2026

Copy link
Copy Markdown
Member

cc @akhilerm @mikebrow

@mikebrow mikebrow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Aug 3, 2026
@dims
dims enabled auto-merge August 3, 2026 14:44
@dims
dims added this pull request to the merge queue Aug 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 3, 2026
@mikebrow
mikebrow added this pull request to the merge queue Aug 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 3, 2026
@mikebrow
mikebrow added this pull request to the merge queue Aug 3, 2026
Merged via the queue into containerd:main with commit 8c8b4a8 Aug 3, 2026
87 of 90 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Aug 3, 2026
@samuelkarp samuelkarp added impact/changelog area/cri Container Runtime Interface (CRI) and removed impact/changelog labels Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cri Container Runtime Interface (CRI) size/XS

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants