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

server/status: silence missing CPU cgroup error #118657

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions pkg/server/status/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,7 @@ func (rsr *RuntimeStatSampler) SampleEnvironment(
if err != nil {
log.Ops.Errorf(ctx, "unable to get process CPU usage: %v", err)
}
cpuCapacity, err := getCPUCapacity()
if err != nil {
log.Ops.Errorf(ctx, "unable to get CPU capacity: %v", err)
}
cpuCapacity := getCPUCapacity()
cpuUsageStats, err := cpu.Times(false /* percpu */)
if err != nil {
log.Ops.Errorf(ctx, "unable to get system CPU usage: %v", err)
Expand Down Expand Up @@ -842,19 +839,20 @@ func GetProcCPUTime(ctx context.Context) (userTimeMillis, sysTimeMillis int64, e
// getCPUCapacity returns the number of logical CPU processors available for
// use by the process. The capacity accounts for cgroup constraints, GOMAXPROCS
// and the number of host processors.
func getCPUCapacity() (float64, error) {
func getCPUCapacity() float64 {
numProcs := float64(runtime.GOMAXPROCS(0 /* read only */))
cgroupCPU, err := cgroups.GetCgroupCPU()
if err != nil {
// Return the GOMAXPROCS value if unable to read the cgroup settings, in
// practice this is not likely to occur.
return numProcs, err
// Return the GOMAXPROCS value if unable to read the cgroup settings. This
// can happen if cockroach is not running inside a CPU cgroup, which is a
// supported deployment mode. We could log here, but we don't to avoid spam.
return numProcs
}
cpuShare := cgroupCPU.CPUShares()
// Take the minimum of the CPU shares and the GOMAXPROCS value. The most CPU
// the process could use is the lesser of the two.
if cpuShare > numProcs {
return numProcs, nil
return numProcs
}
return cpuShare, nil
return cpuShare
}