Skip to content

Commit 7fbb8a7

Browse files
authored
Merge pull request #97 from coroot/fix_cgroup_detection_on_service_init
fix cgroup detection during systemd service initialization
2 parents 042e50b + 4c0f168 commit 7fbb8a7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

cgroup/cgroup.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ func NewFromProcessCgroupFile(filePath string) (*Cgroup, error) {
105105
cg.subsystems[cgType] = path.Join(baseCgroupPath, parts[2])
106106
}
107107
}
108-
if p := cg.subsystems["cpu"]; p != "" {
108+
if p := cg.subsystems["name=systemd"]; p != "" {
109+
cg.Id = p
110+
cg.Version = V1
111+
} else if p = cg.subsystems["cpu"]; p != "" {
109112
cg.Id = p
110113
cg.Version = V1
111114
} else {

cgroup/cgroup_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ func TestNewFromProcessCgroupFile(t *testing.T) {
5555
assert.Equal(t, "73051af271105c07e1f493b34856a77e665e3b0b4fc72f76c807dfbffeb881bd", cg.ContainerId)
5656
assert.Equal(t, ContainerTypeDocker, cg.ContainerType)
5757

58+
cg, err = NewFromProcessCgroupFile(path.Join("fixtures/proc/600/cgroup"))
59+
assert.Nil(t, err)
60+
assert.Equal(t, V1, cg.Version)
61+
assert.Equal(t, "/system.slice/springboot.service", cg.Id)
62+
assert.Equal(t, "/system.slice/springboot.service", cg.ContainerId)
63+
assert.Equal(t, ContainerTypeSystemdService, cg.ContainerType)
64+
5865
baseCgroupPath = "/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podc83d0428_58af_41eb_8dba_b9e6eddffe7b.slice/docker-0e612005fd07e7f47e2cd07df99a2b4e909446814d71d0b5e4efc7159dd51252.scope"
5966
defer func() {
6067
baseCgroupPath = ""

cgroup/fixtures/proc/600/cgroup

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
11:freezer:/
2+
10:blkio:/init.scope
3+
9:hugetlb:/
4+
8:memory:/init.scope
5+
7:pids:/init.scope
6+
6:devices:/init.scope
7+
5:rdma:/
8+
4:cpuset:/
9+
3:net_cls,net_prio:/
10+
2:cpu,cpuacct:/
11+
1:name=systemd:/system.slice/springboot.service

0 commit comments

Comments
 (0)