-
Notifications
You must be signed in to change notification settings - Fork 14
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
add klog.v(0) and logger.v(0) check #4
add klog.v(0) and logger.v(0) check #4
Conversation
4fb10d3
to
038c0b9
Compare
/cc @pohly |
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 already looks pretty good. Some comments...
4befb0d
to
33ca26b
Compare
@pohly Thank you for the very detailed review, some scenarios were not considered at first, and now it has been updated. |
33ca26b
to
f7558df
Compare
Pos: fexpr.Fun.Pos(), | ||
Message: msg, | ||
}) | ||
} |
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.
Can you move the pass.Report
down into checkForVerboseZero
to avoid the code duplication? If we ever decide to make it better (for example, by suggesting a code update), then we only need to make that change in one place.
checkForVerboseZero
can call a isVerboseZero
that is equivalent to the current function.
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.
Yeah, this part is duplicated.
I have optimized it.
f7558df
to
8b816a4
Compare
logcheck/pkg/logcheck.go
Outdated
@@ -36,6 +36,7 @@ const ( | |||
parametersCheck = "parameters" | |||
contextualCheck = "contextual" | |||
withHelpersCheck = "with-helpers" | |||
verboseZeroCheck = "verbose-zero" |
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.
One last thing: should this be "verbosity" instead of "verbose"?
I think V
stands for "verbosity" of the log message, but I might be wrong (not a native speaker).
A log message is "verbose", but it has "verbosity zero".
937b8ad
to
9bb3130
Compare
9bb3130
to
7fe4221
Compare
@pohly I think you are right.
So |
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
/approve
Thanks a lot!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pohly, yangjunmyfm192085 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 |
return true | ||
} | ||
|
||
if id, ok := subCallExpr.Args[0].(*ast.Ident); ok && id.Obj.Kind == 2 { |
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'm not sure what is nil, but when I tried this change on top of your kubernetes/kubernetes#111708 I got a nil pointer access:
ERRO [runner] Panic: logcheck: package "vclib" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 18650 [running]:
runtime/debug.Stack()
/nvme/gopath/go-1.19/src/runtime/debug/stack.go:24 +0x65
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
/nvme/gopath/pkg/mod/github.com/golangci/golangci-lint@v1.48.0/pkg/golinters/goanalysis/runner_action.go:101 +0x155
panic({0x153a9e0, 0x2024fd0})
/nvme/gopath/go-1.19/src/runtime/panic.go:884 +0x212
sigs.k8s.io/logtools/logcheck/pkg.isVerbosityZero({0x18ff6c0?, 0xc01b9c4000?})
/nvme/gopath/pkg/mod/sigs.k8s.io/logtools@v0.2.1-0.20220830112100-f68289b649a5/logcheck/pkg/logcheck.go:544 +0xb5
To reproduce, check out your Kubernetes branch and patch it:
diff --git a/hack/tools/go.mod b/hack/tools/go.mod
index 8728f260aa4..ffcc1ab1519 100644
--- a/hack/tools/go.mod
+++ b/hack/tools/go.mod
@@ -11,7 +11,7 @@ require (
github.com/google/go-flow-levee v0.1.5
gotest.tools/gotestsum v1.6.4
honnef.co/go/tools v0.3.3
- sigs.k8s.io/logtools v0.1.0
+ sigs.k8s.io/logtools v0.2.1-0.20220830112100-f68289b649a5
sigs.k8s.io/zeitgeist v0.2.0
)
diff --git a/hack/tools/go.sum b/hack/tools/go.sum
index 0dc6f65d798..c39cafc35cd 100644
--- a/hack/tools/go.sum
+++ b/hack/tools/go.sum
@@ -829,6 +829,7 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
+github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
gitlab.com/bosi/decorder v0.2.3 h1:gX4/RgK16ijY8V+BRQHAySfQAb354T7/xQpDB2n10P0=
gitlab.com/bosi/decorder v0.2.3/go.mod h1:9K1RB5+VPNQYtXtTDAzd2OEftsZb1oV0IrJrzChSdGE=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
@@ -1077,6 +1078,7 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220702020025-31831981b65f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
@@ -1368,6 +1370,10 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/logtools v0.1.0 h1:BWdoZu2PK6/lj5QhSXBGlHFu3d/ST1HlINXwE/CkJRQ=
sigs.k8s.io/logtools v0.1.0/go.mod h1:/Rp/yzQWyUgsNCRb1HKRnrVujUV9CmzksOlsQR2OVvw=
+sigs.k8s.io/logtools v0.2.0 h1:FMy0Td6HnWP+Iqq9QWEZigS130aZSMtlhRn5pcZbwCo=
+sigs.k8s.io/logtools v0.2.0/go.mod h1:2HGcCK1vi9YvsBoUDMXvrf588j890iRtsymJX2biE0Q=
+sigs.k8s.io/logtools v0.2.1-0.20220830112100-f68289b649a5 h1:dy8gOoe/fHFqY1vN16XTgl/S8TIpuyxkE0wCTUr1UV4=
+sigs.k8s.io/logtools v0.2.1-0.20220830112100-f68289b649a5/go.mod h1:2HGcCK1vi9YvsBoUDMXvrf588j890iRtsymJX2biE0Q=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
Then run hack/verify-golangci-lint.sh
. That also shows that there are several more code lines which need to be modified.
If you want to try out a modified logcheck then you can point towards a local copy with:
(cd hack/tools && go mod edit -replace sigs.k8s.io/logtools=<absolute path>/logtools/)
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.
No code survives first contact with the real world 😁
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.
Let me analyze why
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.
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's indeed a bit odd. I can only reproduce it by running hack/verify-golangci-lint.sh
, but not when invoking logcheck directly.
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 now I cannot reproduce it anymore. Perhaps it was a problem with the golangci-lint cache.
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.
Hi, @pohly ,I think I caught the issue.
When Constants of value is defined in different files, there will be cases where it cannot be parsed directly
such as
https://github.com/kubernetes/kubernetes/blob/2b2be7fa6b69c7591a31475fc4fb1dcff362a128/staging/src/k8s.io/legacy-cloud-providers/vsphere/vclib/datastore.go#L62
Do we need to continue dealing with this scenario, is it a bit complicated?
Or do we just need to fix panic?
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 think it is sufficient to avoid the panic. Please reopen #5 and add an explanation in the code why the additional if conditions are needed, then I can merge it.
as mentioned in #2
Calling
V
with zero as parameter just causes additional overhead.we want a way to enforce that this code pattern doesn't get added back in some future PR