From b293e4965d18e05cc39564f87b722c78d1d81a98 Mon Sep 17 00:00:00 2001 From: Harshal Patil Date: Wed, 3 May 2023 14:49:02 -0400 Subject: [PATCH] Request the pid of another container if current pid is not longer valid Signed-off-by: Harshal Patil Co-authored-by: Ryan Phillips --- container/crio/handler.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/container/crio/handler.go b/container/crio/handler.go index 9a06cac353..0885778565 100644 --- a/container/crio/handler.go +++ b/container/crio/handler.go @@ -305,14 +305,20 @@ func (h *crioContainerHandler) GetStats() (*info.ContainerStats, error) { if err != nil { return stats, err } - // Clean up stats for containers that don't have their own network - this - // includes containers running in Kubernetes pods that use the network of the - // infrastructure container. This stops metrics being reported multiple times - // for each container in a pod. + if !h.needNet() { + // Clean up stats for containers that don't have their own network - this + // includes containers running in Kubernetes pods that use the network of the + // infrastructure container. This stops metrics being reported multiple times + // for each container in a pod. stats.Network = info.NetworkStats{} + } else if len(stats.Network.Interfaces) == 0 { + // No network related information indicates that the pid of the + // container is not longer valid and we need to ask crio to + // provide the pid of another container from that pod + h.pidKnown = false + return stats, nil } - // Get filesystem stats. err = h.getFsStats(stats) if err != nil {