-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor: replace zap with slog #6466
Conversation
a6288d5
to
295a6e9
Compare
Signed-off-by: knqyf263 <[email protected]>
@simar7 @nikpivkin @chen-keinan The changes are extensive, so we will probably find something wrong. I'd like as many people as possible to review it. |
"github.com/aquasecurity/trivy/pkg/types" | ||
) | ||
|
||
// clusterRun runs scan on kubernetes cluster | ||
func clusterRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) error { | ||
// TODO: replace with log.Logger | ||
logger, _ := zap.NewProduction() |
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.
trivy-kubernetes v0.6.6 is available and include PR for slog you made
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.
Great, but it seems to include a breaking change.
aquasecurity/trivy-kubernetes#325
Therefore, I'll not remove zap from trivy-kubernetes in this PR. After you apply the above change in Trivy, I'll remove them.
@@ -25,7 +25,7 @@ func initGoogleClassifier() error { | |||
// This loading is expensive and should be called only when the license classification is needed. | |||
var err error | |||
classifierOnce.Do(func() { | |||
log.Logger.Debug("Loading the default license classifier...") | |||
log.Debug("Loading the default license classifier...") |
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.
general nit comment, I see we have many logging some are fully lower-case and some are capital first letter.
it will be great to have one convension
log.Debug("Loading the default license classifier...") | |
log.Debug("loading the default license classifier...") |
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.
We try to follow this convention.
https://google.github.io/styleguide/go/decisions.html#error-strings
Error strings should not be capitalized (unless beginning with an exported name, a proper noun or an acronym) and should not end with punctuation. This is because error strings usually appear within other context before being printed to the user.
On the other hand, the style for the full displayed message (logging, test failure, API response, or other UI) depends, but should typically be capitalized.
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.
Therefore, the log message should be capitalized. If you find a log message in lowercase, please fix it.
Co-authored-by: Nikita Pivkin <[email protected]>
Co-authored-by: Nikita Pivkin <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
Co-authored-by: simar7 <[email protected]>
Signed-off-by: knqyf263 <[email protected]>
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
I'm still going through the PR as it's very big so I'll ask something that might already be taken care of: I wonder if we should allow (or disallow) a mix of strong and loose typed key/value pairs in our logs. For example if we enforce it via something like .LogAttr() it would help prevent getting in the situation where by accident we miss adding attributes. Alternatively to solve the missed attribute problem, we could run a linter check to highlight such cases. On that note, maybe we should include sloglint (part of golangci-lint)? |
Yes, but there are no leveled attr functions like WarnAttr and ErrorAttr, right?
Sounds nice! I'll enable it. Thanks. |
I've not looked into this error, but the linter seems unstable.
|
I'll open another PR for sloglint. Wdyt? @simar7 |
Yeah that's fine! |
Thanks @nikpivkin |
Signed-off-by: knqyf263 <[email protected]> Co-authored-by: Nikita Pivkin <[email protected]> Co-authored-by: simar7 <[email protected]>
- Fix registry version aquasecurity/trivy#6219; \n- Fix replace zap with slog aquasecurity/trivy#6466; \n - The fix with slog used a zap to slog bridge (official from zap, but exp). It didn't have a license file, so I hardcoded a commit version that had; \n- Adopt opts.Align() to validate options object;
- Fix registry version aquasecurity/trivy#6219; \n- Fix replace zap with slog aquasecurity/trivy#6466; \n - The fix with slog used a zap to slog bridge (official from zap, but exp). It didn't have a license file, so I hardcoded a commit version that had; \n- Adopt opts.Align() to validate options object;
* Bump trivy to v0.49.1 * Bump trivy to v0.51.4 - Fix registry version aquasecurity/trivy#6219; - Fix replace zap with slog aquasecurity/trivy#6466; - The fix with slog used a zap to slog bridge (official from zap, but exp). It didn't have a license file, so I hardcoded a commit version that had; - Adopt opts.Align() to validate options object; * Bump trivy to v0.52.2 * Temp change the workflow trigger to test changes * Free up space on runner * Bump trivy to v0.53.0 - Fix go clear cache aquasecurity/trivy#7010 * Bump trivy to v0.54.1 - Fix --vuln-type flag renamed into --pkg-types aquasecurity/trivy#7104; - Adopt package relationships aquasecurity/trivy#7237 * Rollback CI run on target * Clean 'scan cache clean' code and add timeout to it
Description
Replace zap with log/slog.
Related issues
Related PRs
Checklist