Skip to content

Commit

Permalink
Apply monitoring linters (#2827)
Browse files Browse the repository at this point in the history
* 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>

* Apply monitoringlinter

Apply monitoringlinter, which is designed to ensure that in Kubernetes
operator projects, monitoring-related practices are implemented within
the pkg/monitoring directory using operator-observability methods.

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

---------

Signed-off-by: assafad <aadmi@redhat.com>
  • Loading branch information
assafad authored Mar 19, 2024
1 parent ee361d4 commit a190ef5
Show file tree
Hide file tree
Showing 28 changed files with 3,162 additions and 115 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DO=eval
export JOB_TYPE=prow
endif

sanity: generate generate-doc validate-no-offensive-lang goimport lint-metrics
sanity: generate generate-doc validate-no-offensive-lang goimport lint-metrics lint-monitoring
go version
go fmt ./...
go mod tidy -v
Expand Down Expand Up @@ -233,6 +233,10 @@ validate-no-offensive-lang:
lint-metrics:
./hack/prom_metric_linter.sh --operator-name="kubevirt" --sub-operator-name="hco"

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

.PHONY: start \
clean \
build \
Expand Down Expand Up @@ -279,5 +283,6 @@ lint-metrics:
generate-doc \
validate-no-offensive-lang \
lint-metrics \
lint-monitoring \
sanity \
goimport
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/google/uuid v1.6.0
github.com/kubevirt/cluster-network-addons-operator v0.91.0
github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20240125201600-b689e9c89409
github.com/machadovilaca/operator-observability v0.0.13
github.com/machadovilaca/operator-observability v0.0.16
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.1
github.com/openshift/api v3.9.1-0.20190517100836-d5b34b957e91+incompatible
Expand Down Expand Up @@ -66,6 +66,7 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
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/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
Expand All @@ -135,8 +137,8 @@ github.com/kubevirt/cluster-network-addons-operator v0.91.0 h1:FyigSFOEVJ7eX5uzc
github.com/kubevirt/cluster-network-addons-operator v0.91.0/go.mod h1:PywaJQjkV9RNroC5pKNbPuA0dhUlCW1zl/OcJhEWVKI=
github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20240125201600-b689e9c89409 h1:w+MkYRwdxddjNwR7BbNMWP24wVli/G6zna86wfbhiAk=
github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20240125201600-b689e9c89409/go.mod h1:qGj2agzgwQ27nYhP3xhLs+IBzE5+ALNUg8bDfMcwPqo=
github.com/machadovilaca/operator-observability v0.0.13 h1:9mhxEjkdE6pcl3ke8chbbAWxx25+K1m4Gq31yo+r2JU=
github.com/machadovilaca/operator-observability v0.0.13/go.mod h1:e4Z3VhOXb9InkmSh00JjqBBijE+iD+YMzynBpKB3+gE=
github.com/machadovilaca/operator-observability v0.0.16 h1:Pjeu8DlyoM7AS/M5kumBExe7ES/cXqo9MttyQlEZx0Q=
github.com/machadovilaca/operator-observability v0.0.16/go.mod h1:e4Z3VhOXb9InkmSh00JjqBBijE+iD+YMzynBpKB3+gE=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
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) {
RegisterFailHandler(Fail)
RunSpecs(t, "Rules Suite")
}

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

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

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

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

It("Should validate recording rules", func() {
recordingRules := ListRecordingRules()
problems := linter.LintRecordingRules(recordingRules)
Expect(problems).To(BeEmpty())
})
})
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.3.0 // indirect
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 // indirect
github.com/machadovilaca/operator-observability v0.0.13 // indirect
github.com/machadovilaca/operator-observability v0.0.16 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
Expand Down
4 changes: 2 additions & 2 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 h1:nHHjmvjitIiyP
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0/go.mod h1:YBCo4DoEeDndqvAn6eeu0vWM7QdXmHEeI9cFWplmBys=
github.com/kubevirt/cluster-network-addons-operator v0.91.0 h1:FyigSFOEVJ7eX5uzc1bpZRAbrKh08Yd0MLfQ20eUMH0=
github.com/kubevirt/cluster-network-addons-operator v0.91.0/go.mod h1:PywaJQjkV9RNroC5pKNbPuA0dhUlCW1zl/OcJhEWVKI=
github.com/machadovilaca/operator-observability v0.0.13 h1:9mhxEjkdE6pcl3ke8chbbAWxx25+K1m4Gq31yo+r2JU=
github.com/machadovilaca/operator-observability v0.0.13/go.mod h1:e4Z3VhOXb9InkmSh00JjqBBijE+iD+YMzynBpKB3+gE=
github.com/machadovilaca/operator-observability v0.0.16 h1:Pjeu8DlyoM7AS/M5kumBExe7ES/cXqo9MttyQlEZx0Q=
github.com/machadovilaca/operator-observability v0.0.16/go.mod h1:e4Z3VhOXb9InkmSh00JjqBBijE+iD+YMzynBpKB3+gE=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
Expand Down

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

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

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

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

2 changes: 1 addition & 1 deletion tests/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ github.com/kubevirt/hyperconverged-cluster-operator/api/v1beta1
github.com/kubevirt/hyperconverged-cluster-operator/controllers/common
github.com/kubevirt/hyperconverged-cluster-operator/pkg/monitoring/metrics
github.com/kubevirt/hyperconverged-cluster-operator/pkg/util
# github.com/machadovilaca/operator-observability v0.0.13
# github.com/machadovilaca/operator-observability v0.0.16
## explicit; go 1.21
github.com/machadovilaca/operator-observability/pkg/operatormetrics
# github.com/mailru/easyjson v0.7.7
Expand Down
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 a190ef5

Please sign in to comment.