From f4f3b0d0737b9ae4e0181d53dfffca19340a59ed Mon Sep 17 00:00:00 2001 From: Nikolay Sivko Date: Tue, 1 Oct 2024 15:15:43 +0300 Subject: [PATCH] remove `ipsByNs` cache --- containers/container.go | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/containers/container.go b/containers/container.go index 86121ad..cb85971 100644 --- a/containers/container.go +++ b/containers/container.go @@ -119,7 +119,6 @@ type Container struct { delaysLock sync.Mutex listens map[netaddr.IPPort]map[uint32]*ListenDetails - ipsByNs map[string][]netaddr.IP connectsSuccessful map[AddrPair]*ConnectionStats // dst:actual_dst -> count connectsFailed map[netaddr.IPPort]int64 // dst -> count @@ -164,7 +163,6 @@ func NewContainer(id ContainerID, cg *cgroup.Cgroup, md *ContainerMetadata, host delaysByPid: map[uint32]Delays{}, listens: map[netaddr.IPPort]map[uint32]*ListenDetails{}, - ipsByNs: map[string][]netaddr.IP{}, connectsSuccessful: map[AddrPair]*ConnectionStats{}, connectsFailed: map[netaddr.IPPort]int64{}, @@ -486,16 +484,12 @@ func (c *Container) onListenOpen(pid uint32, addr netaddr.IPPort, safe bool) { return } defer ns.Close() - nsId := ns.UniqueId() - ips, ok := c.ipsByNs[nsId] - if !ok { - if ips, err = proc.GetNsIps(ns); err != nil { - klog.Warningln(err) - } else { - klog.Infof("got IPs %s for %s", ips, nsId) - c.ipsByNs[nsId] = ips - } + ips, err := proc.GetNsIps(ns) + if err != nil { + klog.Warningln(err) + return } + klog.Infof("got IPs %s for %s", ips, ns.UniqueId()) details.NsIPs = ips } } @@ -1024,12 +1018,6 @@ func (c *Container) gc(now time.Time) { seenNamespaces[p.NetNsId()] = true } - for ns := range c.ipsByNs { - if !seenNamespaces[ns] { - delete(c.ipsByNs, ns) - } - } - c.revalidateListens(now, listens) for srcDst, conn := range c.connectionsActive {