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

Support structured logging #208

Merged

Conversation

bells17
Copy link
Contributor

@bells17 bells17 commented Aug 17, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

I've added JSON logging and changed to use structured logging (e.g., klog.InfoS) in this PR.
With this change, it is now possible to output the logs of the external-health-monitor container in JSON format.
Running the container with the --logging-format=json option will output the logs in JSON format.

In addition, I've modified the log messages based on the following guideline:
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#remove-string-formatting-from-log-message

I’ve update the klog functions in use according to the guidelines provided below, and I've confirmed that they pass the logcheck tests:
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#change-log-functions

$ logcheck cmd/csi-external-health-monitor-controller/main.go
$ logcheck ./pkg/controller/
$ logcheck ./pkg/csi-handler/
$ logcheck ./pkg/csi-handler/
$ logcheck ./pkg/mock/
$ logcheck ./pkg/util/

related PR: kubernetes-csi/livenessprobe#202

Which issue(s) this PR fixes:

Special notes for your reviewer:

# The logs below were outputted because the program was running on MacOS.
$ go run cmd/csi-external-health-monitor-controller/main.go --logging-format=json
{"ts":1692983306225.366,"caller":"csi-external-health-monitor-controller/main.go:103","msg":"Version","v":0,"version":"unknown"}
{"ts":1692983306225.402,"caller":"csi-external-health-monitor-controller/main.go:117","msg":"Failed to build a Kubernetes config","err":"unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined"}
exit status 1

$ go run cmd/csi-external-health-monitor-controller/main.go
I0826 02:08:31.658543   19448 main.go:103] "Version" version="unknown"
E0826 02:08:31.658664   19448 main.go:117] "Failed to build a Kubernetes config" err="unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined"
exit status 1

Does this PR introduce a user-facing change?:

Added support structured logging

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 17, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @bells17!

It looks like this is your first PR to kubernetes-csi/external-health-monitor 🎉. 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-csi/external-health-monitor 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 Aug 17, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @bells17. Thanks for your PR.

I'm waiting for a kubernetes-csi 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 17, 2023
@bells17 bells17 force-pushed the support-structured-logging branch from 281219c to 856803e Compare August 17, 2023 17:32
@bells17 bells17 marked this pull request as ready for review August 17, 2023 17:39
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 17, 2023
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 21, 2023
@xing-yang
Copy link
Contributor

/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 Aug 21, 2023
@xing-yang
Copy link
Contributor

Hi @bells17, it looks like you are not a member yet. Please feel free to open an issue here and apply for membership in kubernetes-csi org.

@bells17
Copy link
Contributor Author

bells17 commented Aug 21, 2023

I apologize for the oversight. I've noticed that the klog functions in use are not aligned with the guidelines below, so I will be changing the status of the Pull Request to Draft for now:
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#change-log-functions

@bells17 bells17 marked this pull request as draft August 21, 2023 16:09
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 21, 2023
@bells17 bells17 force-pushed the support-structured-logging branch 3 times, most recently from 2f5c597 to c6dda1f Compare August 25, 2023 17:21
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2023
@bells17 bells17 marked this pull request as ready for review August 26, 2023 01:56
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 26, 2023
@k8s-ci-robot k8s-ci-robot requested a review from jingxu97 August 26, 2023 01:56
@bells17
Copy link
Contributor Author

bells17 commented Aug 26, 2023

The changes are done, so I've changed the PR status back to ready.

@bells17 bells17 force-pushed the support-structured-logging branch from c6dda1f to 85851cf Compare August 30, 2023 13:52
@bells17 bells17 force-pushed the support-structured-logging branch from 85851cf to 4574105 Compare August 30, 2023 15:42
@bells17 bells17 requested a review from xing-yang September 4, 2023 14:08
@xing-yang xing-yang self-assigned this Sep 6, 2023
@@ -172,7 +171,7 @@ func (watcher *NodeWatcher) WatchNodes() {
return false
}
if !errors.IsNotFound(err) {
klog.V(2).Infof("error getting node %q from informer: %v", key, err)
klog.V(2).ErrorS(err, "Error getting node from informer", "node", key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you keep this at InfoS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xing-yang Sorry for the mistake. I've updated it to use InfoS.

@bells17 bells17 requested a review from xing-yang September 8, 2023 16:44
@xing-yang
Copy link
Contributor

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bells17, xing-yang

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 Sep 11, 2023
@k8s-ci-robot k8s-ci-robot merged commit 9d66687 into kubernetes-csi:master Sep 11, 2023
@bells17 bells17 deleted the support-structured-logging branch September 12, 2023 06:18
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. kind/feature Categorizes issue or PR as related to a new feature. 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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants