Skip to content

Commit

Permalink
Get rid of redundant logs in HCN version range checks
Browse files Browse the repository at this point in the history
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 #1043

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
  • Loading branch information
dcantah committed Jun 24, 2021
1 parent 9bc76cd commit e895133
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions hcn/hcnsupport.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package hcn

import (
"sync"

"github.com/sirupsen/logrus"
)

var versionOnce sync.Once

// SupportedFeatures are the features provided by the Service.
type SupportedFeatures struct {
Acl AclFeatures `json:"ACL"`
Expand All @@ -24,6 +28,32 @@ type SupportedFeatures struct {
NestedIpSet bool `json:"NestedIpSet"`
}

// Returns a logrus.Fields structure with all of the supported features.
func (sf SupportedFeatures) featuresToFields() logrus.Fields {
return logrus.Fields{
"AclAddressLists": sf.Acl.AclAddressLists,
"AclNoHostRulePriority": sf.Acl.AclNoHostRulePriority,
"AclPortRanges": sf.Acl.AclPortRanges,
"AclRuleId": sf.Acl.AclRuleId,
"ApiV2": sf.Api.V2,
"ApiV1": sf.Api.V2,
"RemoteSubnet": sf.RemoteSubnet,
"HostRoute": sf.HostRoute,
"DSR": sf.DSR,
"Slash32EndpointPrefixes": sf.Slash32EndpointPrefixes,
"AclSupportForProtocol252": sf.AclSupportForProtocol252,
"SessionAffinity": sf.SessionAffinity,
"IPv6DualStack": sf.IPv6DualStack,
"SetPolicy": sf.SetPolicy,
"VxlanPort": sf.VxlanPort,
"L4Proxy": sf.L4Proxy,
"L4WfpProxy": sf.L4WfpProxy,
"TierAcl": sf.TierAcl,
"NetworkACL": sf.NetworkACL,
"NestedIpSet": sf.NestedIpSet,
}
}

// AclFeatures are the supported ACL possibilities.
type AclFeatures struct {
AclAddressLists bool `json:"AclAddressLists"`
Expand Down Expand Up @@ -76,6 +106,18 @@ func GetSupportedFeatures() SupportedFeatures {
features.NetworkACL = isFeatureSupported(globals.Version, NetworkACLPolicyVersion)
features.NestedIpSet = isFeatureSupported(globals.Version, NestedIpSetVersion)

// Only print the HNS 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 HNS feature is supported. This is a common occurrence in kubeproxy
// for example.
versionOnce.Do(func() {
logrus.WithFields(logrus.Fields{
"Major": globals.Version.Major,
"Minor": globals.Version.Minor,
}).Infof("HNS version")
logrus.WithFields(features.featuresToFields()).Infof("Supported HNS features")
})

return features
}

Expand All @@ -91,19 +133,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
Expand Down

0 comments on commit e895133

Please sign in to comment.