DataDog / datadog-go

go dogstatsd client library for datadog
MIT License
353 stars 132 forks source link

Try to detect the container ID from `/proc/self/mountinfo` #268

Closed L3n41c closed 1 year ago

L3n41c commented 2 years ago

The DSD golang library is already able to auto-detect the container ID of the running process by inspecting /proc/self/cgroup. Unfortunately, this technique stopped working with cgroup v2 which comes with cgroup namespace. If the running process runs in a non-host cgroup namespace, its visible /proc/self/cgroup will not contain the container ID. This PR implements an alternative way of finding the container ID in /proc/self/mountinfo.

If we’re using cgroup V1, we can still use the /proc/self/cgroup-based logic. If we’re in the host cgroup namespace, we can still use the /proc/self/cgroup-based logic. Otherwise, let’s make a try with /proc/self/mountinfo.

This PR replicates in the DSD golang client library the logic that has been introduced in DataDog/datadog-agent#14045.