From 6288bb97125c8a25d79b87ffd3a597258fa4e0bc Mon Sep 17 00:00:00 2001 From: Daniel Canter Date: Tue, 22 Jun 2021 16:19:03 -0700 Subject: [PATCH] Get rid of redundant logs in HCN version range checks Kubeproxy logs are filled with redudnant version check spam from an unexported call that's invoked as part of checking if a feature is supported. The logs don't detail what feature(s) are even being checked so it just seems like spam. With the way things are implemented all of the hcn features are checked for support in any of the `hcn.XSupported()` calls not just the one being checked, so these logs come up quite a bit if there's many features that aren't supported on the machine. Add two new logs in a sync.Once that logs the HNS version and supported features. This should be enough to investigate version issues. Should remedy https://github.com/microsoft/hcsshim/issues/1043 Signed-off-by: Daniel Canter --- hcn/hcnsupport.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/hcn/hcnsupport.go b/hcn/hcnsupport.go index 033428f1c2..4be8df17db 100644 --- a/hcn/hcnsupport.go +++ b/hcn/hcnsupport.go @@ -1,9 +1,14 @@ package hcn import ( + "fmt" + "sync" + "github.com/sirupsen/logrus" ) +var versionOnce sync.Once + // SupportedFeatures are the features provided by the Service. type SupportedFeatures struct { Acl AclFeatures `json:"ACL"` @@ -76,6 +81,17 @@ func GetSupportedFeatures() SupportedFeatures { features.NetworkACL = isFeatureSupported(globals.Version, NetworkACLPolicyVersion) features.NestedIpSet = isFeatureSupported(globals.Version, NestedIpSetVersion) + // Only print the HCN version and features supported once, instead of everytime this is invoked. These logs are useful to + // debug incidents where there's confusion on if a feature is supported on the host machine. The sync.Once helps to avoid redundant + // spam of these anytime a check needs to be made for if an HCN feature is supported. This is a common occurrence in kubeproxy + // for example. + versionOnce.Do(func() { + logrus.WithFields(logrus.Fields{ + "version": fmt.Sprintf("%+v", globals.Version), + "supportedFeatures": fmt.Sprintf("%+v", features), + }).Info("HCN feature check") + }) + return features } @@ -91,19 +107,15 @@ func isFeatureSupported(currentVersion Version, versionsSupported VersionRanges) func isFeatureInRange(currentVersion Version, versionRange VersionRange) bool { if currentVersion.Major < versionRange.MinVersion.Major { - logrus.Infof("currentVersion.Major < versionRange.MinVersion.Major: %v, %v", currentVersion.Major, versionRange.MinVersion.Major) return false } if currentVersion.Major > versionRange.MaxVersion.Major { - logrus.Infof("currentVersion.Major > versionRange.MaxVersion.Major: %v, %v", currentVersion.Major, versionRange.MaxVersion.Major) return false } if currentVersion.Major == versionRange.MinVersion.Major && currentVersion.Minor < versionRange.MinVersion.Minor { - logrus.Infof("currentVersion.Minor < versionRange.MinVersion.Major: %v, %v", currentVersion.Minor, versionRange.MinVersion.Minor) return false } if currentVersion.Major == versionRange.MaxVersion.Major && currentVersion.Minor > versionRange.MaxVersion.Minor { - logrus.Infof("currentVersion.Minor > versionRange.MaxVersion.Major: %v, %v", currentVersion.Minor, versionRange.MaxVersion.Minor) return false } return true