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

Update logging guidelines #6283

Merged
merged 1 commit into from
Mar 17, 2022

Conversation

serathius
Copy link
Contributor

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 9, 2021
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added area/developer-guide Issues or PRs related to the developer guide sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 9, 2021
Copy link
Contributor

@sftim sftim left a 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.

contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved
contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct?

Suggested change
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`.

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 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/logging.md Outdated Show resolved Hide resolved
contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved
contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved
contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved
@serathius
Copy link
Contributor Author

@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.
What do you think about this idea?

@sftim
Copy link
Contributor

sftim commented Dec 15, 2021

What do you think about this idea?

SGTM, no strong preference either way.

@k8s-triage-robot
Copy link

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 15, 2022
@serathius
Copy link
Contributor Author

/remove-lifecycle stale
/assign @pohly

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 15, 2022
contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved
contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved
contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved
contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved

* 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.
Copy link
Contributor

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.

Copy link
Contributor Author

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/logging.md Outdated Show resolved Hide resolved
@serathius
Copy link
Contributor Author

@pohly addressed all the comments. PTAL

Copy link
Contributor

@pohly pohly left a 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?

contributors/devel/sig-instrumentation/logging.md Outdated Show resolved Hide resolved
Co-authored-by: Patrick Ohly <patrick.ohly@intel.com>
Co-authored-by: Tim Bannister <tim@scalefactory.com>
@serathius
Copy link
Contributor Author

Done

@pohly
Copy link
Contributor

pohly commented Mar 17, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 17, 2022
@k8s-ci-robot k8s-ci-robot merged commit d14dd59 into kubernetes:master Mar 17, 2022
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. area/developer-guide Issues or PRs related to the developer guide cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. 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.

Improve structured logging migration guide
5 participants