Use non-root available space to trigger out-of-disk events.

This commit is contained in:
Rohit Jnagal 2015-05-13 05:46:03 +00:00
parent ec19d41b63
commit 7a2add5e0a
2 changed files with 21 additions and 16 deletions

View File

@ -48,6 +48,7 @@ type DiskSpacePolicy struct {
type fsInfo struct {
Usage int64
Capacity int64
Available int64
Timestamp time.Time
}
@ -77,6 +78,7 @@ func (dm *realDiskSpaceManager) getFsInfo(fsType string, f func() (cadvisorApi.F
fsi.Timestamp = time.Now()
fsi.Usage = int64(fs.Usage)
fsi.Capacity = int64(fs.Capacity)
fsi.Available = int64(fs.Available)
dm.cachedInfo[fsType] = fsi
}
return fsi, nil
@ -99,17 +101,16 @@ func (dm *realDiskSpaceManager) isSpaceAvailable(fsType string, threshold int, f
return true, fmt.Errorf("failed to get fs info for %q: %v", fsType, err)
}
if fsInfo.Capacity == 0 {
return true, fmt.Errorf("could not determine capacity for %q fs.", fsType)
return true, fmt.Errorf("could not determine capacity for %q fs. Info: %+v", fsType, fsInfo)
}
free := fsInfo.Capacity - fsInfo.Usage
if free < 0 {
return true, fmt.Errorf("wrong fs usage for %q: capacity %d, usage %d", fsType, fsInfo.Capacity, fsInfo.Usage)
if fsInfo.Available < 0 {
return true, fmt.Errorf("wrong available space for %q: %+v", fsType, fsInfo)
}
const mb = int64(1024 * 1024)
if free < int64(threshold)*mb {
glog.Infof("Running out of space on disk for %q: free %d MB, threshold %d MB", fsType, free/mb, threshold)
if fsInfo.Available < int64(threshold)*mb {
glog.Infof("Running out of space on disk for %q: available %d MB, threshold %d MB", fsType, fsInfo.Available/mb, threshold)
return false, nil
}
return true, nil

View File

@ -81,15 +81,17 @@ func testRootFsAvailable(t *testing.T) {
require.NoError(t, err)
const mb = 1024 * 1024
// 500MB free
// 500MB available
mockCadvisor.On("DockerImagesFsInfo").Return(cadvisorApi.FsInfo{
Usage: 9500 * mb,
Capacity: 10000 * mb,
Usage: 9500 * mb,
Capacity: 10000 * mb,
Available: 500 * mb,
}, nil)
// 10MB free
// 10MB available
mockCadvisor.On("RootFsInfo").Return(cadvisorApi.FsInfo{
Usage: 990 * mb,
Capacity: 1000 * mb,
Usage: 990 * mb,
Capacity: 1000 * mb,
Available: 10 * mb,
}, nil)
ok, err := dm.IsDockerDiskSpaceAvailable()
require.NoError(t, err)
@ -124,12 +126,14 @@ func testCache(t *testing.T) {
require.NoError(t, err)
const mb = 1024 * 1024
mockCadvisor.On("DockerImagesFsInfo").Return(cadvisorApi.FsInfo{
Usage: 400 * mb,
Capacity: 1000 * mb,
Usage: 400 * mb,
Capacity: 1000 * mb,
Available: 300 * mb,
}, nil).Once()
mockCadvisor.On("RootFsInfo").Return(cadvisorApi.FsInfo{
Usage: 9 * mb,
Capacity: 10 * mb,
Usage: 9 * mb,
Capacity: 10 * mb,
Available: 500,
}, nil).Once()
ok, err := dm.IsDockerDiskSpaceAvailable()
ok, err = dm.IsRootDiskSpaceAvailable()