Skip to content

fix(container): Improve container ID detection using deepest cgroup path match for nested containerIDs in cgroup path #2119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vimalk78
Copy link
Collaborator

@vimalk78 vimalk78 commented Jun 1, 2025

This PR improves container ID detection using deepest cgroup path match for nested containerIDs in cgroup path, typical in kind cluster.

If multiple container IDs are found within a single cgroup path, the changed function prioritizes the one appearing furthest to the right or "deepest" in the path string.

e.g. for a pod created in kind cluster, the cgroup path for the process running in pod is typically like below:

0::/system.slice/docker-fd9d0ea06257a9780827cbc7fd92e3812a54fca26d63e191b73610d5d48b9cbd.scope/kubelet.slice/kubelet-kubepods.slice/kubelet-kubepods-besteffort.slice/kubelet-kubepods-besteffort-podeab5a334_93fe_48a8_b139_9e8079c1f163.slice/cri-containerd-99f3a16ea25b7724cb56a4f0c0df1113ad9474fbf5545bead97fd5c7f61c13f4.scope

the first container (docker) refers to the kind node
the second container (cri-containerd) refers to the container running as part of the pod

this commit will return the second container id

@vimalk78 vimalk78 requested a review from sthaha June 1, 2025 12:36
@github-actions github-actions bot added fix A bug fix chore Routine tasks or maintenance labels Jun 1, 2025
Copy link

codecov bot commented Jun 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.56%. Comparing base (0131d23) to head (c46f84f).
Report is 6 commits behind head on reboot.

Additional details and impacted files
@@            Coverage Diff             @@
##           reboot    #2119      +/-   ##
==========================================
- Coverage   92.63%   92.56%   -0.08%     
==========================================
  Files          33       33              
  Lines        2553     2582      +29     
==========================================
+ Hits         2365     2390      +25     
- Misses        149      152       +3     
- Partials       39       40       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vimalk78 vimalk78 force-pushed the containerID-for-kind branch from dc1a471 to c537458 Compare June 1, 2025 12:38
@sthaha
Copy link
Collaborator

sthaha commented Jun 2, 2025

Thanks a lot @vimalk78 ! lgtm but CI is failing.

Question. if we want the deepest scope, how about we separate each segment by / and regex match each segment in reverse order?

go.mod Outdated
Comment on lines 3 to 5
go 1.23

toolchain go1.23.3
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! wondering if you ran go mod tidy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

@vprashar2929 vprashar2929 removed the chore Routine tasks or maintenance label Jun 2, 2025
@vimalk78 vimalk78 force-pushed the containerID-for-kind branch from c537458 to 5d355d0 Compare June 2, 2025 06:13
@vimalk78
Copy link
Collaborator Author

vimalk78 commented Jun 2, 2025

/retest

…match

  If multiple container IDs are found within a single cgroup path, the changed function prioritizes the one appearing furthest to the right or "deepest" in the path string.

  e.g. for a pod created in kind cluster, the cgroup path for the process running in pod is typically like below:
  0::/system.slice/docker-fd9d0ea06257a9780827cbc7fd92e3812a54fca26d63e191b73610d5d48b9cbd.scope/kubelet.slice/kubelet-kubepods.slice/kubelet-kubepods-besteffort.slice/kubelet-kubepods-besteffort-podeab5a334_93fe_48a8_b139_9e8079c1f163.slice/cri-containerd-99f3a16ea25b7724cb56a4f0c0df1113ad9474fbf5545bead97fd5c7f61c13f4.scope
  the first container (docker) refers to the kind node
  the second container (cri-containerd) refers to the container running as part of the pod

  this commit will return the second container id.

Signed-off-by: Vimal Kumar <[email protected]>
@vimalk78 vimalk78 force-pushed the containerID-for-kind branch from 5d355d0 to c46f84f Compare June 2, 2025 06:45
@sthaha sthaha merged commit 32d60d5 into sustainable-computing-io:reboot Jun 2, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix A bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants