Skip to content

Commit

Permalink
Apply monitoring linters (#447)
Browse files Browse the repository at this point in the history
* Apply monitoringlinter

Apply monitoringlinter, which is designed to enforce
kubevirt/community#219 by ensuring that monitoring-related practices are
implemented within the pkg/monitoring directory using
operator-observability methods.

Signed-off-by: assafad <aadmi@redhat.com>

* Apply operator-observability rules linter

Apply operator-observability rules linter which ensures that kubevirt
alerts and recording rules definitions are following the monitoring best
practices.

Signed-off-by: assafad <aadmi@redhat.com>

---------

Signed-off-by: assafad <aadmi@redhat.com>
  • Loading branch information
assafad authored Mar 25, 2024
1 parent a068af5 commit 78ba2f3
Show file tree
Hide file tree
Showing 18 changed files with 3,109 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ test:
lint-metrics:
./hack/prom_metric_linter.sh --operator-name="kubevirt" --sub-operator-name="hpp"

lint-monitoring:
go install github.com/kubevirt/monitoring/monitoringlinter/cmd/monitoringlinter@e2be790
monitoringlinter ./...

generate-doc: build-docgen
_out/metricsdocs > docs/metrics.md

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gosuri/uitable v0.0.1/go.mod h1:tKR86bXuXPZazfOTG1FIzvjIdXzd0mo4Vtn16vt0PJo=
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd h1:PpuIBO5P3e9hpqBD0O/HjhShYuM6XE0i/lbE6J94kww=
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
Expand Down
1 change: 1 addition & 0 deletions hack/run-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ source "${script_dir}"/common.sh
go version
# Validate
make lint-metrics
make lint-monitoring
make generate-doc
git difftool -y --trust-exit-code --extcmd=./hack/diff-csv.sh

Expand Down
42 changes: 42 additions & 0 deletions pkg/monitoring/rules/rules_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package rules

import (
"testing"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"

"github.com/machadovilaca/operator-observability/pkg/testutil"
)

func TestRules(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Rules Suite")
}

var _ = ginkgo.Describe("Rules Validation", func() {
var linter *testutil.Linter

ginkgo.BeforeEach(func() {
gomega.Expect(SetupRules("")).To(gomega.Succeed())
linter = testutil.New()
})

ginkgo.It("Should validate alerts", func() {
linter.AddCustomAlertValidations(
testutil.ValidateAlertNameLength,
testutil.ValidateAlertRunbookURLAnnotation,
testutil.ValidateAlertHealthImpactLabel,
testutil.ValidateAlertPartOfAndComponentLabels)

alerts := ListAlerts()
problems := linter.LintAlerts(alerts)
gomega.Expect(problems).To(gomega.BeEmpty())
})

ginkgo.It("Should validate recording rules", func() {
recordingRules := ListRecordingRules()
problems := linter.LintRecordingRules(recordingRules)
gomega.Expect(problems).To(gomega.BeEmpty())
})
})
15 changes: 15 additions & 0 deletions vendor/github.com/grafana/regexp/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/github.com/grafana/regexp/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/grafana/regexp/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 78ba2f3

Please sign in to comment.