enhance: excessive disk usage logs generated if the path does not exist (#38822)

issue: #38820
pr: #38821

Signed-off-by: jaime <yun.zhang@zilliz.com>
pull/38932/head
jaime 2025-01-02 14:28:53 +08:00 committed by GitHub
parent 1d55ad6a1d
commit 5fb8313d6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -17,6 +17,8 @@ import (
"runtime"
"sync"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/errors/oserror"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/disk"
"github.com/shirou/gopsutil/v3/mem"
@ -107,6 +109,10 @@ func GetFreeMemoryCount() uint64 {
func GetDiskUsage(path string) (float64, float64, error) {
diskStats, err := disk.Usage(path)
if err != nil {
// If the path does not exist, ignore the error and return 0.
if errors.Is(err, oserror.ErrNotExist) {
return 0, 0, nil
}
return 0, 0, err
}
usedGB := float64(diskStats.Used) / 1e9

View File

@ -47,6 +47,11 @@ func TestGetDiskUsage(t *testing.T) {
assert.NoError(t, err)
assert.GreaterOrEqual(t, used, 0.0)
assert.GreaterOrEqual(t, total, 0.0)
used, total, err = GetDiskUsage("/dir_not_exist")
assert.NoError(t, err)
assert.Equal(t, 0.0, used)
assert.Equal(t, 0.0, total)
}
func TestGetIOWait(t *testing.T) {