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 19, 2024
1 parent 107e779 commit 8f57722
Show file tree
Hide file tree
Showing 17 changed files with 3,106 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ require (
github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2c
github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.2/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/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
Expand Down
4 changes: 4 additions & 0 deletions pkg/monitoring/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func BuildPrometheusRule(namespace string) (*promv1.PrometheusRule, error) {
)
}

func ListAlerts() []promv1.Rule {
return operatorrules.ListAlerts()
}

func ListRecordingRules() []operatorrules.RecordingRule {
return operatorrules.ListRecordingRules()
}
40 changes: 40 additions & 0 deletions pkg/monitoring/rules/rules_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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)

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

It("Should validate recording rules", func() {
problems := linter.LintRecordingRules(ListRecordingRules())
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.

Loading

0 comments on commit 8f57722

Please sign in to comment.