Revert "Merge pull request #1503 from dashpole/configure_root_path"

Undo this commit
This reverts commit 719df516db, reversing
changes made to cae5bfaee6.
This commit is contained in:
David Ashpole 2016-10-19 13:47:01 -07:00
parent 719df516db
commit a9b9dbe6be
5 changed files with 11 additions and 25 deletions

View File

@ -27,7 +27,6 @@ import (
"time" "time"
"github.com/google/cadvisor/container" "github.com/google/cadvisor/container"
"github.com/google/cadvisor/fs"
cadvisorhttp "github.com/google/cadvisor/http" cadvisorhttp "github.com/google/cadvisor/http"
"github.com/google/cadvisor/manager" "github.com/google/cadvisor/manager"
"github.com/google/cadvisor/utils/sysfs" "github.com/google/cadvisor/utils/sysfs"
@ -125,7 +124,7 @@ func main() {
collectorHttpClient := createCollectorHttpClient(*collectorCert, *collectorKey) collectorHttpClient := createCollectorHttpClient(*collectorCert, *collectorKey)
containerManager, err := manager.New(memoryStorage, sysFs, *maxHousekeepingInterval, *allowDynamicHousekeeping, ignoreMetrics.MetricSet, &collectorHttpClient, fs.DefaultRootPath) containerManager, err := manager.New(memoryStorage, sysFs, *maxHousekeepingInterval, *allowDynamicHousekeeping, ignoreMetrics.MetricSet, &collectorHttpClient)
if err != nil { if err != nil {
glog.Fatalf("Failed to create a Container Manager: %s", err) glog.Fatalf("Failed to create a Container Manager: %s", err)
} }

View File

@ -43,7 +43,6 @@ const (
LabelSystemRoot = "root" LabelSystemRoot = "root"
LabelDockerImages = "docker-images" LabelDockerImages = "docker-images"
LabelRktImages = "rkt-images" LabelRktImages = "rkt-images"
DefaultRootPath = "/"
) )
// The maximum number of `du` and `find` tasks that can be running at once. // The maximum number of `du` and `find` tasks that can be running at once.
@ -88,8 +87,6 @@ type Context struct {
// docker root directory. // docker root directory.
Docker DockerContext Docker DockerContext
RktPath string RktPath string
// The "rootFs" filesystem is the filesystem that contains the RootPath
RootPath string
} }
type DockerContext struct { type DockerContext struct {
@ -118,15 +115,7 @@ func NewFsInfo(context Context) (FsInfo, error) {
fsInfo.addDockerImagesLabel(context, mounts) fsInfo.addDockerImagesLabel(context, mounts)
glog.Infof("Filesystem partitions: %+v", fsInfo.partitions) glog.Infof("Filesystem partitions: %+v", fsInfo.partitions)
rootDevice, err := fsInfo.GetDirFsDevice(context.RootPath) fsInfo.addSystemRootLabel(mounts)
if err != nil {
return nil, fmt.Errorf("error trying to get filesystem Device for rootPath %v: err: %v", context.RootPath, err)
}
rootMountpoint, err := fsInfo.GetMountpointForDevice(rootDevice.Device)
if err != nil {
return nil, fmt.Errorf("error trying to get MountPoint for Root Device: %v, err: %v", rootDevice, err)
}
fsInfo.addSystemRootLabel(rootMountpoint, mounts)
return fsInfo, nil return fsInfo, nil
} }
@ -198,10 +187,10 @@ func (self *RealFsInfo) getDockerDeviceMapperInfo(context DockerContext) (string
}, nil }, nil
} }
// addSystemRootLabel attempts to determine which device contains the mount for rootMountpoint. // addSystemRootLabel attempts to determine which device contains the mount for /.
func (self *RealFsInfo) addSystemRootLabel(rootMountpoint string, mounts []*mount.Info) { func (self *RealFsInfo) addSystemRootLabel(mounts []*mount.Info) {
for _, m := range mounts { for _, m := range mounts {
if m.Mountpoint == rootMountpoint { if m.Mountpoint == "/" {
self.partitions[m.Source] = partition{ self.partitions[m.Source] = partition{
fsType: m.Fstype, fsType: m.Fstype,
mountpoint: m.Mountpoint, mountpoint: m.Mountpoint,

View File

@ -88,7 +88,7 @@ func TestFileNotExist(t *testing.T) {
func TestDirDiskUsage(t *testing.T) { func TestDirDiskUsage(t *testing.T) {
as := assert.New(t) as := assert.New(t)
fsInfo, err := NewFsInfo(Context{RootPath: DefaultRootPath}) fsInfo, err := NewFsInfo(Context{})
as.NoError(err) as.NoError(err)
dir, err := ioutil.TempDir(os.TempDir(), "") dir, err := ioutil.TempDir(os.TempDir(), "")
as.NoError(err) as.NoError(err)
@ -108,7 +108,7 @@ func TestDirDiskUsage(t *testing.T) {
func TestDirInodeUsage(t *testing.T) { func TestDirInodeUsage(t *testing.T) {
as := assert.New(t) as := assert.New(t)
fsInfo, err := NewFsInfo(Context{RootPath: DefaultRootPath}) fsInfo, err := NewFsInfo(Context{})
as.NoError(err) as.NoError(err)
dir, err := ioutil.TempDir(os.TempDir(), "") dir, err := ioutil.TempDir(os.TempDir(), "")
as.NoError(err) as.NoError(err)
@ -199,7 +199,7 @@ func TestAddSystemRootLabel(t *testing.T) {
labels: map[string]string{}, labels: map[string]string{},
partitions: map[string]partition{}, partitions: map[string]partition{},
} }
fsInfo.addSystemRootLabel(DefaultRootPath, tt.mounts) fsInfo.addSystemRootLabel(tt.mounts)
if source, ok := fsInfo.labels[LabelSystemRoot]; !ok || source != tt.expected { if source, ok := fsInfo.labels[LabelSystemRoot]; !ok || source != tt.expected {
t.Errorf("case %d: expected mount source '%s', got '%s'", i, tt.expected, source) t.Errorf("case %d: expected mount source '%s', got '%s'", i, tt.expected, source)

View File

@ -127,7 +127,7 @@ type Manager interface {
} }
// New takes a memory storage and returns a new manager. // New takes a memory storage and returns a new manager.
func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingInterval time.Duration, allowDynamicHousekeeping bool, ignoreMetricsSet container.MetricSet, collectorHttpClient *http.Client, rootPath string) (Manager, error) { func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingInterval time.Duration, allowDynamicHousekeeping bool, ignoreMetricsSet container.MetricSet, collectorHttpClient *http.Client) (Manager, error) {
if memoryCache == nil { if memoryCache == nil {
return nil, fmt.Errorf("manager requires memory storage") return nil, fmt.Errorf("manager requires memory storage")
} }
@ -154,8 +154,7 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn
Driver: dockerStatus.Driver, Driver: dockerStatus.Driver,
DriverStatus: dockerStatus.DriverStatus, DriverStatus: dockerStatus.DriverStatus,
}, },
RktPath: rktPath, RktPath: rktPath,
RootPath: rootPath,
} }
fsInfo, err := fs.NewFsInfo(context) fsInfo, err := fs.NewFsInfo(context)
if err != nil { if err != nil {

View File

@ -30,7 +30,6 @@ import (
"github.com/google/cadvisor/container" "github.com/google/cadvisor/container"
"github.com/google/cadvisor/container/docker" "github.com/google/cadvisor/container/docker"
containertest "github.com/google/cadvisor/container/testing" containertest "github.com/google/cadvisor/container/testing"
"github.com/google/cadvisor/fs"
info "github.com/google/cadvisor/info/v1" info "github.com/google/cadvisor/info/v1"
itest "github.com/google/cadvisor/info/v1/test" itest "github.com/google/cadvisor/info/v1/test"
"github.com/google/cadvisor/info/v2" "github.com/google/cadvisor/info/v2"
@ -301,7 +300,7 @@ func TestDockerContainersInfo(t *testing.T) {
} }
func TestNewNilManager(t *testing.T) { func TestNewNilManager(t *testing.T) {
_, err := New(nil, nil, 60*time.Second, true, container.MetricSet{}, http.DefaultClient, fs.DefaultRootPath) _, err := New(nil, nil, 60*time.Second, true, container.MetricSet{}, http.DefaultClient)
if err == nil { if err == nil {
t.Fatalf("Expected nil manager to return error") t.Fatalf("Expected nil manager to return error")
} }