/
alert_custom_validations.go
86 lines (68 loc) · 2.06 KB
/
alert_custom_validations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package testutil
import (
promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
)
func ValidateAlertNameLength(alert *promv1.Rule) []Problem {
var result []Problem
if len(alert.Alert) > 50 {
result = append(result, Problem{
ResourceName: alert.Alert,
Description: "alert name exceeds 50 characters",
})
}
return result
}
func ValidateAlertHasDescriptionAnnotation(alert *promv1.Rule) []Problem {
var result []Problem
description := alert.Annotations["description"]
if description == "" {
result = append(result, Problem{
ResourceName: alert.Alert,
Description: "alert must have a description annotation",
})
}
return result
}
func ValidateAlertRunbookURLAnnotation(alert *promv1.Rule) []Problem {
var result []Problem
runbookURL := alert.Annotations["runbook_url"]
if runbookURL == "" {
result = append(result, Problem{
ResourceName: alert.Alert,
Description: "alert must have a runbook_url annotation",
})
}
return result
}
func ValidateAlertHealthImpactLabel(alert *promv1.Rule) []Problem {
var result []Problem
healthImpact := alert.Labels["operator_health_impact"]
if !isValidHealthImpact(healthImpact) {
result = append(result, Problem{
ResourceName: alert.Alert,
Description: "alert must have a operator_health_impact label with value critical, warning, or none",
})
}
return result
}
func ValidateAlertPartOfAndComponentLabels(alert *promv1.Rule) []Problem {
var result []Problem
partOf := alert.Labels["kubernetes_operator_part_of"]
if partOf == "" {
result = append(result, Problem{
ResourceName: alert.Alert,
Description: "alert must have a kubernetes_operator_part_of label",
})
}
component := alert.Labels["kubernetes_operator_component"]
if component == "" {
result = append(result, Problem{
ResourceName: alert.Alert,
Description: "alert must have a kubernetes_operator_component label",
})
}
return result
}
func isValidHealthImpact(healthImpact string) bool {
return healthImpact == "critical" || healthImpact == "warning" || healthImpact == "none"
}