Skip to content

🐛 Fix allowed levels for --zap-log-levels flag to align with logr levels #991

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

Merged
merged 2 commits into from
Jul 23, 2020

Conversation

bharathi-tenneti
Copy link
Contributor

@bharathi-tenneti bharathi-tenneti commented Jun 10, 2020

--Current implementation in flags.go has a bug, which is leading to incorrect zap log level to be set.
--This PR also focuses on aligning --zap-log-level with logr levels.
Example: --zap-log-level=2 should map to using increased verbosity logr.V(2).Info().
-- This PR also disables Sampling for debug levels with increased verbosity, as they will cause index out of bounds errors in sampling code.

Closes: #990

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 10, 2020
@k8s-ci-robot k8s-ci-robot requested review from alenkacz and gerred June 10, 2020 21:53
@k8s-ci-robot
Copy link
Contributor

Hi @bharathi-tenneti. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 10, 2020
@bharathi-tenneti bharathi-tenneti changed the title 🐛 Zaploglevel bug in returning correct logLevel from command line in flags.go [WIP] 🐛 Zaploglevel bug in returning correct logLevel from command line in flags.go Jun 10, 2020
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 10, 2020
@bharathi-tenneti
Copy link
Contributor Author

/cc @joelanford @hasbro17

@bharathi-tenneti
Copy link
Contributor Author

bharathi-tenneti commented Jun 11, 2020

Please use unit test cases, to test this fix.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 11, 2020
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.

Need to clarify what --zap-stacktrace-level=disabled is for.
Plus some nits on the test cases.

@bharathi-tenneti bharathi-tenneti changed the title [WIP] 🐛 Zaploglevel bug in returning correct logLevel from command line in flags.go [WIP] 🐛 Fix allowed levels for --zap-log-levels flag to align with logr levels Jun 17, 2020
@bharathi-tenneti bharathi-tenneti changed the title [WIP] 🐛 Fix allowed levels for --zap-log-levels flag to align with logr levels 🐛 Fix allowed levels for --zap-log-levels flag to align with logr levels Jun 18, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 18, 2020
@hasbro17
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 19, 2020
Comment on lines 186 to 193
if o.Level.Enabled(zapcore.DebugLevel) {
o.ZapOpts = append(o.ZapOpts, zap.Development())
} else {
o.ZapOpts = append(o.ZapOpts,
zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewSampler(core, time.Second, 100, 100)
}))
}
Copy link
Member

Choose a reason for hiding this comment

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

I think its technically okay to use sampling with zapcore.DebugLevel. It only needs to be disabled starting at zapcore.Level(-2).

Also, I don't think we want to force development mode based on the log level.

Given the above details, does the following work?

Suggested change
if o.Level.Enabled(zapcore.DebugLevel) {
o.ZapOpts = append(o.ZapOpts, zap.Development())
} else {
o.ZapOpts = append(o.ZapOpts,
zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewSampler(core, time.Second, 100, 100)
}))
}
if !o.Level.Enabled(zapcore.Level(-2)) {
o.ZapOpts = append(o.ZapOpts,
zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewSampler(core, time.Second, 100, 100)
}))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't this only cover Level(-2) ,We still need to handle Level(-3) or below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree , We can remove the developement mode, and it can be as shown below.

	// Disable sampling when we are in debug mode. Otherwise, this will
		// cause index out of bounds errors in the sampling code.
		if o.Level.Enabled(zapcore.DebugLevel) {
			o.ZapOpts = append(o.ZapOpts)
		} else {
			o.ZapOpts = append(o.ZapOpts,
				zap.WrapCore(func(core zapcore.Core) zapcore.Core {
					return zapcore.NewSampler(core, time.Second, 100, 100)
				}))
		}

@kubernetes-sigs kubernetes-sigs deleted a comment from joelanford Jul 7, 2020
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

It shows /lgtm /approve for me 👍

@bharathi-tenneti
Copy link
Contributor Author

/retest

@DirectXMan12 DirectXMan12 self-assigned this Jul 16, 2020
@vincepri
Copy link
Member

/cc @joelanford @DirectXMan12

@joelanford
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 23, 2020
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/milestone v0.6.x

@k8s-ci-robot k8s-ci-robot added this to the v0.6.x milestone Jul 23, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bharathi-tenneti, vincepri

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 23, 2020
@vincepri
Copy link
Member

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jul 23, 2020
@bharathi-tenneti
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit fb0577a into kubernetes-sigs:master Jul 23, 2020
kevindelgado pushed a commit to kevindelgado/controller-runtime that referenced this pull request Sep 15, 2020
…vels (kubernetes-sigs#991)

* Fix zap levels to align with logr

* Fix sampling logic for debug levels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zap loglevels incorrectly returns log level when used from command line.
7 participants