Skip to content

Commit

Permalink
Add operator-observability rules unit test
Browse files Browse the repository at this point in the history
Add rules unit test, which ensures that alerts and recording rules
definitions are following conventions.

Signed-off-by: assafad <aadmi@redhat.com>
  • Loading branch information
assafad committed Mar 28, 2024
1 parent 9bdc857 commit a67a78a
Show file tree
Hide file tree
Showing 17 changed files with 3,110 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -122,6 +122,7 @@ require (
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/h2non/filetype v1.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -862,6 +862,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gosuri/uitable v0.0.4 h1:IG2xLKRvErL3uhY6e1BylFzG+aJiwQviDDTfOKeKTpY=
github.com/gosuri/uitable v0.0.4/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-20190203031600-7a902570cb17 h1:prg2TTpTOcJF1jRWL2zSU1FQNgB0STAFNux8GK82y8k=
github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
Expand Down
13 changes: 13 additions & 0 deletions pkg/monitoring/rules/rules_suite_test.go
@@ -0,0 +1,13 @@
package rules

import (
"testing"

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

func TestRules(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Rules Suite")
}
35 changes: 35 additions & 0 deletions pkg/monitoring/rules/rules_test.go
@@ -0,0 +1,35 @@
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() {
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())
})
})
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.

0 comments on commit a67a78a

Please sign in to comment.