Skip to content

Commit

Permalink
Merge pull request #97 from coroot/fix_cgroup_detection_on_service_init
Browse files Browse the repository at this point in the history
fix cgroup detection during systemd service initialization
  • Loading branch information
def committed Jun 13, 2024
2 parents 042e50b + 4c0f168 commit 7fbb8a7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cgroup/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ func NewFromProcessCgroupFile(filePath string) (*Cgroup, error) {
cg.subsystems[cgType] = path.Join(baseCgroupPath, parts[2])
}
}
if p := cg.subsystems["cpu"]; p != "" {
if p := cg.subsystems["name=systemd"]; p != "" {
cg.Id = p
cg.Version = V1
} else if p = cg.subsystems["cpu"]; p != "" {
cg.Id = p
cg.Version = V1
} else {
Expand Down
7 changes: 7 additions & 0 deletions cgroup/cgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func TestNewFromProcessCgroupFile(t *testing.T) {
assert.Equal(t, "73051af271105c07e1f493b34856a77e665e3b0b4fc72f76c807dfbffeb881bd", cg.ContainerId)
assert.Equal(t, ContainerTypeDocker, cg.ContainerType)

cg, err = NewFromProcessCgroupFile(path.Join("fixtures/proc/600/cgroup"))
assert.Nil(t, err)
assert.Equal(t, V1, cg.Version)
assert.Equal(t, "/system.slice/springboot.service", cg.Id)
assert.Equal(t, "/system.slice/springboot.service", cg.ContainerId)
assert.Equal(t, ContainerTypeSystemdService, cg.ContainerType)

baseCgroupPath = "/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podc83d0428_58af_41eb_8dba_b9e6eddffe7b.slice/docker-0e612005fd07e7f47e2cd07df99a2b4e909446814d71d0b5e4efc7159dd51252.scope"
defer func() {
baseCgroupPath = ""
Expand Down
11 changes: 11 additions & 0 deletions cgroup/fixtures/proc/600/cgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
11:freezer:/
10:blkio:/init.scope
9:hugetlb:/
8:memory:/init.scope
7:pids:/init.scope
6:devices:/init.scope
5:rdma:/
4:cpuset:/
3:net_cls,net_prio:/
2:cpu,cpuacct:/
1:name=systemd:/system.slice/springboot.service

0 comments on commit 7fbb8a7

Please sign in to comment.