From 8955c1a0668a7c7e49944a32c158005732a4bb05 Mon Sep 17 00:00:00 2001 From: Sohan Kunkerkar Date: Thu, 22 Aug 2024 14:26:13 -0400 Subject: [PATCH] container/crio: fix network metrics collection logic This change modifies the logic for gathering network metrics in the CRI-O handler to ensure that metrics are collected from all containers. Since all containers share the same network namespace, it is crucial to gather metrics from every container to account for scenarios where the infra container may have empty network metrics. Signed-off-by: Sohan Kunkerkar --- container/crio/handler.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/container/crio/handler.go b/container/crio/handler.go index a68325187e..90f86829dc 100644 --- a/container/crio/handler.go +++ b/container/crio/handler.go @@ -148,13 +148,13 @@ func newCrioContainerHandler( Namespace: CrioNamespace, } - // Find out if we need network metrics reported for this container. - // Containers that don't have their own network -- this includes - // containers running in Kubernetes pods that use the network of the - // infrastructure container -- does not need their stats to be - // reported. This stops metrics being reported multiple times for each - // container in a pod. - metrics := common.RemoveNetMetrics(includedMetrics, cInfo.Labels["io.kubernetes.container.name"] != "POD") + // In a Kubernetes pod, all containers share the same network namespace. + // If the infrastructure container has empty network metrics, the CRI-O + // handler uses a running container in the pod to gather the necessary + // metrics. Therefore, it is essential to collect network metrics from + // all containers to ensure that if there is any running container in + // the pod, we capture the required network metrics for accurate reporting. + metrics := includedMetrics libcontainerHandler := containerlibcontainer.NewHandler(cgroupManager, rootFs, cInfo.Pid, metrics)