From ede9e0a15588b0ca3f85c3cf8a1b8eb7e739315f Mon Sep 17 00:00:00 2001 From: Povilas Versockas Date: Mon, 6 Feb 2023 21:03:53 +0200 Subject: [PATCH] [memorylimiter] Fix cgroups parsing (#6825) --- .chloggen/fix-memory-limiter.yaml | 16 ++++++++++++++++ internal/cgroups/cgroups.go | 4 +++- internal/cgroups/testdata/proc/cgroups/mountinfo | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 .chloggen/fix-memory-limiter.yaml diff --git a/.chloggen/fix-memory-limiter.yaml b/.chloggen/fix-memory-limiter.yaml new file mode 100755 index 000000000000..3254fa7e34d4 --- /dev/null +++ b/.chloggen/fix-memory-limiter.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: memorylimiterprocessor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Fix incorrect parsing of cgroups when running Collector with host mount" + +# One or more tracking issues or pull requests related to the change +issues: [6826] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/internal/cgroups/cgroups.go b/internal/cgroups/cgroups.go index ed9e46104ae4..37eaaacc0b7b 100644 --- a/internal/cgroups/cgroups.go +++ b/internal/cgroups/cgroups.go @@ -104,7 +104,9 @@ func NewCGroups(procPathMountInfo, procPathCGroup string) (CGroups, error) { if err != nil { return err } - cgroups[opt] = NewCGroup(cgroupPath) + if strings.HasPrefix(cgroupPath, "/sys") { + cgroups[opt] = NewCGroup(cgroupPath) + } } return nil diff --git a/internal/cgroups/testdata/proc/cgroups/mountinfo b/internal/cgroups/testdata/proc/cgroups/mountinfo index e68af08a5763..a3caa8b760b3 100644 --- a/internal/cgroups/testdata/proc/cgroups/mountinfo +++ b/internal/cgroups/testdata/proc/cgroups/mountinfo @@ -6,3 +6,5 @@ 6 5 0:5 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:6 - cgroup cgroup rw,cpuset 7 5 0:6 /docker /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:7 - cgroup cgroup rw,cpu,cpuacct 8 5 0:7 /docker /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:8 - cgroup cgroup rw,memory +9 1 0:8 / /var/lib/docker/overlay2/9054a95f2cf7296867089e1bd37931742a17eb3308a795d51adb2654ee2276df/merged/sys/fs/cgroup ro,nosuid,nodev,noexec,relatime - tmpfs tmpfs rw,mode=755 +10 9 0:9 /docker /var/lib/docker/overlay2/9054a95f2cf7296867089e1bd37931742a17eb3308a795d51adb2654ee2276df/merged/sys/fs/cgroup/memory ro,nosuid,nodev,noexec,relatime master:17 - cgroup cgroup rw,memory