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

forbiddenmethod: add (disabled) lint against (*errgroup.Group).Go and go #62243

Merged
merged 1 commit into from
May 6, 2021

Conversation

tbg
Copy link
Member

@tbg tbg commented Mar 19, 2021

This helps move the needle on #58164 by introducing linters that
force both the use of a ctxgroup over an errgroup and prevent
direct use of the go keyword.

They are disabled by default because we need to fix the issues they
find first. This can be done (for development) in
forbiddenmethod.Analyzers. They can then also be invoked in a targeted
fashion:

go vet -vettool ./bin/roachvet -errgroupgo ./pkg/somewhere
go vet -vettool ./bin/roachvet -nakedgo ./pkg/somewhere

Release note: None

@tbg tbg requested review from a team and erikgrinaker and removed request for a team March 19, 2021 10:34
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

:lgtm: but I wonder if we maybe should exclude internal tooling such as roachprod and workload where this isn't really a concern.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 7 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @tbg)

@tbg tbg changed the title forbiddenmethod: lint against (*errgroup.Group).Go and go forbiddenmethod: add (disabled) lint against (*errgroup.Group).Go and go Mar 19, 2021
@tbg
Copy link
Member Author

tbg commented Mar 19, 2021

Thanks for the quick reviews! I have some WIP to actually fix a bunch of the lint failures but figured it was better to merge this as-is first, with the lints there but not part of make lint.

I also finally figured out how to make the //nolint:nakedgo thing work, PTAL.

@tbg tbg requested a review from erikgrinaker March 19, 2021 16:50
Copy link
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

This is awesome, LGTM!

Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 5 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz and @tbg)


pkg/testutils/lint/lint_test.go, line 2006 at r2 (raw file):

		nakedGoroutineExceptions := `(` + strings.Join([]string{
			`pkg/.*_test.go`,

Escape the ..


pkg/testutils/lint/passes/forbiddenmethod/naked_go.go, line 46 at r2 (raw file):

			// The approach here is inspired by `analysistest.check` - the
			// nolint comment has to be on the same line as the *end* of the
			// `*GoStmt`.

Hm, this is a bit unfortunate -- for inline large-body goroutines it'd be most natural to put the nolint above it. Although I suppose we won't be using a whole lot of go keywords anyway, so maybe it's ok if the ergonomics are a bit off. Happy to have an escape hatch at all!


pkg/testutils/lint/passes/forbiddenmethod/naked_go.go, line 67 at r2 (raw file):

				}
			}
			if cc != nil && strings.Contains(cc.Text, "nolint:"+nakedGoPassName) {

This won't handle comma-separated components, but maybe that's ok.

@tbg tbg requested review from erikgrinaker and knz April 30, 2021 13:27
Copy link
Member Author

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @erikgrinaker and @knz)


pkg/testutils/lint/lint_test.go, line 2006 at r2 (raw file):

Previously, erikgrinaker (Erik Grinaker) wrote…

Escape the ..

Done.


pkg/testutils/lint/passes/forbiddenmethod/naked_go.go, line 46 at r2 (raw file):

Previously, erikgrinaker (Erik Grinaker) wrote…
			// The approach here is inspired by `analysistest.check` - the
			// nolint comment has to be on the same line as the *end* of the
			// `*GoStmt`.

Hm, this is a bit unfortunate -- for inline large-body goroutines it'd be most natural to put the nolint above it. Although I suppose we won't be using a whole lot of go keywords anyway, so maybe it's ok if the ergonomics are a bit off. Happy to have an escape hatch at all!

I'll leave as is - I agree, but also it's not easy to make these things happen and as you noted possibly not worth it.


pkg/testutils/lint/passes/forbiddenmethod/naked_go.go, line 67 at r2 (raw file):

Previously, erikgrinaker (Erik Grinaker) wrote…

This won't handle comma-separated components, but maybe that's ok.

It will, you just have to say nolint:foo,nolint:bar but also, hopefully these never need to stack and if so, I'd rather spend time fixing it when the time comes.

Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 7 files at r1, 2 of 5 files at r2, 1 of 1 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @tbg)

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 5 files at r2, 1 of 1 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @tbg)


pkg/testutils/lint/lint_test.go, line 2033 at r3 (raw file):

			`pkg/workload/`,
			`pkg/cli/systembench/`,
			`pkg/cmd/roachprod/`,

Feels to me like anything under /pkg/cmd can be ignored

@tbg tbg requested a review from knz April 30, 2021 15:56
Copy link
Member Author

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Thanks for the reviews! Going to shake out any remaining lint failures and merge.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz)


pkg/testutils/lint/lint_test.go, line 2033 at r3 (raw file):

Previously, knz (kena) wrote…

Feels to me like anything under /pkg/cmd can be ignored

Maybe, but once we hang correctness guarantees of this lint I don't know if we want to take any chances. And definitely roachtest will want this hygiene too (since it needs to recover from all panics in the subtests) and that too sits fully in cmd right now. I'll leave as is and we can revisit.

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @tbg)


pkg/testutils/lint/lint_test.go, line 2033 at r3 (raw file):

Previously, tbg (Tobias Grieger) wrote…

Maybe, but once we hang correctness guarantees of this lint I don't know if we want to take any chances. And definitely roachtest will want this hygiene too (since it needs to recover from all panics in the subtests) and that too sits fully in cmd right now. I'll leave as is and we can revisit.

no objection from me - my approval stands.

…nd `go`

This helps move the needle on cockroachdb#58164 by introducing linters that
force both the use of a `ctxgroup` over an `errgroup` and prevent
direct use of the `go` keyword.

They are disabled by default because we need to fix the issues they
find first. This can be done (for development) in
`forbiddenmethod.Analyzers`. They can then also be invoked in a targeted
fashion:

```
go vet -vettool ./bin/roachvet -errgroupgo ./pkg/somewhere
go vet -vettool ./bin/roachvet -nakedgo ./pkg/somewhere
```

Release note: None
@tbg tbg force-pushed the go-prevent-it branch from c9c514c to 6d69977 Compare May 6, 2021 09:56
@tbg
Copy link
Member Author

tbg commented May 6, 2021

bors r=knz,erikgrinaker,jordanlewis

@craig
Copy link
Contributor

craig bot commented May 6, 2021

Build succeeded:

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