Repository navigation
cri: skip failed container instead of dropping entire sandbox metrics - #13896
Conversation
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]>
|
/cc @dims |
There was a problem hiding this comment.
🟡 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 nilwithcontinuefor per-container metrics collection errors (exceptIsCanceled) 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.
In
ListPodSandboxMetrics, whencollectContainerMetricsfails for anycontainer in a sandbox, the goroutine uses
return nilto 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 nildoes not continue the loop.This causes entire pods to silently disappear from
/metrics/cadvisorwhenthe kubelet uses the
PodAndContainerStatsFromCRIfeature gate. A singlecontainer 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:
Each of these errors triggers
return nil, which exits the sandbox'sgoroutine before appending
sandboxMetricsto the response. The testretried 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 nilwithcontinuein the two affected errorcases (
IsUnavailable/IsNotFoundanddefault), so that individualcontainer failures skip only that container. The
IsCanceledcase is leftunchanged since cancellation should stop the goroutine.