Skip to content

Commit 6288bb9

Browse files
committed
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 microsoft#1043 Signed-off-by: Daniel Canter <[email protected]>
1 parent 9bc76cd commit 6288bb9

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

hcn/hcnsupport.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package hcn
22

33
import (
4+
"fmt"
5+
"sync"
6+
47
"github.com/sirupsen/logrus"
58
)
69

10+
var versionOnce sync.Once
11+
712
// SupportedFeatures are the features provided by the Service.
813
type SupportedFeatures struct {
914
Acl AclFeatures `json:"ACL"`
@@ -76,6 +81,17 @@ func GetSupportedFeatures() SupportedFeatures {
7681
features.NetworkACL = isFeatureSupported(globals.Version, NetworkACLPolicyVersion)
7782
features.NestedIpSet = isFeatureSupported(globals.Version, NestedIpSetVersion)
7883

84+
// Only print the HCN version and features supported once, instead of everytime this is invoked. These logs are useful to
85+
// debug incidents where there's confusion on if a feature is supported on the host machine. The sync.Once helps to avoid redundant
86+
// spam of these anytime a check needs to be made for if an HCN feature is supported. This is a common occurrence in kubeproxy
87+
// for example.
88+
versionOnce.Do(func() {
89+
logrus.WithFields(logrus.Fields{
90+
"version": fmt.Sprintf("%+v", globals.Version),
91+
"supportedFeatures": fmt.Sprintf("%+v", features),
92+
}).Info("HCN feature check")
93+
})
94+
7995
return features
8096
}
8197

@@ -91,19 +107,15 @@ func isFeatureSupported(currentVersion Version, versionsSupported VersionRanges)
91107

92108
func isFeatureInRange(currentVersion Version, versionRange VersionRange) bool {
93109
if currentVersion.Major < versionRange.MinVersion.Major {
94-
logrus.Infof("currentVersion.Major < versionRange.MinVersion.Major: %v, %v", currentVersion.Major, versionRange.MinVersion.Major)
95110
return false
96111
}
97112
if currentVersion.Major > versionRange.MaxVersion.Major {
98-
logrus.Infof("currentVersion.Major > versionRange.MaxVersion.Major: %v, %v", currentVersion.Major, versionRange.MaxVersion.Major)
99113
return false
100114
}
101115
if currentVersion.Major == versionRange.MinVersion.Major && currentVersion.Minor < versionRange.MinVersion.Minor {
102-
logrus.Infof("currentVersion.Minor < versionRange.MinVersion.Major: %v, %v", currentVersion.Minor, versionRange.MinVersion.Minor)
103116
return false
104117
}
105118
if currentVersion.Major == versionRange.MaxVersion.Major && currentVersion.Minor > versionRange.MaxVersion.Minor {
106-
logrus.Infof("currentVersion.Minor > versionRange.MaxVersion.Major: %v, %v", currentVersion.Minor, versionRange.MaxVersion.Minor)
107119
return false
108120
}
109121
return true

0 commit comments

Comments
 (0)