Browse Source

libnetwork/iptables: reduce DeleteConntrackEntriesXX debug logs

Both functions were generating debug logs if there was nothing to log.
The function already produces logs if things failed while deleting entries,
so these logs would only be printed if there was nothing to delete, so can
safely be discarded.

Before this change:

    DEBU[2023-08-14T12:33:23.082052638Z] Revoking external connectivity on endpoint sweet_swirles (1519f9376a3abe7a1c981600c25e8df6bbd0a3bc3a074f1c2b3bcbad0438443b)
    DEBU[2023-08-14T12:33:23.085782847Z] DeleteConntrackEntries purged ipv4:0, ipv6:0
    DEBU[2023-08-14T12:33:23.085793847Z] DeleteConntrackEntriesByPort for udp ports purged ipv4:0, ipv6:0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 year ago
parent
commit
f1240393d9
1 changed files with 8 additions and 2 deletions
  1. 8 2
      libnetwork/iptables/conntrack.go

+ 8 - 2
libnetwork/iptables/conntrack.go

@@ -50,7 +50,10 @@ func DeleteConntrackEntries(nlh *netlink.Handle, ipv4List []net.IP, ipv6List []n
 		totalIPv6FlowPurged += flowPurged
 	}
 
-	log.G(context.TODO()).Debugf("DeleteConntrackEntries purged ipv4:%d, ipv6:%d", totalIPv4FlowPurged, totalIPv6FlowPurged)
+	if totalIPv4FlowPurged > 0 || totalIPv6FlowPurged > 0 {
+		log.G(context.TODO()).Debugf("DeleteConntrackEntries purged ipv4:%d, ipv6:%d", totalIPv4FlowPurged, totalIPv6FlowPurged)
+	}
+
 	return totalIPv4FlowPurged, totalIPv6FlowPurged, nil
 }
 
@@ -86,7 +89,10 @@ func DeleteConntrackEntriesByPort(nlh *netlink.Handle, proto types.Protocol, por
 		totalIPv6FlowPurged += v6FlowPurged
 	}
 
-	log.G(context.TODO()).Debugf("DeleteConntrackEntriesByPort for %s ports purged ipv4:%d, ipv6:%d", proto.String(), totalIPv4FlowPurged, totalIPv6FlowPurged)
+	if totalIPv4FlowPurged > 0 || totalIPv6FlowPurged > 0 {
+		log.G(context.TODO()).Debugf("DeleteConntrackEntriesByPort for %s ports purged ipv4:%d, ipv6:%d", proto.String(), totalIPv4FlowPurged, totalIPv6FlowPurged)
+	}
+
 	return nil
 }