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

Replace old linters with golangci-lint #3237

Merged
merged 12 commits into from
Sep 2, 2021

Conversation

albertteoh
Copy link
Contributor

Which problem is this PR solving?

Short description of the changes

  • Replaces our existing lint checks with golangci-lint.
  • Goal is to achieve parity (wrt linters) with the existing checks and minimal code changes. If we wish to include more linters, it's a straightforward config change.

Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
@codecov
Copy link

codecov bot commented Aug 29, 2021

Codecov Report

Merging #3237 (8b3a050) into master (fb4be5d) will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3237      +/-   ##
==========================================
- Coverage   95.99%   95.95%   -0.05%     
==========================================
  Files         242      242              
  Lines       14813    14813              
==========================================
- Hits        14220    14214       -6     
- Misses        514      519       +5     
- Partials       79       80       +1     
Impacted Files Coverage Δ
cmd/flags/admin.go 82.81% <ø> (ø)
cmd/collector/app/server/zipkin.go 68.29% <0.00%> (-2.44%) ⬇️
cmd/query/app/static_handler.go 95.80% <0.00%> (-1.80%) ⬇️
...lugin/sampling/strategystore/adaptive/processor.go 99.35% <0.00%> (-0.65%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb4be5d...8b3a050. Read the comment docs.

Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
Comment on lines -35 to -36
healthCheckHTTPPort = "health-check-http-port"
adminHTTPPort = "admin-http-port"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused and deprecated here.

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please let me know if there are issues with moving to "google.golang.org/protobuf/proto", and I can revert back and add a //nolint directive. Tests appear to still be passing with this change.

@@ -35,12 +35,7 @@ GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOBUILD=CGO_ENABLED=0 installsuffix=cgo go build -trimpath
GOTEST=go test -v $(RACE)
GOLINT=golint
Copy link
Contributor Author

@albertteoh albertteoh Aug 29, 2021

Choose a reason for hiding this comment

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

golint, go vet and gosec should no longer be needed as golangci-lint provides these linters, so I'm removing them from the Makefile to simplify.

Comment on lines +14 to +15
- G104
- G107
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These gosec rules were excluded in the Makefile, so I did the same.

Comment on lines +16 to +17
- G404
- G601
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These gosec rules were not excluded in the Makefile, but were identified, giving the errors:

cmd/collector/app/sanitizer/cache/auto_refresh_cache.go:136:40: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
	return (interval / 2) + time.Duration(rand.Int63n(int64(interval/2)))
	                                      ^
crossdock/services/tracehandler.go:308:27: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
	return fmt.Sprintf("%x", rand.Int63())
	                         ^
cmd/ingester/app/processor/decorator/retry.go:54:18: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
	rand:           rand.New(rand.NewSource(time.Now().UnixNano())),
	                ^
model/converter/thrift/jaeger/from_domain.go:106:37: G601: Implicit memory aliasing in for loop. (gosec)
		jaegerTags[idx] = d.keyValueToTag(&kv)
		                                  ^
cmd/anonymizer/main.go:72:22: G601: Implicit memory aliasing in for loop. (gosec)
				writer.WriteSpan(&span)

I've excluded them for now, but if there is a preference to address these rules in this PR, I can do so.

Copy link
Member

Choose a reason for hiding this comment

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

let's fix them in another PR

@@ -22,9 +22,15 @@ jobs:
- name: Run unit tests
run: make test-ci

- name: golangci-lint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up placing the lint step within the unit-tests, which is similar behaviour to the Makefile. However, I feel it would be nicer as a separate job in order to enable concurrency, but am getting errors relating to undefined types. Oddly, testing on my fork doesn't have this issue.

I believe it's the same config as is with #2602 and does not appear to have encountered this problem. Maybe @daxmc99 has some ideas about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be worth noting that (I think) those "undefined" errors could be due to not having run go build on jaeger, which explains why moving this step as part of the unit tests job works.

@albertteoh albertteoh marked this pull request as ready for review August 29, 2021 13:17
@albertteoh albertteoh requested a review from a team as a code owner August 29, 2021 13:17
@albertteoh albertteoh changed the title Golangci lint Replace old linters with golangci-lint Aug 29, 2021
$(MAKE) go-lint
@echo Running go fmt on ALL_SRC ...
@$(GOFMT) -e -s -l $(ALL_SRC) > $(FMT_LOG)
./scripts/updateLicenses.sh >> $(FMT_LOG)
Copy link
Member

Choose a reason for hiding this comment

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

This must remain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, I've added this back into the lint target. Tested by removing the license from grpc_handler.go:

$ make lint
golangci-lint run
./scripts/updateLicenses.sh > .fmt.log
License check failures, run 'make fmt'
cmd/collector/app/handler/grpc_handler.go
make: *** [lint] Error 1

Makefile Show resolved Hide resolved
Makefile Outdated

.PHONY: install-ci
install-ci: install-tools

.PHONY: test-ci
test-ci: build-examples lint cover
test-ci: build-examples cover
Copy link
Member

Choose a reason for hiding this comment

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

I would consider killing this target and invoking directly in GA

Copy link
Member

Choose a reason for hiding this comment

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

I like a minimal CI configuration. I want to be able to easily replicate locally what CI is doing - e.g. run the same make target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, I agree that it's a better developer experience if the CI scripts can be traced down to the make target then "replayed" locally, which a GA step doesn't afford.

As such, I've removed the GA step to run golangci-lint and kept the original setup where the test-ci target will run the lint target. Fewer changes, and cleaner.

Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
go install github.com/mjibson/esc
go install github.com/securego/gosec/cmd/gosec
go install honnef.co/go/tools/cmd/staticcheck
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add this to the tools so CI is able to run golangci-lint, and ensure devs also have the right tools installed to test linting.

- G404
- G601
gosimple:
go: "1.17"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bumped the go version since we've moved onto 1.17 already.

@albertteoh
Copy link
Contributor Author

Please let me know if there are any issues that still need addressing.

yurishkuro
yurishkuro previously approved these changes Sep 2, 2021
Makefile Outdated
@echo Running go lint...
@$(GOLINT) $(ALL_PKGS) | grep -v _nolint.go >> $(LINT_LOG) || true;
@[ ! -s "$(LINT_LOG)" ] || (echo "Lint Failures" | cat - $(LINT_LOG) && false)
@[ ! -s "$(FMT_LOG)" -a ! -s "$(IMPORT_LOG)" ] || (echo "License check or import ordering failures, run 'make fmt'" | cat - $(FMT_LOG) && false)
Copy link
Member

Choose a reason for hiding this comment

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

This does not print import_log

Copy link
Contributor Author

@albertteoh albertteoh Sep 2, 2021

Choose a reason for hiding this comment

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

Addressed in 8b3a050

Signed-off-by: Albert Teoh <see.kwang.teoh@gmail.com>
Comment on lines +16 to +17
- G404
- G601
Copy link
Member

Choose a reason for hiding this comment

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

let's fix them in another PR

@yurishkuro yurishkuro merged commit 27fe841 into jaegertracing:master Sep 2, 2021
@albertteoh
Copy link
Contributor Author

thanks for the review Yuri/Pavol! 🙏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants