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

Implement Logging Guidelines #251

Open
danehans opened this issue Jan 29, 2025 · 10 comments
Open

Implement Logging Guidelines #251

danehans opened this issue Jan 29, 2025 · 10 comments
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines.

Comments

@danehans
Copy link
Contributor

#182 defined logging conventions and guidelines for the project. These guidelines should be implemented throughout the project. We should also consider tooling to ensure PRs follow logging guidelines.

@danehans danehans added the good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. label Jan 29, 2025
@tchap
Copy link
Contributor

tchap commented Jan 30, 2025

I don't mind working on this. It seems to me it would be good to refactor the code a bit as well to get rid of all the Fatal calls and just return errors. I can just replace the calls, but honestly, it's not that great and also a bit ugly. What do you think?

@tchap
Copy link
Contributor

tchap commented Jan 30, 2025

Rewrote error handling not to use Fatal in the executable code: tchap@2d0108b . Let me know whether this is acceptable, I just played around this optimistically and I don't want to intrude, so I can as well just discard it, but it will have to be done, eventually.

@danehans
Copy link
Contributor Author

I'm good with ErrorS instead of Fatal. Update the logging guidelines if needed. Since we do t have CI setup yet, can you run the e2e test locally and post a snip of your results?

@tchap
Copy link
Contributor

tchap commented Jan 30, 2025

/assign

@tchap
Copy link
Contributor

tchap commented Feb 2, 2025

Also let me know how far you want to push this. Reading up on the current Kubernetes standards, the trend is to move to logr.Logger and contextual logging, i.e. basically drop using klog interface altogether and remove global logging calls as in klog.Info. So these are actually two separate issues:

  • Use contextual logging.
  • Remove klog.

I think that contextual logging is pretty nice, it allows you to attach additional information to log entries. It obviously comes with some extra cost like replacing loggers in ctx unless you are passing it around as an arg, but overall it is a clear and simple approach. You can do contextual logging without dropping klog as there are compatible calls, but then there is really no reason to keep klog.

@danehans
Copy link
Contributor Author

danehans commented Feb 3, 2025

Reading up on the current Kubernetes standards

@tchap can you please provide a link(s) to these current standards? I think we should include this link(s) within our logging docs.

the trend is to move to logr.Logger and contextual logging, i.e. basically drop using klog interface

I'm in favor of moving to logr.Logger with contextual logging if this follows the k8s guidelines. Let's get input from @ahg-g @liu-cong @kfswain @robscott before proceeding.

@tchap
Copy link
Contributor

tchap commented Feb 3, 2025

can you please provide a link(s) to these current standards? I think we should include this link(s) within our logging docs.

Sure, it's right in the doc that is linked from dev.md.

@tchap
Copy link
Contributor

tchap commented Feb 3, 2025

To be clear, the doc is 2 years old, but I haven't found anything more up to date. It's in sync with what kubebuilder generates when starting a new controller project. But keep me in check, I am pretty new to this stuff.

It seems you can use both klog and logr, but if there is any substantial work being done on logging, I would vote for moving away from using global package loggers like klog.* calls. Not a great pattern. Just instantiate your logger, pass it around as an arg or in the context. It is also set "globally" in controller-runtime. It just seems way cleaner to me.

@tchap
Copy link
Contributor

tchap commented Feb 15, 2025

I think that this is implemented now, except perhaps the tooling to check incoming PRs.

When implementing this issue, I used https://pkg.go.dev/k8s.io/klog/hack/tools/logcheck . Not sure it can be used for PRs, but just linking in here just in case.

@kfswain
Copy link
Collaborator

kfswain commented Feb 19, 2025

I agree. I'm happy to consider this closed, I'll let @danehans make the final call however

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines.
Projects
None yet
Development

No branches or pull requests

3 participants