Skip to content

Commit

Permalink
Improve debug logging around instance group management
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarygerard committed Aug 31, 2023
1 parent cbc8f49 commit 0ee532a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions providers/gce/gce_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ func splitNodesByZone(nodes []*v1.Node) map[string][]*v1.Node {
return zones
}

func getZone(n *v1.Node) string {
zone, ok := n.Labels[v1.LabelFailureDomainBetaZone]
func getZone(node *v1.Node) string {
zone, ok := node.Labels[v1.LabelFailureDomainBetaZone]
if !ok {
klog.Warningf("Node without zone label, returning %q as zone. Node name: %v, node labels: %v", defaultZone, node.Name, node.Labels)
return defaultZone
}
return zone
Expand Down
2 changes: 1 addition & 1 deletion providers/gce/gce_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (g *Cloud) UpdateLoadBalancer(ctx context.Context, clusterName string, svc
}
}

klog.V(4).Infof("UpdateLoadBalancer(%v, %v, %v, %v, %v): updating with %d nodes", clusterName, svc.Namespace, svc.Name, loadBalancerName, g.region, len(nodes))
klog.V(4).Infof("UpdateLoadBalancer(%v, %v, %v, %v, %v): updating with %v nodes [node names limited, total number of nodes: %d]", clusterName, svc.Namespace, svc.Name, loadBalancerName, g.region, loggableNodeNames(nodes), len(nodes))

switch scheme {
case cloud.SchemeInternal:
Expand Down
10 changes: 9 additions & 1 deletion providers/gce/gce_loadbalancer_external.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import (
)

const (
errStrLbNoHosts = "cannot EnsureLoadBalancer() with no hosts"
errStrLbNoHosts = "cannot EnsureLoadBalancer() with no hosts"
maxNodeNamesToLog = 50
)

// ensureExternalLoadBalancer is the external implementation of LoadBalancer.EnsureLoadBalancer.
Expand Down Expand Up @@ -819,6 +820,13 @@ func nodeNames(nodes []*v1.Node) []string {
return ret
}

func loggableNodeNames(nodes []*v1.Node) []string {
if len(nodes) > maxNodeNamesToLog {
return nodeNames(nodes[:maxNodeNamesToLog])
}
return nodeNames(nodes)
}

func hostURLToComparablePath(hostURL string) string {
idx := strings.Index(hostURL, "/zones/")
if idx < 0 {
Expand Down
2 changes: 1 addition & 1 deletion providers/gce/gce_loadbalancer_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func (g *Cloud) ensureInternalHealthCheck(name string, svcName types.NamespacedN
}

func (g *Cloud) ensureInternalInstanceGroup(name, zone string, nodes []*v1.Node) (string, error) {
klog.V(2).Infof("ensureInternalInstanceGroup(%v, %v): checking group that it contains %v nodes", name, zone, len(nodes))
klog.V(2).Infof("ensureInternalInstanceGroup(%v, %v): checking group that it contains %v nodes [node names limited, total number of nodes: %d]", name, zone, loggableNodeNames(nodes), len(nodes))
ig, err := g.GetInstanceGroup(name, zone)
if err != nil && !isNotFound(err) {
return "", err
Expand Down

0 comments on commit 0ee532a

Please sign in to comment.