-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Update logging guidelines #6283
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: serathius 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @serathius
Thanks for this PR. I reviewed this using the docs style guide for context.
I wasn't able to understand all of the new text so I have guessed at the intended meaning. I've added suggestions and where I wasn't sure I've marked these with ?
s.
I hope this review is useful. Please feel free to select only the suggestions you feel are right.
However, should not be used by external projects as it is mostly developed to maintain backward compatibility. | ||
With introduction of [Structured Logging](https://github.com/kubernetes/enhancements/issues/1602) Kubernetes is being migrated to [logr](https://github.com/go-logr/logr) interface, any changes in klog are done to ensure smooth transition. | ||
|
||
For projects that want to integrate with Kubernetes or write same log format we recommend using [klogr](https://github.com/kubernetes/klog/tree/main/klogr), reimplementation of klog format that exposes [logr](https://github.com/go-logr/logr) interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct?
For projects that want to integrate with Kubernetes or write same log format we recommend using [klogr](https://github.com/kubernetes/klog/tree/main/klogr), reimplementation of klog format that exposes [logr](https://github.com/go-logr/logr) interface. | |
For projects that want to integrate with Kubernetes or write same log format we recommend using [klogr](https://github.com/kubernetes/klog/tree/main/klogr). The `klogr` library exposes an interface that | |
follows [logr](https://github.com/go-logr/logr) conventions, and emits log entries that are equivalent to `klog`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should recommend using klogr, or at least not without further explanations. For example, a library should accept a logr.Logger
instance and let the caller decide whether that is klogr or something else.
But right now we are not ready yet to propose how such a library should accept such a logger - we need a decision about kubernetes/enhancements#3078 first.
contributors/devel/sig-instrumentation/migration-to-structured-logging.md
Outdated
Show resolved
Hide resolved
contributors/devel/sig-instrumentation/migration-to-structured-logging.md
Outdated
Show resolved
Hide resolved
contributors/devel/sig-instrumentation/migration-to-structured-logging.md
Outdated
Show resolved
Hide resolved
@sftim Awesome job on the suggestions! Applied most of them. I only need to rewrite klogr section as @pohly mentioned we should not recommend it. One of the goals of this PR was to start splitting migration guide vs logging good practices. As 1/3 of K8s codebase is already migrated we need to put more weight on good practices document vs migration. Currently migration document contains both migration instruction and some good practices. I was hoping that in future we will be able to rewrite good practices document to list of concrete rules with examples, and make the migration guide just reference selected rules. |
SGTM, no strong preference either way. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
|
||
* klog.ErrorS() - Errors should be used to indicate unexpected behaviours in code, like unexpected errors returned by subroutine function calls. | ||
Logs generated by `ErrorS` command may be enhanced with additional debug information (by logging library). Calling `ErrorS` with `nil` as error may be acceptable if there is error condition that deserves a stack trace at this origin point. | ||
There are two main klog methods for writing logs: `klog.InfoS` and `klog.ErrorS`. Both methods are part of a [logr](https://github.com/go-logr/logr) compatible interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have to update this section to cover the replacement of those calls with logging through Logger
. This goes beyond a simple PR review, so let's get this merged first even if it is not fully up-to-date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sg
contributors/devel/sig-instrumentation/migration-to-structured-logging.md
Show resolved
Hide resolved
contributors/devel/sig-instrumentation/migration-to-structured-logging.md
Outdated
Show resolved
Hide resolved
contributors/devel/sig-instrumentation/migration-to-structured-logging.md
Show resolved
Hide resolved
@pohly addressed all the comments. PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last typo fix for my own suggestion, then we can merge. Can squash before your next push?
Co-authored-by: Patrick Ohly <patrick.ohly@intel.com> Co-authored-by: Tim Bannister <tim@scalefactory.com>
a579591
to
e5eed38
Compare
Done |
/lgtm |
Fixes kubernetes/kubernetes#105975
cc @pohly @shivanshu1333