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

✨ Ensure logging is uniform #237

Merged

Conversation

DirectXMan12
Copy link
Contributor

This ensures that logging uses a uniform set of tags and "style" for the tags. It also adds a helper that prevents the entire object from being logged when logging kubernetes objects. Instead, only a few key identifier fields (name, namespace, api version, and kind, when relevant) are logged when in production (the full object is still logged in development).

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 5, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12

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 size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 5, 2018
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 5, 2018
This commit makes sure we're specific on what packages we "require" in
Gopkg.toml.  Erroneously requiring the root package in the
apiextensions-apiserver, was causing us to pull in main, and
transitively a whole bunch of deps that we didn't actually need.
@DirectXMan12
Copy link
Contributor Author

Please take a look at the logging guidelines, and then I'll move them to the kb book as well.

@DirectXMan12
Copy link
Contributor Author

cc @droot

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Took a quick look, looks good to me overall.

a Kubernetes object", "pod", somePod)`. controller-runtime provides
a special encoder for Zap that will transform Kubernetes objects into
`name, namespace, apiVersion, kind` objects, when available and not in
development mode. Other logr implementations should implement similar
Copy link
Contributor

Choose a reason for hiding this comment

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

This is sweet.

logic.

## Logging Tags

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be useful to highlight what Tags are and how they impact the log message and what is their utility ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

replaced the word "tag" with "key-value pairs" to make things more obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and expanded on things a bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good.

This adds a "wrapper" to a Zap encoder designed to nicely log Kubernetes
objects when in non-development mode.  When in development mode, we
still log the entire object.
This overhauls log tags in CR to ensure that we have consistent style
and naming across all of our log lines.
This updates the dep list with the new zap/buffer dependency.
Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

Looks great overall.
I have left a few minor comments.
And I have found that there are one pair of backquote embeded in another pair of backquote, which mess up the format a bit. e.g.

`foo `embeded text` bar`

It will be helpful to use GH preview to ensure a pretty markdown format.

```

While it's possible to use higher log levels, it's reccomended that you
stick with `V(1)` or V(0)` (which is equivalent to not specifying `V`),
Copy link
Member

Choose a reason for hiding this comment

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

V(0)`

nit: a missing "`"

that. Never use `fmt.Sprintf` in your message.

- Try to match the terminology in your messages with your key-value pairs
-- for instance, if you have a key-value pairs `api version`, use the
Copy link
Member

Choose a reason for hiding this comment

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

I can't follow this example.

Is api version the key in the K-V pair?

And it does using APIVersion conflicts with a later section saying

Use lower-case, space separated keys.  For example `object` for objects,
  `api version` for `APIVersion`

accept a generic interface.

- When logging a raw type, log it using the `type` key, with a value of
`fmt.Sprintf("%T", typ)`
Copy link
Member

Choose a reason for hiding this comment

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

typo here?

- If there's specific context around a type, the key may be more specific,
but should end with `type` -- for instance, `OwnerType` should be logged
as `owner` in the context of `log.Error(err, "Could not get ObjectKinds
for OwnerType", `owner type`, fmt.Sprintf("%T"))`. When possible, favor
Copy link
Member

Choose a reason for hiding this comment

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

fmt.Sprintf("%T")

Need an object here.

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Logging guidelines looks pretty good now.

logic.

## Logging Tags

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good.

@droot
Copy link
Contributor

droot commented Dec 6, 2018

/lgtm

Will wait @mengqiy to take a look and approve since he had a few comments to be addressed.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 6, 2018
@droot droot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 6, 2018
@k8s-ci-robot k8s-ci-robot merged commit 43351af into kubernetes-sigs:master Dec 6, 2018
@mengqiy
Copy link
Member

mengqiy commented Dec 6, 2018

It seems the bot reacted too fast 😆
I'm OK to let Solly address the minor comments in a followup PR.

justinsb pushed a commit to justinsb/controller-runtime that referenced this pull request Dec 7, 2018
…ging-audit

✨ Ensure logging is uniform
DirectXMan12 pushed a commit that referenced this pull request Jan 31, 2020
Add pkg/imports for linking dependencies from projects
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

4 participants