Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

More cleanups #38

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

More cleanups #38

wants to merge 11 commits into from

Conversation

krnowak
Copy link
Member

@krnowak krnowak commented May 11, 2020

This PR enables golangci-lint linter by default now. To do that I had to placate it first. Some of the ignored errors are under TODO as it wasn't clear for me what is the path forward. The CI will fail the tree is not clean after building and linting.

Other than that, I have changed that way the syscall stuff is generated. We use go generate to do it for us. One change I'm not sure about it running go generate on every build - this may trip us up during CI as the CI will likely run under a kernel that's older than the one on the developer machine.

I planned cleaning up the traceloop builder dockerfile, but apparently clang does not like the kernel headers in fedora 32, so I left that to be done later.

@krnowak
Copy link
Member Author

krnowak commented May 11, 2020

CI seems to have network problems.

Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

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

Looks good overall. A left comment about running lint for each build.

Would you mind including a target to run go generate in the Makefile? It took me a while to realize what the correct command was.

Comment on lines +95 to +97
go test -run xxxxxMatchNothingxxxxx ./... >/dev/null # check if tests build properly
./tools/golangci-lint run --fix
go mod tidy

Choose a reason for hiding this comment

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

Do we really want to run all of this when building? I think it makes more sense to have a separated target that is run by the CI and by developers when they want to check the style.

Copy link
Member Author

Choose a reason for hiding this comment

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

Linter isn't about the style/formatting only. It finds unused code, ignored errors and so on. So I prefer to run it every time. Also, it doesn't take a lot of time anyway.

Choose a reason for hiding this comment

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

My point is, if you are developing and just one to perform a quick compilation without caring about other details, should we run the lint? Won't it be too annoying to have the lint in between when you only want to compile to test a change you did?

Copy link
Member Author

Choose a reason for hiding this comment

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

It mostly wasn't annoying in my experience. We did the same in otel-go and nebraska, and it was just fine. The linter is run with the --fix flag, which tries to fix the issues it finds automatically.

The only annoyance was when there were bugs in the linter, but those get fixed rather quickly.

Choose a reason for hiding this comment

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

Ah right, it has the --fix option, it should be good then.

@krnowak
Copy link
Member Author

krnowak commented May 13, 2020

Looks good overall. A left comment about running lint for each build.

Would you mind including a target to run go generate in the Makefile? It took me a while to realize what the correct command was.

Ah, yeah. If you will see the list of commits, then you'll notice a revert commit. go generate ./... used to be called also during build to generate some of the syscall code (which is checked in into the repo, by the way), but there are two problems with it:

  • The results of the code generation is dependent on the kernel version - I have updated the code to match kernel 5.6, but the CI likely has some old kernel, so when it runs go generate it will generate a different code, which will show up with git diff, so CI will bail out at the end. Probably the solution would be ignore the differences in generated files or make the generators smarter (like don't generate if our kernel is too old or something).
  • The generators read some stuff from /sys which requires root, so they call sudo. This fails during CI. I suppose that the fix would be to drop sudo from generator and run sudo-if-not-CI go generate ./....

I haven't yet got around too fix the issues, hence I just dropped the go generate from the build for now. These scripts weren't called during build before anyway, so now we are not in a strictly worse situation.

krnowak added 11 commits May 13, 2020 14:58
golangci-lint requires a comment about blank imports. I copied a
comment from k8s client-go code.
This is to placate golangci-lint (it does not like the implicitly
ignored errors). Most of the places where we ignore errors are
suspicious, so I wrote a TODO comment there.
Seems like this functionality got moved to the scripts that should be
run as a part of the build process.
The linters should clean up the imports and the code.
It's basically the same as the default Makefile target (`all`), but it
also checks if the tree is clean after the build. This should catch an
issue when the generated files need updating, or if the code was not
properly formatted.
The scripts now take a parameter being an output file. This will make
it possible to use them in the `go:generate` comments.

We also filter out an ID line from output params - it is likely to
differ from kernel to kernel and we don't care about it.

Other than that - minor cleanups, like using \t instead of literal
tabs.
I'd say that the scripts are also the tools, so let's keep the helper
stuff in a single place.
This step was done manually, but the follow up commit will make it
automatic.
Not sure about this change - it will generate different results on
older kernels. It also may trip the CI if the CI is running on older
kernel than the developer's machine.
This reverts commit ee6fe99.

The CI doesn't like it. We will need to run go generate under sudo I
think.
@krnowak krnowak force-pushed the krnowak/lint-rest branch from 79c4ec9 to f1362b8 Compare May 13, 2020 13:03
@alban
Copy link
Member

alban commented May 13, 2020

I wonder if there is a way to get the information from the kernel sources or the kernel headers instead of /sys... That would have the benefit that the code generator could run from a container with a specific version of the kernel package installed, and that would not be dependant on the kernel used by the CI. But I agree this does not have to be fixed in this PR.

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

Successfully merging this pull request may close these issues.

3 participants