From 69c085d9faaf81ff6404f5d49f26233a16b0b2b6 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Fri, 26 May 2017 11:26:55 -0400 Subject: [PATCH] Cache the Docker thin pool name Cache the Docker thin pool name in the dockerFactory and pass it to each Docker container handler, instead of calling `docker info` each time a new container handler is created, as the thin pool name is extremely unlikely to change. --- container/docker/docker.go | 5 ++++- container/docker/factory.go | 11 ++++++++++- container/docker/handler.go | 14 ++++---------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/container/docker/docker.go b/container/docker/docker.go index 14c717a7..93d96c62 100644 --- a/container/docker/docker.go +++ b/container/docker/docker.go @@ -37,7 +37,10 @@ func Status() (v1.DockerStatus, error) { if err != nil { return v1.DockerStatus{}, err } + return StatusFromDockerInfo(dockerInfo), nil +} +func StatusFromDockerInfo(dockerInfo dockertypes.Info) v1.DockerStatus { out := v1.DockerStatus{} out.Version = VersionString() out.APIVersion = APIVersionString() @@ -53,7 +56,7 @@ func Status() (v1.DockerStatus, error) { for _, v := range dockerInfo.DriverStatus { out.DriverStatus[v[0]] = v[1] } - return out, nil + return out } func Images() ([]v1.DockerImage, error) { diff --git a/container/docker/factory.go b/container/docker/factory.go index 09d1d3aa..cc75f2a0 100644 --- a/container/docker/factory.go +++ b/container/docker/factory.go @@ -107,6 +107,7 @@ type dockerFactory struct { ignoreMetrics container.MetricSet + thinPoolName string thinPoolWatcher *devicemapper.ThinPoolWatcher zfsWatcher *zfs.ZfsWatcher @@ -136,6 +137,7 @@ func (self *dockerFactory) NewContainerHandler(name string, inHostNamespace bool metadataEnvs, self.dockerVersion, self.ignoreMetrics, + self.thinPoolName, self.thinPoolWatcher, self.zfsWatcher, ) @@ -323,12 +325,18 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c return fmt.Errorf("failed to get cgroup subsystems: %v", err) } - var thinPoolWatcher *devicemapper.ThinPoolWatcher + var ( + thinPoolWatcher *devicemapper.ThinPoolWatcher + thinPoolName string + ) if storageDriver(dockerInfo.Driver) == devicemapperStorageDriver { thinPoolWatcher, err = startThinPoolWatcher(dockerInfo) if err != nil { glog.Errorf("devicemapper filesystem stats will not be reported: %v", err) } + + status := StatusFromDockerInfo(*dockerInfo) + thinPoolName = status.DriverStatus[dockerutil.DriverStatusPoolName] } var zfsWatcher *zfs.ZfsWatcher @@ -350,6 +358,7 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c storageDriver: storageDriver(dockerInfo.Driver), storageDir: RootDir(), ignoreMetrics: ignoreMetrics, + thinPoolName: thinPoolName, thinPoolWatcher: thinPoolWatcher, zfsWatcher: zfsWatcher, } diff --git a/container/docker/handler.go b/container/docker/handler.go index 4a3db6f9..9cecc7bf 100644 --- a/container/docker/handler.go +++ b/container/docker/handler.go @@ -146,6 +146,7 @@ func newDockerContainerHandler( metadataEnvs []string, dockerVersion []int, ignoreMetrics container.MetricSet, + thinPoolName string, thinPoolWatcher *devicemapper.ThinPoolWatcher, zfsWatcher *zfs.ZfsWatcher, ) (container.ContainerHandler, error) { @@ -180,10 +181,10 @@ func newDockerContainerHandler( return nil, err } - // Determine the rootfs storage dir OR the pool name to determine the device + // Determine the rootfs storage dir OR the pool name to determine the device. + // For devicemapper, we only need the thin pool name, and that is passed in to this call var ( rootfsStorageDir string - poolName string zfsFilesystem string zfsParent string ) @@ -199,13 +200,6 @@ func newDockerContainerHandler( } zfsParent = status.DriverStatus[dockerutil.DriverStatusParentDataset] zfsFilesystem = path.Join(zfsParent, rwLayerID) - case devicemapperStorageDriver: - status, err := Status() - if err != nil { - return nil, fmt.Errorf("unable to determine docker status: %v", err) - } - - poolName = status.DriverStatus[dockerutil.DriverStatusPoolName] } // TODO: extract object mother method @@ -219,7 +213,7 @@ func newDockerContainerHandler( storageDriver: storageDriver, fsInfo: fsInfo, rootFs: rootFs, - poolName: poolName, + poolName: thinPoolName, zfsFilesystem: zfsFilesystem, rootfsStorageDir: rootfsStorageDir, envs: make(map[string]string),