Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgroup: improve test to find cgroup compatibility issues #41347

Merged
merged 10 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion util/cgroup/cgroup_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/pingcap/errors"
)

var errNoCPUControllerDetected = errors.New("no cpu controller detected")

// Helper function for getCgroupCPU. Root is always "/", except in tests.
func getCgroupCPU(root string) (CPUUsage, error) {
path, err := detectControlPath(filepath.Join(root, procPathCGroup), "cpu,cpuacct")
Expand All @@ -30,7 +32,7 @@ func getCgroupCPU(root string) (CPUUsage, error) {

// No CPU controller detected
if path == "" {
return CPUUsage{}, errors.New("no cpu controller detected")
return CPUUsage{}, errNoCPUControllerDetected
}

mount, ver, err := getCgroupDetails(filepath.Join(root, procPathMountInfo), path, "cpu,cpuacct")
Expand Down
10 changes: 7 additions & 3 deletions util/cgroup/cgroup_cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ func TestGetCgroupCPU(t *testing.T) {
}()
}
cpu, err := GetCgroupCPU()
require.NoError(t, err)
require.NotZero(t, cpu.Period)
require.Less(t, int64(1), cpu.Period)
if err == errNoCPUControllerDetected {
require.False(t, InContainer(), "Please check linux version > v4.7.x. This is related to cgroup compatibility.")
} else {
require.NoError(t, err)
require.NotZero(t, cpu.Period)
require.Less(t, int64(1), cpu.Period)
}
close(exit)
wg.Wait()
}