-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Remove dependencies on unused tools, install tools explicitly instead of via go.mod #3355
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3355 +/- ##
==========================================
+ Coverage 96.45% 96.47% +0.01%
==========================================
Files 259 259
Lines 15166 15166
==========================================
+ Hits 14629 14631 +2
+ Misses 453 451 -2
Partials 84 84
Continue to review full report at Codecov.
|
@@ -25,5 +25,4 @@ import ( | |||
_ "github.com/securego/gosec/cmd/gosec" | |||
_ "github.com/vektra/mockery/cmd/mockery" | |||
_ "github.com/wadey/gocovmerge" | |||
_ "golang.org/x/lint/golint" |
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.
actually, we need to replace it with import of github.com/golangci/golangci-lint
, because it is being explicitly installed by version in install-tools
Makefile target instead of using go.mod as we do with other tools.
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.
what about simply removing this file? It seems build tag 'tool' is nowhere called...
github.com/golangci/golangci-lint is not a valid package (it's a binary)
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 file is needed so that the respective packages are added to go.mod and when we do go install
we use the versions pinned in go.mod, not the random/latest ones.
I am not sure what you mean that github.com/golangci/golangci-lint is not a valid package - it's the source code of the tool , we currently install it as
go install github.com/golangci/golangci-lint/cmd/[email protected]
but once we have it in go.mod with the version we should just install it with go install github.com/golangci/golangci-lint/cmd/golangci-lint
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.
Ok, I have tried to replicate your suggestion to the best of my understanding. Please notice that:
- having
golangci-lint
in ourgo.mod
is bringing a lot of indirect dependencies as well (see thego.mod
file). This is a consequence of the nature ofgolangci-lint
- it is a linter aggregator and therefore it declares all the supported linters as its dependencies. In Jaeger case this might be a big price to pay given that we are only using 3 out of the very long list of supported linters. - Since we do not use
gosec
directly but only indirectly throughgolangci-lint
I have removed the explicit dependency from thetools.go
file. - I have removed altogether the import of
honnef.co/go/tools/cmd/staticcheck
as we are not using it directly or indirectly. (correct me if I'm wrong) - I took the liberty to merge
install-mockery
intoinstall-tools
target because it felt tidier IMO. Please let me know if you prefer to keep them separate (and if there is a rational for that I would be interested to know as well).
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.
Hm, I think it was a mistake that staticcheck was removed https://github.com/jaegertracing/jaeger/pull/3237/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52L169 -- cc @albertteoh
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 staticcheck
linter is included by default: https://golangci-lint.run/usage/linters/#enabled-by-default-linters
Confirmed with:
$ make lint
...
INFO [lintersdb] Active 11 linters: [deadcode gofmt gosec gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]
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 wanted to complement with some info:
As a matter of fact in the official golangci-lint documentation the go install github.com/golangci/golangci-lint/cmd/golangci-lint@<version>
is the advised best approach.
Some things I think we should tackle nevertheless:
- Having the tools versioning in
tools.go
or inmake install-tools
sounds good to me, but I think that it would be simpler/clearer if we pick one instead of using a hybrid approach (some tools versioned ingo.mod
and others explicitly specified in theinstall-tools
). This is why earlier I suggested deleting thetools.go
. In the context of this PR I suggest we only do a cleanup and follow up on actions 3 and 4 below. To be completely honest I have a preference to handle the tool dependencies outside ofgo.mod
because the fact that we are using onlygo
tools is incidental and I think it makes more sense to centralize the tooling dependency in a language-agnostic place (like themake install-tools
target). - Even if you choose to keep the
tools.go
we do not need to declaregosec
andstaticcheck
as those are indirect dependencies ofgolangci-lint
and will be taken care of byinstall-tools
target. - (to be done in separate PR)
https://github.com/wadey/gocovmerge
last commit was in 2016 - I would consider either:- vendoring it
- copying it to this repository
- since the script is very simple, create our own version and maintain it in the scope of this repo
- (to be done in separate PR) considering to upgrade
mockery
to v2.
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 thought we don't need gocovmerge anymore since we no longer test pkg by 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.
I think you are absolutely right :)
I have updated the PR.
pkg/es/wrapper/wrapper_nolint.go
Outdated
@@ -16,9 +16,6 @@ package eswrapper | |||
|
|||
import "github.com/jaegertracing/jaeger/pkg/es" | |||
|
|||
// Some of the functions of elastic.BulkIndexRequest violate golint rules, | |||
// e.g. Id() should be ID() and BodyJson() should be BodyJSON(). | |||
|
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 feels like the relevant comment that explains the need for this file.
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.
please restore the comment
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 did it already
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 still shows as deleted in the latest version of PR
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.
my bad. Updated now
@@ -19,11 +19,8 @@ package jaeger | |||
|
|||
// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module | |||
import ( | |||
_ "honnef.co/go/tools/cmd/staticcheck" |
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 used in our current configuration of golangci-lint
or in any other form
_ "github.com/mjibson/esc" | ||
_ "github.com/securego/gosec/cmd/gosec" |
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.
indirect dependency of golangci-lint
will be naturally included in go.mod
as indirect dependency.
@@ -409,12 +410,8 @@ generate-zipkin-swagger: init-submodules | |||
$(SWAGGER) generate server -f ./idl/swagger/zipkin2-api.yaml -t $(SWAGGER_GEN_DIR) -O PostSpans --exclude-main | |||
rm $(SWAGGER_GEN_DIR)/restapi/operations/post_spans_urlbuilder.go $(SWAGGER_GEN_DIR)/restapi/server.go $(SWAGGER_GEN_DIR)/restapi/configure_zipkin.go $(SWAGGER_GEN_DIR)/models/trace.go $(SWAGGER_GEN_DIR)/models/list_of_traces.go $(SWAGGER_GEN_DIR)/models/dependency_link.go | |||
|
|||
.PHONY: install-mockery |
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 took the liberty to merge all the tools installation into a single make target. makes sense?
I tend to agree, this went into the wrong direction, we don't want to be tracking so many dependencies. I think we should go back to installing golang-ci via explicit version and not list it in the tools.go Question, however: when we install golang-ci directly, not via go.mod, (a) does it auto-install all other required tools, and (b) does it manage their versions or always gets the latest? |
Yes, that's my understanding. To test it, I removed by
My understanding is that it manages their versions:
is consistent with golangci-lint v1.42.0's (the tag version we're installing in Makefile's Switching to golangci-lint's master branch, we see this dependency version has been upgraded:
|
golint has been deprecated and is no longer used in this repository. Eliminating the useless import in the tools.go. Signed-off-by: rbroggi <[email protected]>
* Uniform the tool dependency handling by delegating it to the `go.mod` file * Using `tools.go` to import all the *direct* tools dependencies * Centralizing the installation of dependencies in a single make target * Eliminating explicit dependency from `gosec` as it's a transitive dependency of `golangci-lint` Signed-off-by: rbroggi <[email protected]>
Signed-off-by: rbroggi <[email protected]>
Signed-off-by: rbroggi <[email protected]>
Signed-off-by: rbroggi <[email protected]>
Signed-off-by: rbroggi <[email protected]>
golint
import
Short description of the changes
golint has been deprecated and is no longer used in this repository. Eliminating the useless import in the tools.go.
Signed-off-by: rbroggi [email protected]