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

MON-3850: Lint CMO tests #2292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

rexagod
Copy link
Member

@rexagod rexagod commented Mar 27, 2024

Adds an explicit vet target and also integrates it into the verify flow to catch any such violations within the source code.


  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

@rexagod rexagod mentioned this pull request Mar 27, 2024
1 task
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 27, 2024
@simonpasquier
Copy link
Contributor

Hmm I can't get go vet ./... to fail on my machine :-/

@rexagod
Copy link
Member Author

rexagod commented Apr 2, 2024

Strange, are you on go1.21? I can reproduce this in a container if that's better.

Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

/lgtm

my bad, I suppose that I didn't revert the fix in pkg/client/client_test.go when checking.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 2, 2024
Copy link
Contributor

openshift-ci bot commented Apr 2, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rexagod, simonpasquier

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [rexagod,simonpasquier]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@machine424
Copy link
Contributor

How about making use of golangci's govet https://golangci-lint.run/usage/linters/ and enable it for tests? that way we're sure it'll run in CI as well.
(for now we skip all the tests

but I think we can have better filtering: we want some linters to run on tests as well)

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 23, 2024
Copy link
Contributor

openshift-ci bot commented Apr 23, 2024

New changes are detected. LGTM label has been removed.

@rexagod rexagod changed the title bugfix: add vet target bugfix: add govet linter Apr 23, 2024
@rexagod rexagod changed the title bugfix: add govet linter MON-3850: Lint CMO tests May 3, 2024
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 3, 2024
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented May 3, 2024

@rexagod: This pull request references MON-3850 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.16.0" version, but no target version was set.

In response to this:

Adds an explicit vet target and also integrates it into the verify flow to catch any such violations within the source code.


  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@@ -0,0 +1,11 @@
run:
Copy link
Contributor

Choose a reason for hiding this comment

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

How about expressing this is .golangci.yaml itself? I think we can enable linters on tests and then exclude the ones we don't want/want later under issues

Copy link
Member Author

Choose a reason for hiding this comment

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

My only concern here is that by switching to issues: from run:, we will potentially lose out on all options that the latter field offers over the former.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could switch into run: then, but for now I don't think we'll be needing any of those features. WDYT?

Copy link
Member Author

@rexagod rexagod May 14, 2024

Choose a reason for hiding this comment

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

I've pushed a commit with the proposed changes. However, I'm not sure if there's an "include-only" approach under issues: that would allow us to not duplicate the entire list across run: and issues:. I tried the following with no luck.

issues:
  exclude-rules:
# Run some linter only for test files by excluding its issues for everything else.    	
	- path-except: _test\.go
      linters:
       - govet

Also, not that we use presets, but issues: prevents us from using those as well, just thought it's worth mentioning what we are getting into with this change. I haven't resolved all the lint issues yet, but I'll hop on those once this thread resolves.

Copy link
Contributor

Choose a reason for hiding this comment

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

I, personally, have no problem with the disabled linters for tests being enumerated explicitly.
Sure, nothing is set in stone, we can always change the config to adapt to the future needs.
You don't have to fix all the linters errors for tests immediately, you can just start with govet if you want.
Gradually, we can work on reducing that list of "disabled linters for tests", although there might be some that we may never wish to activate for tests...

Copy link
Contributor

Choose a reason for hiding this comment

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

I see the golangci-lint job is failing on the govet linter for that test file now: https://prow.ci.openshift.org/view/gs/test-platform-results/pr-logs/pull/openshift_cluster-monitoring-operator/2292/pull-ci-openshift-cluster-monitoring-operator-master-golangci-lint/1796402383471775744

Can you think of any scenarios that might lead to unnoticed consistency issues? If we add a new linter in the future, we'll include it in the first list and run golang-lint. If it fails on tests, we can either fix the tests if we want to keep it enabled or add it to the second list to disable it. If the linter doesn't fail on tests, that's good and means we're checking the tests as well. If the tests change in the future in a way that breaks the linter, we will always have the option to disable the linter for them.

With versioning (git) and reviews, we'll track every change to that file and ensure that the disabling or enabling of a linter for tests is justified.

And we'll also try to Gradually, we can work on reducing that list of "disabled linters for tests", although there might be some that we may never wish to activate for tests...

Copy link
Member Author

@rexagod rexagod Jun 2, 2024

Choose a reason for hiding this comment

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

I see the golangci-lint job is failing on the govet linter for that test file now: prow.ci.openshift.org/view/gs/test-platform-results/pr-logs/pull/openshift_cluster-monitoring-operator/2292/pull-ci-openshift-cluster-monitoring-operator-master-golangci-lint/1796402383471775744

The problem is test/!.*_test.go files not being covered by the configuration.

Can you think of any scenarios that might lead to unnoticed consistency issues? [...] With versioning (git) and reviews, we'll track every change to that file and ensure that the disabling or enabling of a linter for tests is justified.

The committer needs to update two lists now, which are not independent of each other. This is only verified by the manual review process that is subject to human oversight.

If it fails on tests, we can either fix the tests if we want to keep it enabled or add it to the second list to disable it. If the linter doesn't fail on tests, that's good and means we're checking the tests as well. If the tests change in the future in a way that breaks the linter, we will always have the option to disable the linter for them.

Irrespective of linter pass or fail status, we would've added a linter to the tests without knowing about that. Imagine if a couple of linters have no problem with the tests and got in as a result of human oversight, until they do. At that point, we will be alarmed by the CI and either have to drop them or fix all the lint issues. Pragmatically, neither of these should happen, and the code, as well as its toolchain configuration, should always be in a deterministic state at all times.

We brought up the topic of the CI being flaky during the sprint review, and this change will contribute to false alarms that could have been avoided, or better handled. By "better handling", I mean if A added a linter to the first list and not the second one, and the code was merged, while implicitly enabling the linter for tests, and later on, B, while adding some new tests, encountered linter issues because of that linter. B will now have to fix the test lint issues caused by A, or bring this up with the team (if they want to drop the linter for tests, since the linter was implicitly enabled for tests, which may or may not have been the intention in the first place), creating unnecessary iterations and cycles for B.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see but I maintain my previous stance on this:

If we add a new linter in the future, we'll include it in the first list and run golang-lint. If it fails on tests, we can either fix the tests if we want to keep it enabled or add it to the second list to disable it. If the linter doesn't fail on tests, that's good and means we're checking the tests as well. If the tests change in the future in a way that breaks the linter, we will always have the option to disable the linter for them.

Additionally, as far as I understand, determinism implies that the linter should yield the same results for the same test code. Of course, if the tests change, we should expect the linter results to change as well. This doesn't only apply to tests, the same principle could apply to the rest of the codebase.

Nothing is irreversible or set in stone, we always have the option to make changes in the future. I'd prefer to keep things simple and as similar as possible to what others do. I've never seen multiple .golangci.yaml files and I don't believe our use case is different from others.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me digress a bit. WRT to the configuration being proposed, how do we enable specific linters that are only intended for tests, and not the codebase?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps issues.exclude-rules.path-except is intended for that purpose. Again, I'm not suggesting that the current configuration will meet all our needs in the future. I'm merely proposing that we start with a simple setup and make changes as necessary in the future.

@rexagod rexagod requested a review from machine424 May 13, 2024 15:17
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
.golangci.yaml Outdated
@@ -28,6 +27,7 @@ linters:
- wastedassign
- whitespace
- gci
- govet
Copy link
Contributor

Choose a reason for hiding this comment

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

govet is already enabled in line 17

.golangci.yaml Outdated
exclude-rules:
- path: _test\.go
linters:
# Only enable the following linters for test files (commented out):
Copy link
Contributor

Choose a reason for hiding this comment

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

we can remove these comments I think, the list of linters above can be the source of truth.

Makefile Outdated
@@ -195,11 +195,11 @@ go-fmt:

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT_BIN)
$(GOLANGCI_LINT_BIN) run --verbose --print-resources-usage
$(GOLANGCI_LINT_BIN) run -c .golangci.yaml --verbose --print-resources-usage
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed?

@rexagod
Copy link
Member Author

rexagod commented May 31, 2024

I think I pushed pre-maturely here (owing to testing out different configurations). I'll try #2292 (comment) on my local and update the PR.

@rexagod rexagod marked this pull request as draft May 31, 2024 04:33
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 31, 2024
@rexagod rexagod marked this pull request as ready for review May 31, 2024 04:44
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 31, 2024
@openshift-ci openshift-ci bot requested a review from simonpasquier May 31, 2024 04:45
@rexagod
Copy link
Member Author

rexagod commented May 31, 2024

Posting this here explicitly so GitHub doesn't skip past that: #2292 (comment).

Copy link
Contributor

openshift-ci bot commented May 31, 2024

@rexagod: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/versions fdab1a2 link false /test versions
ci/prow/golangci-lint fdab1a2 link true /test golangci-lint

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants