-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
✨ Ensure logging is uniform #237
Conversation
[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 |
f1ecd04
to
c774e2f
Compare
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.
edc15ac
to
aa88474
Compare
Please take a look at the logging guidelines, and then I'll move them to the kb book as well. |
cc @droot |
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.
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 |
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.
This is sweet.
logic. | ||
|
||
## Logging Tags | ||
|
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.
It will be useful to highlight what Tags
are and how they impact the log message and what is their utility ?
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.
replaced the word "tag" with "key-value pairs" to make things more obvious.
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.
and expanded on things a bit.
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.
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.
aa88474
to
027a76d
Compare
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.
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`), |
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.
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 |
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 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)` |
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.
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 |
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.
fmt.Sprintf("%T")
Need an object here.
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.
Logging guidelines looks pretty good now.
logic. | ||
|
||
## Logging Tags | ||
|
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.
Looks good.
/lgtm Will wait @mengqiy to take a look and approve since he had a few comments to be addressed. |
It seems the bot reacted too fast 😆 |
…ging-audit ✨ Ensure logging is uniform
Add pkg/imports for linking dependencies from projects
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
, andkind
, when relevant) are logged when in production (the full object is still logged in development).