Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Adding logging verbosity levels for pkg/cloud/services/loadbalancer/loadbalancer.go #1636

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions pkg/cloud/services/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const loadBalancerProvisioningStatusActive = "ACTIVE"

func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackCluster, clusterName string, apiServerPort int) (bool, error) {
loadBalancerName := getLoadBalancerName(clusterName)
s.scope.Logger().Info("Reconciling load balancer", "name", loadBalancerName)
s.scope.Logger().V(3).Info("Reconciling load balancer", "name", loadBalancerName)

var fixedIPAddress string
switch {
Expand Down Expand Up @@ -169,7 +169,7 @@ func (s *Service) getOrCreateLoadBalancer(openStackCluster *infrav1.OpenStackClu
return lb, nil
}

s.scope.Logger().Info(fmt.Sprintf("Creating load balancer in subnet: %q", subnetID), "name", loadBalancerName)
s.scope.Logger().V(2).Info("Creating load balancer in subnet", "subnetID", subnetID, "name", loadBalancerName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be just "id" here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But subnet is not the main subject of the message, load balancer is. Hence, no prefixes for load balancer, and "subnetID" for subnet. That was my logic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. We should also update the documentation with the upstream links we used, plus any supplemental conventions we've decided on such as this.


lbCreateOpts := loadbalancers.CreateOpts{
Name: loadBalancerName,
Expand Down Expand Up @@ -199,7 +199,7 @@ func (s *Service) getOrCreateListener(openStackCluster *infrav1.OpenStackCluster
return listener, nil
}

s.scope.Logger().Info("Creating load balancer listener", "name", listenerName, "lb-id", lbID)
s.scope.Logger().V(2).Info("Creating load balancer listener", "name", listenerName, "loadBalancerID", lbID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just "id" here too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same logic here. Load balancer is not the main subject


listenerCreateOpts := listeners.CreateOpts{
Name: listenerName,
Expand Down Expand Up @@ -267,7 +267,7 @@ func (s *Service) getOrUpdateAllowedCIDRS(openStackCluster *infrav1.OpenStackClu
listener.AllowedCIDRs = capostrings.Unique(listener.AllowedCIDRs)

if !reflect.DeepEqual(allowedCIDRs, listener.AllowedCIDRs) {
s.scope.Logger().Info("CIDRs do not match, start to update listener", "expected CIDRs", allowedCIDRs, "load balancer existing CIDR", listener.AllowedCIDRs)
s.scope.Logger().V(3).Info("CIDRs do not match, updating listener", "expectedCIDRs", allowedCIDRs, "currentCIDRs", listener.AllowedCIDRs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If V(2) informs about changes in the system, it's reasonable this should be V(2) too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it important or useful enough to be V(2)? Seems like something that the system does on its own without impacting the user much

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @dulek here. This branch is making an OpenStack API call and reconfiguring the listener (see line 275). This should probably log at V(2).

listenerUpdateOpts := listeners.UpdateOpts{
AllowedCIDRs: &allowedCIDRs,
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func (s *Service) getOrCreatePool(openStackCluster *infrav1.OpenStackCluster, po
return pool, nil
}

s.scope.Logger().Info(fmt.Sprintf("Creating load balancer pool for listener %q", listenerID), "name", poolName, "lb-id", lbID)
s.scope.Logger().V(2).Info("Creating load balancer pool for listener", "loadBalancerID", lbID, "listenerID", listenerID, "name", poolName)

method := pools.LBMethodRoundRobin

Expand Down Expand Up @@ -356,7 +356,7 @@ func (s *Service) getOrCreateMonitor(openStackCluster *infrav1.OpenStackCluster,
return nil
}

s.scope.Logger().Info(fmt.Sprintf("Creating load balancer monitor for pool %q", poolID), "name", monitorName, "lb-id", lbID)
s.scope.Logger().V(2).Info("Creating load balancer monitor for pool", "loadBalancerID", lbID, "name", monitorName, "poolID", poolID)

monitorCreateOpts := monitors.CreateOpts{
Name: monitorName,
Expand Down Expand Up @@ -400,7 +400,7 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac
}

loadBalancerName := getLoadBalancerName(clusterName)
s.scope.Logger().Info("Reconciling load balancer member", "name", loadBalancerName)
s.scope.Logger().V(3).Info("Reconciling load balancer member", "loadBalancerName", loadBalancerName)

lbID := openStackCluster.Status.APIServerLoadBalancer.ID
portList := []int{int(openStackCluster.Spec.ControlPlaneEndpoint.Port)}
Expand Down Expand Up @@ -429,7 +429,7 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac
continue
}

s.scope.Logger().Info("Deleting load balancer member (because the IP of the machine changed)", "name", name)
s.scope.Logger().V(2).Info("Deleting load balancer member because the IP of the machine changed", "name", name)

// lb member changed so let's delete it so we can create it again with the correct IP
err = s.waitForLoadBalancerActive(lbID)
Expand All @@ -445,7 +445,7 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac
}
}

s.scope.Logger().Info("Creating load balancer member", "name", name)
s.scope.Logger().V(2).Info("Creating load balancer member", "name", name)

// if we got to this point we should either create or re-create the lb member
lbMemberOpts := pools.CreateMemberOpts{
Expand Down Expand Up @@ -500,7 +500,7 @@ func (s *Service) DeleteLoadBalancer(openStackCluster *infrav1.OpenStackCluster,
deleteOpts := loadbalancers.DeleteOpts{
Cascade: true,
}
s.scope.Logger().Info("Deleting load balancer", "name", loadBalancerName, "cascade", deleteOpts.Cascade)
s.scope.Logger().V(2).Info("Deleting load balancer", "name", loadBalancerName, "cascade", deleteOpts.Cascade)
err = s.loadbalancerClient.DeleteLoadBalancer(lb.ID, deleteOpts)
if err != nil && !capoerrors.IsNotFound(err) {
record.Warnf(openStackCluster, "FailedDeleteLoadBalancer", "Failed to delete load balancer %s with id %s: %v", lb.Name, lb.ID, err)
Expand Down Expand Up @@ -539,7 +539,7 @@ func (s *Service) DeleteLoadBalancerMember(openStackCluster *infrav1.OpenStackCl
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dulek Not related this this PR, but this looks pretty janky. Does this need an issue to track it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably just make a call and ignore 404's? Is this what you mean here?

if pool == nil {
s.scope.Logger().Info("Load balancer pool does not exist", "name", lbPortObjectsName)
s.scope.Logger().V(4).Info("Load balancer pool does not exist", "name", lbPortObjectsName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V(4) looks correct to me, but I'm interested to know what @dulek thinks. I don't know this code super well: would it be 'normal' for the lb pool to not exist, i.e. an expected state of affairs, even if only briefly? If so, V(4) is appropriate. If it would be unusual then perhaps V(3) would be more appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, you're right, in this context the pool not existing at all is pretty unusual.

continue
}

Expand Down Expand Up @@ -634,7 +634,7 @@ var backoff = wait.Backoff{

// Possible LoadBalancer states are documented here: https://docs.openstack.org/api-ref/load-balancer/v2/index.html#prov-status
func (s *Service) waitForLoadBalancerActive(id string) error {
s.scope.Logger().Info("Waiting for load balancer", "id", id, "targetStatus", "ACTIVE")
s.scope.Logger().V(3).Info("Waiting for load balancer", "id", id, "targetStatus", "ACTIVE")
return wait.ExponentialBackoff(backoff, func() (bool, error) {
lb, err := s.loadbalancerClient.GetLoadBalancer(id)
if err != nil {
Expand All @@ -645,7 +645,7 @@ func (s *Service) waitForLoadBalancerActive(id string) error {
}

func (s *Service) waitForListener(id, target string) error {
s.scope.Logger().Info("Waiting for load balancer listener", "id", id, "targetStatus", target)
s.scope.Logger().V(3).Info("Waiting for load balancer listener", "id", id, "targetStatus", target)
return wait.ExponentialBackoff(backoff, func() (bool, error) {
_, err := s.loadbalancerClient.GetListener(id)
if err != nil {
Expand Down