Skip to content

Commit 3204dd7

Browse files
aledbfroboquat
authored andcommitted
[ws-daemon] Remove warning when cpu.stat does not exists
1 parent aabbe61 commit 3204dd7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

components/ws-daemon/pkg/cpulimit/cfs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package cpulimit
66

77
import (
88
"bufio"
9+
"errors"
10+
"io/fs"
911
"math"
1012
"os"
1113
"path/filepath"
@@ -123,6 +125,10 @@ func (basePath CgroupV1CFSController) readCpuUsage() (time.Duration, error) {
123125
func (basePath CgroupV1CFSController) NrThrottled() (uint64, error) {
124126
f, err := os.Open(filepath.Join(string(basePath), "cpu.stat"))
125127
if err != nil {
128+
if errors.Is(err, fs.ErrNotExist) {
129+
return 0, nil
130+
}
131+
126132
return 0, xerrors.Errorf("cannot read cpu.stat: %w", err)
127133
}
128134
defer f.Close()

components/ws-daemon/pkg/cpulimit/cfs_v2.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package cpulimit
66

77
import (
88
"bufio"
9+
"errors"
10+
"io/fs"
911
"math"
1012
"os"
1113
"path/filepath"
@@ -104,6 +106,10 @@ func (basePath CgroupV2CFSController) readParentQuota() time.Duration {
104106
func (basePath CgroupV2CFSController) getFlatKeyedValue(key string) (int64, error) {
105107
stats, err := os.Open(filepath.Join(string(basePath), "cpu.stat"))
106108
if err != nil {
109+
if errors.Is(err, fs.ErrNotExist) {
110+
return 0, nil
111+
}
112+
107113
return 0, xerrors.Errorf("cannot read cpu.stat: %w", err)
108114
}
109115
defer stats.Close()

0 commit comments

Comments
 (0)