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 to ensure kubevirt
alerts and recording rules definitions are following monitoring best
practices.

Signed-off-by: aadmi <aadmi@redhat.com>
  • Loading branch information
assafad committed Apr 10, 2024
1 parent 008b8f1 commit 9c59fe5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
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",
],
)
27 changes: 27 additions & 0 deletions pkg/monitoring/rules/rules_suite_test.go
@@ -0,0 +1,27 @@
/*
Copyright 2024 The KubeVirt Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package rules

import (
"testing"

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

func TestRules(t *testing.T) {
testutils.KubeVirtTestSuiteSetup(t)
}
51 changes: 51 additions & 0 deletions pkg/monitoring/rules/rules_test.go
@@ -0,0 +1,51 @@
/*
Copyright 2024 The KubeVirt Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

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())
})
})

0 comments on commit 9c59fe5

Please sign in to comment.