Skip to content

Commit

Permalink
Apply operator-observability rules linter
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
assafad committed Mar 6, 2024
1 parent 5fce087 commit dc1cacf
Show file tree
Hide file tree
Showing 20 changed files with 3,165 additions and 5 deletions.
3 changes: 2 additions & 1 deletion go.mod
Expand Up @@ -32,7 +32,7 @@ require (
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20230627123556-81a891d4462a
github.com/machadovilaca/operator-observability v0.0.14
github.com/machadovilaca/operator-observability v0.0.16
github.com/mdlayher/vsock v1.2.1
github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b
github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed
Expand Down Expand Up @@ -117,6 +117,7 @@ require (
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/renameio v0.1.0 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/josharian/native v1.1.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Expand Up @@ -479,6 +479,8 @@ github.com/gordonklaus/ineffassign v0.0.0-20210209182638-d0e41b2fc8ed/go.mod h1:
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
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/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/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
Expand Down Expand Up @@ -581,8 +583,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/monitoring/pkg/metrics/parser v0.0.0-20230627123556-81a891d4462a h1:cdX+oxWw1lJDS3EchP+7Oz1XbErk4r7ffVJu1b1MKgI=
github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20230627123556-81a891d4462a/go.mod h1:qGj2agzgwQ27nYhP3xhLs+IBzE5+ALNUg8bDfMcwPqo=
github.com/machadovilaca/operator-observability v0.0.14 h1:tS/GKvQRKvpD7pRauS1ulw0AN2V0j2mobg+mFWBt5LE=
github.com/machadovilaca/operator-observability v0.0.14/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/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
17 changes: 16 additions & 1 deletion pkg/monitoring/rules/BUILD.bazel
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
Expand All @@ -12,3 +12,18 @@ go_library(
"//vendor/github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = [
"rules_suite_test.go",
"rules_test.go",
],
embed = [":go_default_library"],
deps = [
"//staging/src/kubevirt.io/client-go/testutils:go_default_library",
"//vendor/github.com/machadovilaca/operator-observability/pkg/testutil:go_default_library",
"//vendor/github.com/onsi/ginkgo/v2:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
],
)
11 changes: 11 additions & 0 deletions pkg/monitoring/rules/rules_suite_test.go
@@ -0,0 +1,11 @@
package rules

import (
"testing"

"kubevirt.io/client-go/testutils"
)

func TestRules(t *testing.T) {
testutils.KubeVirtTestSuiteSetup(t)
}
38 changes: 38 additions & 0 deletions pkg/monitoring/rules/rules_test.go
@@ -0,0 +1,38 @@
package rules

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

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

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

BeforeEach(func() {
err := SetupRules("")
Expect(err).ToNot(HaveOccurred())

linter = testutil.New()
})

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

alerts := ListAlerts()
for _, alert := range alerts {
problems := linter.LintAlert(&alert)
Expect(problems).To(BeEmpty())
}
})

It("Should validate recording rules", func() {
recordingRules := ListRecordingRules()
for _, rr := range recordingRules {
problems := linter.LintRecordingRule(&rr)
Expect(problems).To(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.

14 changes: 14 additions & 0 deletions vendor/github.com/grafana/regexp/BUILD.bazel

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.

0 comments on commit dc1cacf

Please sign in to comment.