From 63dd200e7e47261454c7e55fed2ad972144e147f Mon Sep 17 00:00:00 2001 From: haircommander Date: Wed, 22 Aug 2018 13:13:07 -0400 Subject: Changed GetContainerStats to return ErrCtrStateInvalid This results in some functionality changes: If a ErrCtrStateInvalid is returned to GetPodStats, the container is ommitted from the stats. As such, if an empty slice of Container stats are returned to GetPodStats in varlink, an error will occur. GetContainerStats will return the ErrCtrStateInvalid as well. Finally, if ErrCtrStateInvalid is returned to the podman stats call, the container will be ommitted from the stats. Signed-off-by: haircommander Closes: #1319 Approved by: baude --- libpod/pod.go | 9 +++++++-- libpod/pod_ffjson.go | 2 +- libpod/stats.go | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'libpod') diff --git a/libpod/pod.go b/libpod/pod.go index e5d491e52..666480aa8 100644 --- a/libpod/pod.go +++ b/libpod/pod.go @@ -4,6 +4,7 @@ import ( "time" "github.com/containers/storage" + "github.com/pkg/errors" ) // Pod represents a group of containers that are managed together. @@ -192,10 +193,14 @@ func (p *Pod) GetPodStats(previousContainerStats map[string]*ContainerStats) (ma prevStat = &ContainerStats{} } newStats, err := c.GetContainerStats(prevStat) - if err != nil { + // If the container wasn't running, don't include it + // but also suppress the error + if err != nil && errors.Cause(err) != ErrCtrStateInvalid { return nil, err } - newContainerStats[c.ID()] = newStats + if err == nil { + newContainerStats[c.ID()] = newStats + } } return newContainerStats, nil } diff --git a/libpod/pod_ffjson.go b/libpod/pod_ffjson.go index a74c91ccc..36b1cf08f 100644 --- a/libpod/pod_ffjson.go +++ b/libpod/pod_ffjson.go @@ -1,5 +1,5 @@ // Code generated by ffjson . DO NOT EDIT. -// source: libpod/pod.go +// source: /home/pehunt/go/src/github.com/containers/libpod/libpod/pod.go package libpod diff --git a/libpod/stats.go b/libpod/stats.go index 61e85ed5e..9d5efd993 100644 --- a/libpod/stats.go +++ b/libpod/stats.go @@ -26,7 +26,7 @@ func (c *Container) GetContainerStats(previousStats *ContainerStats) (*Container } if c.state.State != ContainerStateRunning { - return stats, nil + return stats, ErrCtrStateInvalid } cgroupPath, err := c.CGroupPath() -- cgit v1.2.3-54-g00ecf