Merge pull request #2284 from sjenning/crio-retry-get-pid
container/crio: retry getting pid if 0
This commit is contained in:
commit
6ecc74d278
@ -33,6 +33,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type crioContainerHandler struct {
|
type crioContainerHandler struct {
|
||||||
|
client crioClient
|
||||||
|
name string
|
||||||
|
|
||||||
machineInfoFactory info.MachineInfoFactory
|
machineInfoFactory info.MachineInfoFactory
|
||||||
|
|
||||||
// Absolute path to the cgroup hierarchies of this container.
|
// Absolute path to the cgroup hierarchies of this container.
|
||||||
@ -68,6 +71,9 @@ type crioContainerHandler struct {
|
|||||||
reference info.ContainerReference
|
reference info.ContainerReference
|
||||||
|
|
||||||
libcontainerHandler *containerlibcontainer.Handler
|
libcontainerHandler *containerlibcontainer.Handler
|
||||||
|
cgroupManager *cgroupfs.Manager
|
||||||
|
rootFs string
|
||||||
|
pidKnown bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ container.ContainerHandler = &crioContainerHandler{}
|
var _ container.ContainerHandler = &crioContainerHandler{}
|
||||||
@ -103,11 +109,20 @@ func newCrioContainerHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
id := ContainerNameToCrioId(name)
|
id := ContainerNameToCrioId(name)
|
||||||
|
pidKnown := true
|
||||||
|
|
||||||
cInfo, err := client.ContainerInfo(id)
|
cInfo, err := client.ContainerInfo(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 ...
|
// passed to fs handler below ...
|
||||||
// XXX: this is using the full container logpath, as constructed by the CRI
|
// XXX: this is using the full container logpath, as constructed by the CRI
|
||||||
@ -142,6 +157,8 @@ func newCrioContainerHandler(
|
|||||||
|
|
||||||
// TODO: extract object mother method
|
// TODO: extract object mother method
|
||||||
handler := &crioContainerHandler{
|
handler := &crioContainerHandler{
|
||||||
|
client: client,
|
||||||
|
name: name,
|
||||||
machineInfoFactory: machineInfoFactory,
|
machineInfoFactory: machineInfoFactory,
|
||||||
cgroupPaths: cgroupPaths,
|
cgroupPaths: cgroupPaths,
|
||||||
storageDriver: storageDriver,
|
storageDriver: storageDriver,
|
||||||
@ -152,6 +169,9 @@ func newCrioContainerHandler(
|
|||||||
includedMetrics: includedMetrics,
|
includedMetrics: includedMetrics,
|
||||||
reference: containerReference,
|
reference: containerReference,
|
||||||
libcontainerHandler: libcontainerHandler,
|
libcontainerHandler: libcontainerHandler,
|
||||||
|
cgroupManager: cgroupManager,
|
||||||
|
rootFs: rootFs,
|
||||||
|
pidKnown: pidKnown,
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.image = cInfo.Image
|
handler.image = cInfo.Image
|
||||||
@ -263,8 +283,27 @@ func (self *crioContainerHandler) getFsStats(stats *info.ContainerStats) error {
|
|||||||
return nil
|
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) {
|
func (self *crioContainerHandler) GetStats() (*info.ContainerStats, error) {
|
||||||
stats, err := self.libcontainerHandler.GetStats()
|
libcontainerHandler := self.getLibcontainerHandler()
|
||||||
|
stats, err := libcontainerHandler.GetStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stats, err
|
return stats, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user