Code change:
// getCadvisorPodInfoFromPodUID returns a pod cgroup information by matching the podUID with its CgroupName identifier base name func getCadvisorPodInfoFromPodUID(podUID types.UID, infos map[string]cadvisorapiv2.ContainerInfo) *cadvisorapiv2.ContainerInfo { <del> for key, info := range infos { if cm.IsSystemdStyleName(key) { // Convert to internal cgroup name and take the last component only. internalCgroupName := cm.ParseSystemdToCgroupName(key) key = internalCgroupName[len(internalCgroupName)-1] } else { // Take last component only. key = path.Base(key) } if cm.GetPodCgroupNameSuffix(podUID) == key { return &info } </del> <ins> if info, found := infos[cm.GetPodCgroupNameSuffix(podUID)]; found { return &info </ins> } return nil } <del> // removeTerminatedContainerInfo returns the specified containerInfo but with // the stats of the terminated containers removed. // </del> <ins> // filterTerminatedContainerInfoAndAssembleByPodCgroupKey returns the specified containerInfo but with // the stats of the terminated containers removed and all containerInfos assembled by pod cgroup key. // the first return map is container cgroup name <-> ContainerInfo and // the second return map is pod cgroup key <-> ContainerInfo. </ins> // A ContainerInfo is considered to be of a terminated container if it has an // older CreationTime and zero CPU instantaneous and memory RSS usage. <del> func removeTerminatedContainerInfo(containerInfo map[string]cadvisorapiv2.ContainerInfo) map[string]cadvisorapiv2.ContainerInfo { </del> <ins> func filterTerminatedContainerInfoAndAssembleByPodCgroupKey(containerInfo map[string]cadvisorapiv2.ContainerInfo) (map[string]cadvisorapiv2.ContainerInfo, map[string]cadvisorapiv2.ContainerInfo) { </ins> cinfoMap := make(map[containerID][]containerInfoWithCgroup) <ins> cinfosByPodCgroupKey := make(map[string]cadvisorapiv2.ContainerInfo) </ins> for key, cinfo := range containerInfo { <ins> var podCgroupKey string if cm.IsSystemdStyleName(key) { // Convert to internal cgroup name and take the last component only. internalCgroupName := cm.ParseSystemdToCgroupName(key) podCgroupKey = internalCgroupName[len(internalCgroupName)-1] } else { // Take last component only. podCgroupKey = path.Base(key) } cinfosByPodCgroupKey[podCgroupKey] = cinfo </ins> if !isPodManagedContainer(&cinfo) { continue }

Related discussion:
text: My initial thoughts are to use an enumeration which has two values KEYCGROUPPATH to provide backwards compatibility and KEYPODUID to enable fast lookups via podUID Refactor ListPodStats method to be more efficient in constructing the PodStats slice and taking into account the fast lookup via podUID I think this is the best approach instead of pushing the data structure implementation for the container info upstream to the cadviser clients, this will at least initially provide a better optimisation scoped within the kubelet/stats package and reduce other possible impacts to changing the cadvisor clients Please advise.
Just realized this looks like a duplicate issue and looking as fixed by PR Both this issue and were raised by Zac
/unassign
/close
You can't close an active issue/PR unless you authored it or you are a collaborator. <detailsIn response to : /close Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
Didn't think I could close this, leaving this with
this will be automatically closed once the PR merges