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

🌱Structured logging migration of cluster-api-provider-openstack/pkg/cloud/services/compute/instance.go #1617

Closed
wants to merge 5 commits into from

Conversation

skylerxhu
Copy link
Contributor

What this PR does / why we need it:
Fix up the string formatting log messages so that they use structured logging as documented here: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 24, 2023
@linux-foundation-easycla
Copy link

CLA Missing ID CLA Not Signed

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: skylerxhu
Once this PR has been reviewed and has the lgtm label, please assign jichenjc for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 cncf-cla: no Indicates the PR's author has not 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 7558308
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/64c065a17cc456000803b7ce
😎 Deploy Preview https://deploy-preview-1617--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

Welcome @skylerxhu!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-openstack 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api-provider-openstack has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 24, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @skylerxhu. 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 the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 24, 2023
@mdbooth
Copy link
Contributor

mdbooth commented Jul 24, 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 24, 2023
@@ -94,7 +94,7 @@ func (s *Service) normalizePortTarget(port *infrav1.PortOpts, openStackCluster *
if err != nil {
// Multiple matches might be ok later when we restrict matches to a single network
if errors.Is(err, networking.ErrMultipleMatches) {
s.scope.Logger().V(4).Info("Can't infer network from subnet %d: %s", i, err)
s.scope.Logger().V(4).Info("Couldn't infer network from subnet","IPIndex", i, "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably change IPIndex to SubnetIndex: FixedIPs is a weird naming thing from OpenStack which really means subnets.

However, both this and the above are very much debug level logs, so anybody interested is likely also looking at the code.

@@ -432,7 +432,7 @@ func (s *Service) getOrCreateRootVolume(eventObject runtime.Object, instanceSpec
return nil, fmt.Errorf("exected to find volume %s with size %d; found size %d", name, size, volume.Size)
}

s.scope.Logger().Info("using existing root volume %s", name)
s.scope.Logger().Info("Using existing root volume", "rootVolumeName", name)
Copy link
Contributor

@mdbooth mdbooth Jul 24, 2023

Choose a reason for hiding this comment

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

This is an interesting rabbit hole. You've used rootVolumeName here, but volumeName below. I don't think this was covered in the guidelines, but I feel like these should be consistent.

But: what's the scope of the consistency? We could call this name and in the message below also change volumeID to ID. That would be consistent within the scope of a single message. But how about consistency across all log messages. How about if we always referred to the ID of a volume as volumeID. That sounds pretty useful to me when grepping for log messages. But I suspect (without checking) that in other places we just use ID for, e.g. a server ID. Should we update those to be serverID. Should we start a new taxonomy for log parameters:

<object>|(ID|Name|Idx)

Where <object> is one of:

  • server
  • volume
  • loadBalancer
  • port
  • router
  • network
  • subnet

floatingIP would be slightly different, as they're normally referenced by IP.

Thinking about this now as we're starting a concerted effort to clean them all up, so we do have the opportunity to make everything consistent if we think it's worthwhile. If we agree on something like this we should add it to our documentation.

Interested in thoughts from @jichenjc @lentzi90 @seanschneeweiss @tobiasgiese @stephenfin.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. As you say, when we're doing this already it makes sense to be consistent in how we log.

Choose a reason for hiding this comment

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

Perhaps it might make sense to add object types like "pool" and "listener" to the set. They are used extensively in pkg/cloud/services/loadbalancer/loadbalancer.go, and possibly other files, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that creating a new taxonomy will help address the consistency issue. During the migration to structured logging, I was confused by these two rules:

  • "Do not provide additional context for how the value is used. Don't use podIP, do use IP."
  • "When names are very ambiguous, try to include context in the label. For example, instead of key use cacheKey or instead of version use dockerVersion."

There seems to be no clear instruction about when to include or exclude the context. This lack of clarity can be problematic for contributors who are not familiar with the default/conventional naming style. It would be beneficial to provide more explicit examples and explanations for each rule.

Copy link
Contributor

Choose a reason for hiding this comment

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

@skylerxhu That's a good catch. That text from the kubernetes guidelines would appear to argue against what I'm suggesting. I think we should assume for now that the guidelines are based on collected experience and just follow them until we find a good reason not to.

To be clear, that means:

  • A property (e.g. id, name, ip) for any object is just called <property>
  • Unless the log message involves more than one object, in which case any 'principal subject' is just %lt;property> and other objects have a prefix

e.g.

("Created network", "id", "aaaa-bbbb-cccc-dddd", "name", "my-network")

("Created subnet", "id", "0000-1111-2222-3333", "name" "my-subnet", "networkID", "aaaa-bbbb-cccc-dddd", "networkName", my-network")

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is worth getting hung up on and it's impacting work by others, so lets aim to settle on a decision before EOD today.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also in favor of name if there is only one object handled within the log message.

Copy link
Contributor

@seanschneeweiss seanschneeweiss Jul 26, 2023

Choose a reason for hiding this comment

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

On the other hand, there is a list of "good keys", and that includes volumeName.

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, can we use past tense here? "Used existing root volume"
Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, can we use past tense here? "Used existing root volume" Does that make sense?

IIRC the guidelines recommend '-ing' when logging before and action. Past tense indicates a completed action.

@linux-foundation-easycla
Copy link

CLA Missing ID CLA Not Signed

@linux-foundation-easycla
Copy link

CLA Missing ID CLA Not Signed

@linux-foundation-easycla
Copy link

CLA Missing ID CLA Not Signed

@linux-foundation-easycla
Copy link

CLA Missing ID CLA Not Signed

@linux-foundation-easycla
Copy link

CLA Missing ID CLA Not Signed

@k8s-ci-robot k8s-ci-robot removed the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 26, 2023
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 26, 2023
@k8s-ci-robot
Copy link
Contributor

@skylerxhu: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-provider-openstack-build 7558308 link true /test pull-cluster-api-provider-openstack-build
pull-cluster-api-provider-openstack-test 7558308 link true /test pull-cluster-api-provider-openstack-test
pull-cluster-api-provider-openstack-e2e-test 7558308 link true /test pull-cluster-api-provider-openstack-e2e-test

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@skylerxhu skylerxhu closed this by deleting the head repository Jul 26, 2023
@@ -579,7 +579,7 @@ func (s *Service) DeleteInstance(eventObject runtime.Object, instanceStatus *Ins
return nil
}

s.scope.Logger().Info("deleting dangling root volume %s(%s)", volume.Name, volume.ID)
s.scope.Logger().Info("Deleting dangling root volume", "volumeName", volume.Name, "volumeID", volume.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if the logging should be moved out of this function to the calling function. And then it should log a line after calling getOrCreateRootVolume, using past tense.
E.g. "deleted volume".

This is something for a separate PR, however requires us to rethink where we log and where not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants