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

🌱 Migrating /pkg/cloud/services/loadbalancer/loadbalancer.go and /controllers/openstackmachine_controller.go to structured logging #1621

Merged
merged 1 commit into from
Aug 16, 2023

Conversation

asarunova
Copy link

@asarunova asarunova commented Jul 24, 2023

What this PR does / why we need it:
It fixes the format of the log messages and log parameters. Following the guidelines here and here. Part of the process to fix issue #1314.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 24, 2023
@netlify
Copy link

netlify bot commented Jul 24, 2023

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
🔨 Latest commit 6915c37
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/64d2ad2af5b4f50008bb11f7
😎 Deploy Preview https://deploy-preview-1621--kubernetes-sigs-cluster-api-openstack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot
Copy link
Contributor

Hi @anastaruno. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 24, 2023
@mdbooth
Copy link
Contributor

mdbooth commented Jul 25, 2023

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 25, 2023
@@ -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().Info("Reconciling load balancer", "loadBalancerName", loadBalancerName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets hold off on this change until we have agreement in #1617 (comment)

I suspect that we may decide we're going to stick with name here.

@mdbooth
Copy link
Contributor

mdbooth commented Jul 25, 2023

This is fun: you have a test failure!
image

If you click on details you'll see it's a linter failure:

pkg/cloud/services/loadbalancer/loadbalancer.go:657: File is not `gci`-ed with --skip-generated -s standard,default (gci)

Honestly I still haven't worked out exactly what 'gci'-ed means, but in this case I'm guessing it's referring to the lack of a newline at the end of the file. Normally it's complaining about the ordering of imports, but not today!

If you want to run the linter tests locally you can do make lint, which should give you the same error. You can fix it manually, but frequently you can fix it automatically by running the linter in update mode. In this repo you can do that with make lint-update.

@asarunova asarunova changed the title 🌱 Migrating /pkg/cloud/services/loadbalancer/loadbalancer.go to structured logging 🌱 Migrating /pkg/cloud/services/loadbalancer/loadbalancer.go and /controllers/openstackmachine_controller.go to structured logging Jul 25, 2023
@asarunova asarunova requested a review from mdbooth July 25, 2023 20:00
@@ -169,7 +169,7 @@ func (s *Service) getOrCreateLoadBalancer(openStackCluster *infrav1.OpenStackClu
return lb, nil
}

s.scope.Logger().Info("Creating load balancer in subnet", "subnetID", subnetID, "loadBalancerName", loadBalancerName)
s.scope.Logger().Info("Creating load balancer in subnet", "id", 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 is tricky! I think we have to prefix at least one of id and name here, as they refer to different objects. Which one is honestly debatable, but I might argue that the 'subject' of the log message is the load balancer, therefore name and subnetID.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree! Subnet is a secondary resource here.

@@ -199,7 +199,7 @@ func (s *Service) getOrCreateListener(openStackCluster *infrav1.OpenStackCluster
return listener, nil
}

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

Choose a reason for hiding this comment

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

2 objects again. I'm thinking name and loadBalancerID.

@@ -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().Info("CIDRs do not match, start to update listener", "expected CIDRs", allowedCIDRs, "existing CIDR", 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.

This is basically a trace level log message. When we get around to it, I'm pretty sure we'll put this at V(5). However...

I'm not 100% sure, but I don't think we want spaces in parameter names. Perhaps expected and current?

We also probably want ..., updating listener.

And lastly: are you able to find out how allowedCIDRs renders in this log message in practise? I wonder if we should explicitly format it somehow. However, don't spend much time on this given that it's most likely a trace level log.

@@ -316,7 +316,7 @@ func (s *Service) getOrCreatePool(openStackCluster *infrav1.OpenStackCluster, po
return pool, nil
}

s.scope.Logger().Info("Creating load balancer pool for listener", "listenerID", listenerID, "poolName", poolName, "loadBalancerID", lbID)
s.scope.Logger().Info("Creating load balancer pool for listener", "id", lbID, "listenerID", listenerID, "name", poolName)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think 'pool' is the subject here, so loadBalancerID, listenerID, name?

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

s.scope.Logger().Info("Creating load balancer monitor for pool", "poolID", poolID, "monitorName", monitorName, "loadBalancerID", lbID)
s.scope.Logger().Info("Creating load balancer monitor for pool", "id", lbID, "name", monitorName, "poolID", poolID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, but for 'monitor' instead of 'pool'.

@@ -400,7 +400,7 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac
}

loadBalancerName := getLoadBalancerName(clusterName)
s.scope.Logger().Info("Reconciling load balancer member", "loadBalancerName", loadBalancerName)
s.scope.Logger().Info("Reconciling load balancer member", "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.

Tricky. The only parameter doesn't refer to the subject of the log message. i.e. We're creating a 'member', but name refers to the load balancer, not the member. I'd probably use loadBalancerName here.

Copy link
Contributor

@mdbooth mdbooth left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 16, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: anastaruno, mdbooth

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 16, 2023
@k8s-ci-robot k8s-ci-robot merged commit e0b2279 into kubernetes-sigs:main Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants