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 <[email protected]>
  • Loading branch information
assafad committed Mar 17, 2024
1 parent 04eef45 commit 9f3bb33
Show file tree
Hide file tree
Showing 139 changed files with 9,091 additions and 4,417 deletions.
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kubevirt/cluster-network-addons-operator

go 1.19
go 1.21

require (
github.com/Masterminds/sprig v2.22.0+incompatible
Expand All @@ -14,7 +14,7 @@ require (
github.com/gobwas/glob v0.2.3
github.com/google/go-github/v32 v32.1.0
github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20231024120544-6a3ba1a680b4
github.com/machadovilaca/operator-observability v0.0.7
github.com/machadovilaca/operator-observability v0.0.16
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.10
github.com/openshift/api v0.0.0
Expand All @@ -23,7 +23,7 @@ require (
github.com/openshift/origin v4.1.0+incompatible
github.com/operator-framework/operator-sdk v1.12.0
github.com/pkg/errors v0.9.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.64.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.68.0
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/common v0.44.0
github.com/spf13/pflag v1.0.5
Expand All @@ -32,11 +32,12 @@ require (
golang.org/x/tools v0.13.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.28.1
k8s.io/apiextensions-apiserver v0.28.0
k8s.io/apiextensions-apiserver v0.28.1
k8s.io/apimachinery v0.28.1
k8s.io/client-go v12.0.0+incompatible
k8s.io/helm v2.16.10+incompatible
k8s.io/kubectl v0.26.0
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
kubevirt.io/api v0.0.0-20230706190111-5527663af491
kubevirt.io/client-go v1.0.0
kubevirt.io/kubevirt v1.0.0
Expand Down Expand Up @@ -122,6 +123,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 Expand Up @@ -249,7 +251,6 @@ require (
k8s.io/kube-aggregator v0.26.3 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubernetes v1.28.1 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
kubevirt.io/containerized-data-importer-api v1.57.0-alpha1 // indirect
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
oras.land/oras-go v1.2.2 // indirect
Expand Down
80 changes: 66 additions & 14 deletions go.sum

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pkg/monitoring/rules/alerts/kubemacpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package alerts
import (
promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
)

var kubemacpoolAlerts = []promv1.Rule{
{
Alert: "KubeMacPoolDuplicateMacsFound",
Expr: intstr.FromString("kubevirt_cnao_kubemacpool_duplicate_macs != 0"),
For: "5m",
For: (*promv1.Duration)(ptr.To("5m")),
Annotations: map[string]string{
"summary": "Duplicate macs found.",
},
Expand All @@ -21,7 +22,7 @@ var kubemacpoolAlerts = []promv1.Rule{
{
Alert: "KubemacpoolDown",
Expr: intstr.FromString("kubevirt_cnao_cr_kubemacpool_aggregated == 1 and kubevirt_cnao_kubemacpool_manager_up == 0"),
For: "5m",
For: (*promv1.Duration)(ptr.To("5m")),
Annotations: map[string]string{
"summary": "KubeMacpool is deployed by CNAO CR but KubeMacpool pod is down.",
},
Expand Down
5 changes: 3 additions & 2 deletions pkg/monitoring/rules/alerts/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (

promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
)

func operatorAlerts(namespace string) []promv1.Rule {
return []promv1.Rule{
{
Alert: "CnaoDown",
Expr: intstr.FromString("kubevirt_cnao_operator_up == 0"),
For: "5m",
For: (*promv1.Duration)(ptr.To("5m")),
Annotations: map[string]string{
"summary": "CNAO pod is down.",
},
Expand All @@ -24,7 +25,7 @@ func operatorAlerts(namespace string) []promv1.Rule {
{
Alert: "NetworkAddonsConfigNotReady",
Expr: intstr.FromString(fmt.Sprintf("sum(kubevirt_cnao_cr_ready{namespace='%s'} or vector(0)) == 0", namespace)),
For: "5m",
For: (*promv1.Duration)(ptr.To("5m")),
Annotations: map[string]string{
"summary": "CNAO CR NetworkAddonsConfig is not ready.",
},
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())
})
})
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 9f3bb33

Please sign in to comment.