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

Move to golangci-lint #1853

Merged
merged 10 commits into from
Jan 8, 2020
Merged

Move to golangci-lint #1853

merged 10 commits into from
Jan 8, 2020

Conversation

bboreham
Copy link
Contributor

This is faster and does more checks.

  • Remove home-grown lint script.
  • Install the golangci-lint binary in the build container.
  • Remove individual tools gocyclo, golint, errcheck which are included in golangci-lint.

Run in --new-from-rev mode so it doesn't fail the build on a bunch of warnings that were pre-existing.

Still running go vet separately because I couldn't see that the vet tool inside golangci-lint is the same thing.

Also run misspell specifically on the docs because golangci-lint only does *.go.

Also remove a couple of unnecessary steps from the build image.

Copy link
Contributor

@khaines khaines left a comment

Choose a reason for hiding this comment

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

I've seen the golangci tools used in other projects, so if it improves our build process in this project, i'm all for it!

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

LGTM, love golangci-lint

go vet -stdmethods=false ./pkg/...
go vet -tags netgo -stdmethods=false ./pkg/...
misspell -error docs
golangci-lint run --new-from-rev ed7c302fd968 --build-tags netgo --timeout=5m --enable golint --enable misspell --enable gofmt
Copy link
Contributor

Choose a reason for hiding this comment

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

This is particularly slow when running on OSX (with Docker for Mac) due to the shared volumes performances. Do you see any problem adding :delegated to the 3 related volumes, switching

	@$(SUDO) time docker run $(RM) $(TTY) -i \
		-v $(shell pwd)/.cache:/go/cache \
		-v $(shell pwd)/.pkg:/go/pkg \
		-v $(shell pwd):/go/src/github.com/cortexproject/cortex \
		$(BUILD_IMAGE) $@;

to

	@$(SUDO) time docker run $(RM) $(TTY) -i \
		-v $(shell pwd)/.cache:/go/cache:delegated \
		-v $(shell pwd)/.pkg:/go/pkg:delegated \
		-v $(shell pwd):/go/src/github.com/cortexproject/cortex:delegated \
		$(BUILD_IMAGE) $@;

In my case, the execution time difference is:

  • Current: 8m8.369s
  • With delegated: 1m38.258s

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does :delegated do?
Would we want it on all similar lines?

Copy link
Contributor

Choose a reason for hiding this comment

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

What does :delegated do?

The :delegated tells Docker for Mac that the container’s view is authoritative (permit delays before updates on the container appear in the host). Details here: https://docs.docker.com/docker-for-mac/osxfs-caching/

I don't have a Linux box right now to play with, but it should just be ignored on Linux.

Would we want it on all similar lines?

I would say yes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered adding :delegated to volume mounts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have done this now.

Makefile Outdated
# -stdmethods=false disables checks for non-standard signatures for methods with familiar names.
# This is needed because the Prometheus storage interface requires a non-standard Seek() method.
go vet -stdmethods=false ./pkg/...
go vet -tags netgo -stdmethods=false ./pkg/...
Copy link
Contributor

Choose a reason for hiding this comment

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

I think go vet is on by default. We use it on Loki.

govet (vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: true, auto-fix: false]

see https://github.com/golangci/golangci-lint#quick-start

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 did this test: change a printf format string to invalid, e.g. %i.
I get a warning from go vet but not from golangci-lint.
So I am un-convinced.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting I have the same issue in loki but if I ran it for the specific package it works. Tried to clean my cache also using golangci-lint cache clean.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is failing golangci-lint run -v ./pkg/querier/queryrange

but not

golangci-lint run -v ./...

Copy link
Contributor

Choose a reason for hiding this comment

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

Found the issue on Loki side, one file was producing warning.

WARN [runner] Can't run linter goanalysis_metalinter: misspell: can't get file /Users/ctovena/go/src/github.com/grafana/loki/pkg/logql/pkg/logql/expr.y contents: can't read file /Users/ctovena/go/src/github.com/grafana/loki/pkg/logql/pkg/logql/expr.y: open /Users/ctovena/go/src/github.com/grafana/loki/pkg/logql/pkg/logql/expr.y: no such file or directory

This was caused by a comment //line expr.y, I cleanup the file and it now catches %i in fmt.

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI it was also causing some linter to be skipped.

Copy link
Contributor

Choose a reason for hiding this comment

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

You have the same kind of warning.

WARN [runner] Can't run linter goanalysis_metalinter: fact_purity: failed prerequisites: [email protected]/cortexproject/cortex/pkg/chunk [github.com/cortexproject/cortex/pkg/chunk/cache.test] 

Not sure why the exit code is not 1.

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 found various issues relating to this - golangci/golangci-lint#866, golangci/golangci-lint#827

@bboreham
Copy link
Contributor Author

I'm now running make lint twice in an attempt to work around golangci/golangci-lint#866, golangci/golangci-lint#827

Once I do that I am reassured that it does indeed run go vet so have taken that out of our commands.

@bboreham
Copy link
Contributor Author

Rebased and we have a bunch of lint failures from code added since I started this PR!

I wonder if we should disable the return value check on log calls (or everywhere)?

@pracucci
Copy link
Contributor

I wonder if we should disable the return value check on log calls (or everywhere)?

My personal take:

  • Definitely disable it for log calls
  • I still see a value for other use cases (errors should be checked/handled)

This is faster and does more checks.

* Remove home-grown `lint` script.
* Install the `golangci-lint` binary in the build container.
* Remove individual tools `gocyclo`, `golint`, `errcheck` which are included in `golangci-lint`.
* golangci-lint also runs go vet so we don't need to.

Run in `--new-from-rev` mode so it doesn't fail the build on a bunch
of warnings that were pre-existing.

Also run `misspell` specifically on the docs because `golangci-lint`
only does `*.go`.

Signed-off-by: Bryan Boreham <[email protected]>
Go caches builds for different tags now, so we don't need to pre-build them.

We don't use `dep` any more.

Signed-off-by: Bryan Boreham <[email protected]>
Signed-off-by: Bryan Boreham <[email protected]>
Signed-off-by: Bryan Boreham <[email protected]>
@bboreham
Copy link
Contributor Author

I figured out how to disable errcheck on individual methods.

@pracucci
Copy link
Contributor

@bboreham What's the state of this PR? Is there anything missing?

@bboreham
Copy link
Contributor Author

bboreham commented Jan 3, 2020

Ideally it would get an approval after the latest set of changes.

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

LGTM X2

@bboreham bboreham merged commit 5528d67 into master Jan 8, 2020
@bboreham bboreham deleted the update-lint branch January 8, 2020 16:33
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.

5 participants