Merge pull request #75 from vmarmol/fix-stats
Ignore stats that are not available
This commit is contained in:
commit
8e3130d7fd
|
@ -7,6 +7,7 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/libcontainer/cgroups"
|
||||
)
|
||||
|
@ -65,6 +66,9 @@ func getBlkioStat(path string) ([]cgroups.BlkioStatEntry, error) {
|
|||
var blkioStats []cgroups.BlkioStatEntry
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
if pathErr, ok := err.(*os.PathError); ok && pathErr.Err == syscall.ENOENT {
|
||||
return blkioStats, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
|
|
@ -86,8 +86,8 @@ func TestBlkioStatsNoSectorsFile(t *testing.T) {
|
|||
|
||||
blkio := &blkioGroup{}
|
||||
err := blkio.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected to fail, but did not")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed unexpectedly: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,8 +102,8 @@ func TestBlkioStatsNoServiceBytesFile(t *testing.T) {
|
|||
|
||||
blkio := &blkioGroup{}
|
||||
err := blkio.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected to fail, but did not")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed unexpectedly: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,8 +118,8 @@ func TestBlkioStatsNoServicedFile(t *testing.T) {
|
|||
|
||||
blkio := &blkioGroup{}
|
||||
err := blkio.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected to fail, but did not")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed unexpectedly: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,8 +134,8 @@ func TestBlkioStatsNoQueuedFile(t *testing.T) {
|
|||
|
||||
blkio := &blkioGroup{}
|
||||
err := blkio.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected to fail, but did not")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed unexpectedly: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/libcontainer/cgroups"
|
||||
)
|
||||
|
@ -60,6 +61,9 @@ func (s *memoryGroup) GetStats(d *data, stats *cgroups.Stats) error {
|
|||
// Set stats from memory.stat.
|
||||
statsFile, err := os.Open(filepath.Join(path, "memory.stat"))
|
||||
if err != nil {
|
||||
if pathErr, ok := err.(*os.PathError); ok && pathErr.Err == syscall.ENOENT {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
defer statsFile.Close()
|
||||
|
|
|
@ -43,8 +43,8 @@ func TestMemoryStatsNoStatFile(t *testing.T) {
|
|||
|
||||
memory := &memoryGroup{}
|
||||
err := memory.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected failure")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue