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

Add monitoring linter #221

Merged
merged 1 commit into from Mar 4, 2024
Merged

Add monitoring linter #221

merged 1 commit into from Mar 4, 2024

Conversation

assafad
Copy link
Collaborator

@assafad assafad commented Feb 20, 2024

What this PR does / why we need it:

Monitoring Linter is a Golang linter designed to ensure that in Kubernetes operator projects,
monitoring-related practices are implemented within the pkg/monitoring directory using operator-observability methods. It verifies that all metrics, alerts and recording rules registrations are centralized in this directory.
The use of Prometheus registration methods is restricted across the entire project.

Fixes https://issues.redhat.com/browse/CNV-36760.

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note:

None

@kubevirt-bot kubevirt-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Feb 20, 2024
@assafad assafad marked this pull request as draft February 20, 2024 17:27
@assafad assafad changed the title [WIP] Monitoring location linter Monitoring location linter Feb 20, 2024
@assafad assafad force-pushed the monitoring-linter branch 6 times, most recently from a53ab94 to 0cde6e3 Compare February 20, 2024 18:33
Copy link
Collaborator

@nunnatsa nunnatsa left a comment

Choose a reason for hiding this comment

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

Did preliminary quick review. Added some comments

Copy link
Member

@machadovilaca machadovilaca left a comment

Choose a reason for hiding this comment

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

just a small nit, otherwise good progress so far!

test/monitoringlocationlinter/analyzer.go Outdated Show resolved Hide resolved
@assafad assafad changed the title Monitoring location linter Add monitoring location linter Feb 26, 2024
@assafad assafad force-pushed the monitoring-linter branch 5 times, most recently from f979aef to d7d196e Compare February 26, 2024 09:32
@assafad assafad removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 26, 2024
@assafad assafad marked this pull request as ready for review February 26, 2024 09:37
Makefile Outdated Show resolved Hide resolved
test/monitoringlocationlinter/analyzer.go Outdated Show resolved Hide resolved
test/monitoringlocationlinter/analyzer.go Outdated Show resolved Hide resolved
@machadovilaca
Copy link
Member

although this is a package that executes testing, it is nonetheless a package to be distributed/imported by other projects
therefore I think it should be in cmd/ pkg/ dirs

test/monitoringlocationlinter/analyzer.go should be pkg/monitoringlocationlinter/analyzer.go
and
test/monitoringlocationlinter/cmd/monitoringlocationlinter/main.go should be cmd/monitoringlocationlinter/main.go

code in test/ should be used to test the code in the own repo cmd/, pkg/, internal/, etc... dirs

wdyt @nunnatsa?

@nunnatsa
Copy link
Collaborator

nunnatsa commented Feb 26, 2024

although this is a package that executes testing, it is nonetheless a package to be distributed/imported by other projects therefore I think it should be in cmd/ pkg/ dirs

test/monitoringlocationlinter/analyzer.go should be pkg/monitoringlocationlinter/analyzer.go and test/monitoringlocationlinter/cmd/monitoringlocationlinter/main.go should be cmd/monitoringlocationlinter/main.go

code in test/ should be used to test the code in the own repo cmd/, pkg/, internal/, etc... dirs

wdyt @nunnatsa?

It should not be in tests for sure. But I would add everything under one directory, e.g.

(and by the way, "monitoringlocationlinter" limit you to only check locations. What if you'll want to add additional rules?)

WDYT about this?

monitoringlinter/
+ -- go.mod
+ -- go.sum
+---> cmd/
          + main.go
+---> analyzer/
          +---> testdata/
                    ...
          + -- analyzer.go
          + -- analyzer_test.go

@nunnatsa
Copy link
Collaborator

@nunnatsa +1 for changing to monitoringlinter. Are you suggesting to have its dir under the root dir?

yes, new directory named monitoringlinter under the repo root dir.

@assafad assafad force-pushed the monitoring-linter branch 2 times, most recently from 89cca74 to a2911dd Compare February 26, 2024 20:04
@assafad assafad changed the title Add monitoring location linter Add monitoring linter Feb 26, 2024
@assafad
Copy link
Collaborator Author

assafad commented Feb 28, 2024

Hi @nunnatsa, @machadovilaca, can you please review again?
I updated the PR with the following changes:

  • Changed the linter name to monitoringlinter and moved its dir to the root dir, as discussed.
    I find the current linter dir structure the most convenient, but let me know if don't agree.
  • Following @machadovilaca's comment, to add checks for operator-observability packages, I changed analyzer.go, please have a look at it again.
  • Updated all required docs and tests following this changes (e.g. added unit tests and files to the testdata).

monitoringlinter/go.mod Outdated Show resolved Hide resolved
@assafad assafad force-pushed the monitoring-linter branch 2 times, most recently from 803b2d7 to 5568c13 Compare February 28, 2024 10:04
Signed-off-by: assafad <aadmi@redhat.com>
@nunnatsa
Copy link
Collaborator

nunnatsa commented Mar 4, 2024

/lgtm
/approve

@nunnatsa nunnatsa added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. labels Mar 4, 2024
@nunnatsa nunnatsa merged commit 11b8ae2 into kubevirt:main Mar 4, 2024
1 check passed
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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants