-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Clean up logging usage (and minor script improvements) #86
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
Clean up logging usage (and minor script improvements) #86
Conversation
The example sets up logr, and then uses the built-in go `log` package. We should show people how to make use of logr instead.
The former abbreviation (`mrg`) is a well known typo. This fixes instances of `mrg` so they say `mgr` (ManaGeR).
We should be consistenly using logr instead of the go standard library, or glog (when in our code -- we don't have any control over code from kubernetes core). Most of this usage was `log.Fatal`, which we replace with calls to `<log>.Error` and `os.Exit(1)`.
Add a single environment variable that can be set to change the default search path for kubebuilder test assets, `KUBEBUILDER_ASSETS`. This prevents us from having to specify all three `TEST_ASSET_<thing>` environment variables manually if kubebuilder isn't installed in /usr/local/kubebuilder.
5390586
to
88fd91b
Compare
Thanks for the PR @DirectXMan12 . Took a quick look and looks good. @mengqiy Can you also pl. take a look at the changes in the admission pkg ? |
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.
/lgtm
@@ -148,7 +147,7 @@ func (f *fsCertWriter) doWrite(webhookName string) (*certgenerator.Artifacts, er | |||
if err != nil { | |||
return nil, err | |||
} | |||
aw, err := atomic.NewAtomicWriter(v.path, fmt.Sprintf("processing webhook %q", webhookName)) | |||
aw, err := atomic.NewAtomicWriter(v.path, log.WithName("atomic-writer").WithValues("task", "processing webhook", "webhook", webhookName)) |
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.
Not in the scope of this PR.
I feel the signature of method WithValues
is a little confusing, if I don't know that the list of interface with 2*n items is actually representing n key-value pairs.
Why not using a signature that taking a map?
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.
the interface is mostly copied from Zap, so using a map means more overhead in our primary usecase. Beyond that, Zap specifically does it to allow certain tricks that we don't take advantage of now, but we could consider in the future (i.e. helpers which have their own tag built in, improvements around number of allocations, etc). Plus, it's fewer keystrokes ;-). I do understand where you're coming from, though.
pkg/runtime/log/log.go
Outdated
) | ||
|
||
// ZapLogger is a Logger implementation. | ||
// if development is true stack traces will be printed for errors | ||
// If development is true, a Zap development config ill be used |
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.
s/ill/will
targetDir string | ||
logContext string | ||
targetDir string | ||
log logr.Logger |
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.
Changing this file means that it starts to diverge from upstream.
But I guess it's not a problem.
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.
if we actually have our own copy, we should treat it as such, IMO.
@DirectXMan12 There is one typo left to fix. Then it's good to go. |
This adds a helper (ZapLoggerTo) to log to a particular io.Writer. This allows us to set our suite logging to `GinkgoWriter`, so that ginkgo captures the logging output correctly.
This fixes the tag handling of the delegating logger, which was missing a splat operator, and thus causing the tags to be misinterpretted. This also adds proper testing of the delegating functionality, so that this doesn't happen again.
This splits up test.sh so that the individual parts can be run separately (particularly, the linting, the testing and coverage, and the downloading of tools, etc). All the scripts now live in the hack directory.
88fd91b
to
d3231aa
Compare
@mengqiy fixes should be in place now, so this should be ready to merge. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. 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 |
…std-log Clean up logging usage (and minor script improvements)
Embbed more example types for docs
This fixes up a bunch of places where we were using the go
log
package in the standard library, or glog, fixes a bug found in the delegating logger, and introduces proper tests for the delegating logger to prevent that from happening again.It also contains a couple minor quality-of-life improvements to the tests scripts -- you can now run linters and testing separately, and can simply specify
KUBEBUILDER_ASSETS
instead of exporting three different variables if your kubebuilder lives elsewhere.