From 5420d84160aa95cbcee5add60995acd54559a17c Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Fri, 30 Aug 2019 10:31:03 -0700 Subject: [PATCH] update cAdvisor godeps to v0.34.0 release --- go.mod | 4 +- go.sum | 4 +- .../google/cadvisor/container/crio/handler.go | 41 ++++++++++++++++++- .../google/cadvisor/container/raw/factory.go | 1 + .../google/cadvisor/container/raw/handler.go | 3 ++ vendor/modules.txt | 2 +- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index c242c498f95..ef6116c5cfb 100644 --- a/go.mod +++ b/go.mod @@ -66,7 +66,7 @@ require ( github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903 github.com/golang/mock v1.2.0 github.com/golang/protobuf v1.3.1 - github.com/google/cadvisor v0.33.2-0.20190719172907-9fa3b1429966 + github.com/google/cadvisor v0.34.0 github.com/google/certificate-transparency-go v1.0.21 // indirect github.com/google/go-cmp v0.3.0 github.com/google/gofuzz v1.0.0 @@ -282,7 +282,7 @@ replace ( github.com/golangplus/fmt => github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995 github.com/golangplus/testing => github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e github.com/google/btree => github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c - github.com/google/cadvisor => github.com/google/cadvisor v0.33.2-0.20190719172907-9fa3b1429966 + github.com/google/cadvisor => github.com/google/cadvisor v0.34.0 github.com/google/certificate-transparency-go => github.com/google/certificate-transparency-go v1.0.21 github.com/google/go-cmp => github.com/google/go-cmp v0.3.0 github.com/google/gofuzz => github.com/google/gofuzz v1.0.0 diff --git a/go.sum b/go.sum index 16d5831543e..1c7ce756be0 100644 --- a/go.sum +++ b/go.sum @@ -200,8 +200,8 @@ github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e h1:KhcknUwkWHKZ github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/cadvisor v0.33.2-0.20190719172907-9fa3b1429966 h1:8PpCh6R0YjmmztPXOq9aKhiUqLGUrp6Fly3vWk7l2Fg= -github.com/google/cadvisor v0.33.2-0.20190719172907-9fa3b1429966/go.mod h1:1nql6U13uTHaLYB8rLS5x9IJc2qT6Xd/Tr1sTX6NE48= +github.com/google/cadvisor v0.34.0 h1:No7G6U/TasplR9uNqyc5Jj0Bet5VSYsK5xLygOf4pUw= +github.com/google/cadvisor v0.34.0/go.mod h1:1nql6U13uTHaLYB8rLS5x9IJc2qT6Xd/Tr1sTX6NE48= github.com/google/certificate-transparency-go v1.0.21 h1:Yf1aXowfZ2nuboBsg7iYGLmwsOARdV86pfH3g95wXmE= github.com/google/certificate-transparency-go v1.0.21/go.mod h1:QeJfpSbVSfYc7RgB3gJFj9cbuQMMchQxrWXz8Ruopmg= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= diff --git a/vendor/github.com/google/cadvisor/container/crio/handler.go b/vendor/github.com/google/cadvisor/container/crio/handler.go index 4078474fef1..d9eab06ee76 100644 --- a/vendor/github.com/google/cadvisor/container/crio/handler.go +++ b/vendor/github.com/google/cadvisor/container/crio/handler.go @@ -33,6 +33,9 @@ import ( ) type crioContainerHandler struct { + client crioClient + name string + machineInfoFactory info.MachineInfoFactory // Absolute path to the cgroup hierarchies of this container. @@ -68,6 +71,9 @@ type crioContainerHandler struct { reference info.ContainerReference libcontainerHandler *containerlibcontainer.Handler + cgroupManager *cgroupfs.Manager + rootFs string + pidKnown bool } var _ container.ContainerHandler = &crioContainerHandler{} @@ -103,11 +109,20 @@ func newCrioContainerHandler( } id := ContainerNameToCrioId(name) + pidKnown := true cInfo, err := client.ContainerInfo(id) if err != nil { return nil, err } + if cInfo.Pid == 0 { + // If pid is not known yet, network related stats can not be retrieved by the + // libcontainer handler GetStats(). In this case, the crio handler GetStats() + // will reattempt to get the pid and, if now known, will construct the libcontainer + // handler. This libcontainer handler is then cached and reused without additional + // calls to crio. + pidKnown = false + } // passed to fs handler below ... // XXX: this is using the full container logpath, as constructed by the CRI @@ -142,6 +157,8 @@ func newCrioContainerHandler( // TODO: extract object mother method handler := &crioContainerHandler{ + client: client, + name: name, machineInfoFactory: machineInfoFactory, cgroupPaths: cgroupPaths, storageDriver: storageDriver, @@ -152,6 +169,9 @@ func newCrioContainerHandler( includedMetrics: includedMetrics, reference: containerReference, libcontainerHandler: libcontainerHandler, + cgroupManager: cgroupManager, + rootFs: rootFs, + pidKnown: pidKnown, } handler.image = cInfo.Image @@ -263,8 +283,27 @@ func (self *crioContainerHandler) getFsStats(stats *info.ContainerStats) error { return nil } +func (self *crioContainerHandler) getLibcontainerHandler() *containerlibcontainer.Handler { + if self.pidKnown { + return self.libcontainerHandler + } + + id := ContainerNameToCrioId(self.name) + + cInfo, err := self.client.ContainerInfo(id) + if err != nil || cInfo.Pid == 0 { + return self.libcontainerHandler + } + + self.pidKnown = true + self.libcontainerHandler = containerlibcontainer.NewHandler(self.cgroupManager, self.rootFs, cInfo.Pid, self.includedMetrics) + + return self.libcontainerHandler +} + func (self *crioContainerHandler) GetStats() (*info.ContainerStats, error) { - stats, err := self.libcontainerHandler.GetStats() + libcontainerHandler := self.getLibcontainerHandler() + stats, err := libcontainerHandler.GetStats() if err != nil { return stats, err } diff --git a/vendor/github.com/google/cadvisor/container/raw/factory.go b/vendor/github.com/google/cadvisor/container/raw/factory.go index cd913d2834b..d843bc8f941 100644 --- a/vendor/github.com/google/cadvisor/container/raw/factory.go +++ b/vendor/github.com/google/cadvisor/container/raw/factory.go @@ -30,6 +30,7 @@ import ( ) var dockerOnly = flag.Bool("docker_only", false, "Only report docker containers in addition to root stats") +var disableRootCgroupStats = flag.Bool("disable_root_cgroup_stats", false, "Disable collecting root Cgroup stats") type rawFactory struct { // Factory for machine information. diff --git a/vendor/github.com/google/cadvisor/container/raw/handler.go b/vendor/github.com/google/cadvisor/container/raw/handler.go index b80f8d2d8e8..ea7ec486451 100644 --- a/vendor/github.com/google/cadvisor/container/raw/handler.go +++ b/vendor/github.com/google/cadvisor/container/raw/handler.go @@ -227,6 +227,9 @@ func (self *rawContainerHandler) getFsStats(stats *info.ContainerStats) error { } func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) { + if *disableRootCgroupStats && isRootCgroup(self.name) { + return nil, nil + } stats, err := self.libcontainerHandler.GetStats() if err != nil { return stats, err diff --git a/vendor/modules.txt b/vendor/modules.txt index 13402be8302..01df8a89083 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -435,7 +435,7 @@ github.com/golang/protobuf/ptypes/timestamp github.com/golang/protobuf/ptypes/wrappers # github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c => github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c github.com/google/btree -# github.com/google/cadvisor v0.33.2-0.20190719172907-9fa3b1429966 => github.com/google/cadvisor v0.33.2-0.20190719172907-9fa3b1429966 +# github.com/google/cadvisor v0.34.0 => github.com/google/cadvisor v0.34.0 github.com/google/cadvisor/accelerators github.com/google/cadvisor/cache/memory github.com/google/cadvisor/client/v2