elastic / elastic-agent-system-metrics

Apache License 2.0
0 stars 22 forks source link

`SubsystemMountpoints()` can return wong V2 path for non-root container environments #139

Closed fearful-symmetry closed 2 months ago

fearful-symmetry commented 2 months ago

Right now, SubsystemMountpoints() will calculate the V2 mountpoint by iterating through /proc/self/mountpoints and and updating the V2Loc as it finds it in the file, ending with the last result. Problem is, some mountpoints files look like this:

1682 1681 0:26 / /sys/fs/cgroup ro,nosuid,nodev,noexec,relatime - cgroup2 cgroup rw,seclabel
1718 1686 0:26 / /hostfs/sys/fs/cgroup rw,nosuid,nodev,noexec,relatime master:4 - cgroup2 cgroup2 rw,seclabel
1771 1770 0:26 / /hostfs/var/lib/docker/overlay2/1b570230fa3ec3679e354b0c219757c739f91d774ebc02174106488606549da0/merged/sys/fs/cgroup ro,nosuid,nodev,noexec,relatime - cgroup2 cgroup rw,seclabel

In this case, the last mountpoint is /hostfs/var/lib/docker/overlay2/1b570230fa3ec3679e354b0c219757c739f91d774ebc02174106488606549da0/merged/sys/fs/cgroup

Problem is, this is a docker overlayfs path, and if the container is running as non-root --user=whomever, then we can't read from this file.

The hostfs path works fine:

cat /hostfs/sys/fs/cgroup/user.slice/user-1000.slice/session-1763.scope/io.pressure 
some avg10=0.00 avg60=0.00 avg300=0.00 total=2256657
full avg10=0.00 avg60=0.00 avg300=0.00 total=1667639