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

✨ Use klog as kubebuilder default logger #3033

Closed

Conversation

astraw99
Copy link
Contributor

@astraw99 astraw99 commented Oct 22, 2022

Fixes #3036
Fixes kubernetes-sigs/controller-runtime#2024

To make the log output consistent with K8s core components (kube-apiserver, kube-controller-manager, etc), and
more human readable.

Test results:
Before this PR, the kubebuilder generated controller-manager log is:

1.6656692709539523e+09  INFO    controller-runtime.metrics      Metrics server is starting to listen    {"addr": "127.0.0.1:8080"}
1.665669270954326e+09   INFO    setup   starting manager
1.6656692709546785e+09  INFO    Starting server {"path": "/metrics", "kind": "metrics", "addr": "127.0.0.1:8080"}
1.6656692709546802e+09  INFO    Starting server {"kind": "health probe", "addr": "[::]:8081"}

After this PR, the kubebuilder generated controller-manager log is:

I1016 23:41:42.700531   61722 listener.go:44] "controller-runtime/metrics: Metrics server is starting to listen" addr=":8080"
I1016 23:41:42.701073   61722 main.go:115] "setup: starting manager"
I1016 23:41:42.701251   61722 internal.go:362] "Starting server" kind="health probe" addr="[::]:8081"
I1016 23:41:42.701255   61722 internal.go:362] "Starting server" path="/metrics" kind="metrics" addr="[::]:8080"

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: astraw99
Once this PR has been reviewed and has the lgtm label, please assign jmrodri for approval by writing /assign @jmrodri in a comment. 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 22, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @astraw99. 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.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Hi @astraw99,

Thank you for your contribution 🥇.

Would not the change done in controller-runtime kubernetes-sigs/controller-runtime#2029 also address your motivation?

(ihmo) we need to discuss if we would like to change the default log lib to klog. For that, we need to understand what are the motivations for the controller-runtime use of zap first. Would possible for you to open an issue with the proposed idea and check out it and add the pros and cons that you see to do this change?

An alternative option would to be add a FAQ section in the docs describing to users how they can customize the scaffold to use klog instead.

@camilamacedo86
Copy link
Member

/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 Oct 23, 2022
@@ -196,7 +198,6 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
Copy link
Member

Choose a reason for hiding this comment

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

@alvaroaleman @joelanford do you remember why we implement the log zap feature in controller-runtime instead of using klog?

c/c @jmrodri @varshaprasad96

Copy link
Member

Choose a reason for hiding this comment

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

/hold

Only to avoid it getting merged before it has enough reviews and discussions.

@@ -8,6 +8,7 @@ require (
k8s.io/api v0.25.0
k8s.io/apimachinery v0.25.0
k8s.io/client-go v0.25.0
k8s.io/klog/v2 v2.70.1
Copy link
Member

Choose a reason for hiding this comment

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

Cons: It will add a new dep for the projects which increases the cost for maintainability.

@astraw99
Copy link
Contributor Author

Hi @astraw99,

Thank you for your contribution 🥇.

Would not the change done in controller-runtime kubernetes-sigs/controller-runtime#2029 also address your motivation?

(ihmo) we need to discuss if we would like to change the default log lib to klog. For that, we need to understand what are the motivations for the controller-runtime use of zap first. Would possible for you to open an issue with the proposed idea and check out it and add the pros and cons that you see to do this change?

An alternative option would to be add a FAQ section in the docs describing to users how they can customize the scaffold to use klog instead.

Opened a proposal #3036, including log format comparison and pros/cons.
PTAL thanks.

@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 Oct 24, 2022
@astraw99 astraw99 changed the title ⚠️ Use klog as kubebuilder default logger ✨ Use klog as kubebuilder default logger Oct 27, 2022
@astraw99
Copy link
Contributor Author

After the issue discussion, we prefer to use zap as default logger.
Will close this proposal PR.

@astraw99 astraw99 closed this Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Use klog as kubebuilder default logger Controller-pod log time format is not human readable
3 participants