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

log: add option to deactivate zap stack trace generation #2319

Merged

Conversation

vboulineau
Copy link
Contributor

Add an option to deactivate stack trace generation, similar to an existing option in Zap itself.
https://github.com/uber-go/zap/blob/v1.10.0/config.go#L202

For some of our public operators, we would like to keep logs clean and tidy to improve readability/investigations for our customers

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 11, 2019
@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 11, 2019
@vboulineau vboulineau force-pushed the feature/no_stack_trace branch 2 times, most recently from 605362f to 1107042 Compare December 11, 2019 15:39
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 11, 2019
Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

Instead of adding a new flag, it may be more convenient to add a --zap-level=disabled.

Con: it doesn't exactly align with zap log levels
Pro: it adds the desired functionality without cluttering the CLI

IMO it is ok to have CLI decoupled from configuration. @joelanford @hasbro17 @jmrodri thoughts?

@estroz
Copy link
Member

estroz commented Dec 11, 2019

@vboulineau also make sure to run

$ make gen-cli-doc

before pushing so docs are generated correctly.

@joelanford
Copy link
Member

@estroz --zap-level is the level at which log messages are written to the output. If I understand correctly, this flag is for disabling the stacktrace, which is a different thing. For example, you might want to see logs starting at the first debug level, but stacktraces starting only at the panic level.

@vboulineau We've recently been contributing to the upstream controller-runtime zap package, with the goal being to phase out SDK's log package.

One of the options currently exposed there is the stacktrace level. Based on that, I'm curious if you think a --zap-stacktrace-level flag would work. You could set --zap-stacktrace-level=panic, which would still log a stacktrace, but only on when using the panic log level (which also causes the program to panic).

If we go this direction, it aligns well with the upstream zap logging package, it provides more fine-grained stacktrace configuration, and it (I think) still meets your use case of cleaning up the logs by allowing you to set it to a level such that it that will only show up in catastrophic situations.

What do you think?

@vboulineau
Copy link
Contributor Author

vboulineau commented Dec 12, 2019

@joelanford I guess it makes sense to log stack trace on panic, as it's likely to be an unexpected behaviour, I can rework the PR to add this flag instead!

Update: PR updated with a stacktrace level. Unfortunately I had to create another 'level' type to avoid cases of stackLevel being < logLevel and to have proper default value in the doc generation (error), I recognised it's not super clean but I was not able to find something better (feel free if you have a better idea).

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 12, 2019
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 12, 2019
@vboulineau vboulineau force-pushed the feature/no_stack_trace branch 2 times, most recently from ac98356 to dad7f53 Compare December 12, 2019 10:09
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 12, 2019
@camilamacedo86
Copy link
Contributor

camilamacedo86 commented Dec 12, 2019

Hi @vboulineau,

See that these changes are not passing in the lint check:

Running golangci-lint
pkg/log/zap/logger.go:53:13: struct of size 64 bytes could be of size 56 bytes (maligned)
type config struct {
^

To check it locally, specifically, run ./hack/tests/check-lint.sh ci
To solve move the sample bool for the latest position of the struct.

@vboulineau
Copy link
Contributor Author

Updated, thanks for picking that up!

@vboulineau
Copy link
Contributor Author

Hey team, do you think this could be merged for 0.16? We were hoping to have it in 0.15 but it seems the release happened already.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 27, 2020
CHANGELOG.md Outdated
@@ -4,6 +4,7 @@

- Added new `--bundle` flag to the `operator-sdk scorecard` command to support bundle validation testing using the validation API (https://github.com/operator-framework/api). ([#1916](https://github.com/operator-framework/operator-sdk/pull/1916)
- Added new `log` field to the `operator-sdk scorecard` v1alpha2 output to support tests that produce logging. ([#1916](https://github.com/operator-framework/operator-sdk/pull/1916)
- Add a new option to set the minimum loglevel that triggers stack trace generation in logs (`--zap-stacktrace-level`) ([#2319](https://github.com/operator-framework/operator-sdk/pull/2319))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Add a new option to set the minimum loglevel that triggers stack trace generation in logs (`--zap-stacktrace-level`) ([#2319](https://github.com/operator-framework/operator-sdk/pull/2319))
- Add a new option to set the minimum log level that triggers stack trace generation in logs (`--zap-stacktrace-level`) ([#2319](https://github.com/operator-framework/operator-sdk/pull/2319))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thank you

pkg/log/zap/flags.go Show resolved Hide resolved
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

@vboulineau Can you fix the merge conflicts? I think it requires re-running make gen-cli-doc

Copy link
Contributor

@hasbro17 hasbro17 left a comment

Choose a reason for hiding this comment

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

@vboulineau SGTM other than rebasing and the typo in the CHANGELOG.

@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 28, 2020
For some of our public operators, we would like to keep logs clean and tidy
to improve readability/investigations for our customers
@vboulineau
Copy link
Contributor Author

Thanks for the reviews, rebased and fix CHANGELOG, should be good to go.

Copy link
Contributor

@hasbro17 hasbro17 left a comment

Choose a reason for hiding this comment

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

LGTM

@vboulineau Thanks for working on this. We should be able to get this in the next release now.

@hasbro17 hasbro17 merged commit 475cdb5 into operator-framework:master Jan 31, 2020
@vboulineau vboulineau deleted the feature/no_stack_trace branch February 3, 2020 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants