mirror of
https://github.com/prymitive/karma
synced 2026-08-23 11:56:20 +00:00
Migrate tests to new annotation scheme
This commit is contained in:
+58
-94
@@ -29,8 +29,9 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"alert": "Memory usage exceeding threshold",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "alert", Value: "Memory usage exceeding threshold"},
|
||||
models.Annotation{Visible: true, Name: "dashboard", Value: "http://localhost/dashboard.html", IsLink: true},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"alertname": "Memory_Usage_Too_High",
|
||||
@@ -48,9 +49,6 @@ var groupTests = []groupTest{
|
||||
},
|
||||
},
|
||||
Receiver: "by-name",
|
||||
Links: map[string]string{
|
||||
"dashboard": "http://localhost/dashboard.html",
|
||||
},
|
||||
},
|
||||
},
|
||||
id: "099c5ca6d1c92f615b13056b935d0c8dee70f18c",
|
||||
@@ -69,8 +67,9 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"alert": "Memory usage exceeding threshold",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "alert", Value: "Memory usage exceeding threshold"},
|
||||
models.Annotation{Visible: true, Name: "dashboard", Value: "http://localhost/dashboard.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -86,9 +85,6 @@ var groupTests = []groupTest{
|
||||
"instance": "server2",
|
||||
"job": "node_exporter",
|
||||
},
|
||||
Links: map[string]string{
|
||||
"dashboard": "http://localhost/dashboard.html",
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
@@ -109,8 +105,8 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -126,13 +122,12 @@ var groupTests = []groupTest{
|
||||
"instance": "server3",
|
||||
"job": "node_ping",
|
||||
},
|
||||
Links: map[string]string{},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -148,13 +143,12 @@ var groupTests = []groupTest{
|
||||
"instance": "server4",
|
||||
"job": "node_ping",
|
||||
},
|
||||
Links: map[string]string{},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -170,7 +164,6 @@ var groupTests = []groupTest{
|
||||
"instance": "server5",
|
||||
"job": "node_ping",
|
||||
},
|
||||
Links: map[string]string{},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
@@ -191,8 +184,8 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -214,13 +207,12 @@ var groupTests = []groupTest{
|
||||
"instance": "server6",
|
||||
"job": "node_ping",
|
||||
},
|
||||
Links: map[string]string{},
|
||||
State: models.AlertStateSuppressed,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -245,13 +237,12 @@ var groupTests = []groupTest{
|
||||
"instance": "server7",
|
||||
"job": "node_ping",
|
||||
},
|
||||
Links: map[string]string{},
|
||||
State: models.AlertStateSuppressed,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -272,7 +263,6 @@ var groupTests = []groupTest{
|
||||
"instance": "server8",
|
||||
"job": "node_ping",
|
||||
},
|
||||
Links: map[string]string{},
|
||||
State: models.AlertStateSuppressed,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
@@ -292,8 +282,9 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
models.Annotation{Visible: true, Name: "url", Value: "http://localhost/example.html", IsLink: true},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"alertname": "Host_Down",
|
||||
@@ -311,13 +302,10 @@ var groupTests = []groupTest{
|
||||
},
|
||||
},
|
||||
Receiver: "by-name",
|
||||
Links: map[string]string{
|
||||
"url": "http://localhost/example.html",
|
||||
},
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"alertname": "Host_Down",
|
||||
@@ -335,11 +323,10 @@ var groupTests = []groupTest{
|
||||
},
|
||||
},
|
||||
Receiver: "by-name",
|
||||
Links: map[string]string{},
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"alertname": "Host_Down",
|
||||
@@ -357,11 +344,10 @@ var groupTests = []groupTest{
|
||||
},
|
||||
},
|
||||
Receiver: "by-name",
|
||||
Links: map[string]string{},
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"alertname": "Host_Down",
|
||||
@@ -379,11 +365,10 @@ var groupTests = []groupTest{
|
||||
},
|
||||
},
|
||||
Receiver: "by-name",
|
||||
Links: map[string]string{},
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"alertname": "Host_Down",
|
||||
@@ -401,11 +386,10 @@ var groupTests = []groupTest{
|
||||
},
|
||||
},
|
||||
Receiver: "by-name",
|
||||
Links: map[string]string{},
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"alertname": "Host_Down",
|
||||
@@ -428,11 +412,10 @@ var groupTests = []groupTest{
|
||||
},
|
||||
},
|
||||
Receiver: "by-name",
|
||||
Links: map[string]string{},
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"alertname": "Host_Down",
|
||||
@@ -459,11 +442,10 @@ var groupTests = []groupTest{
|
||||
},
|
||||
},
|
||||
Receiver: "by-name",
|
||||
Links: map[string]string{},
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"alertname": "Host_Down",
|
||||
@@ -486,7 +468,6 @@ var groupTests = []groupTest{
|
||||
},
|
||||
},
|
||||
Receiver: "by-name",
|
||||
Links: map[string]string{},
|
||||
},
|
||||
},
|
||||
id: "58c6a3467cebc53abe68ecbe8643ce478c5a1573",
|
||||
@@ -505,8 +486,9 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"alert": "Less than 10% disk space is free",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "alert", Value: "Less than 10% disk space is free"},
|
||||
models.Annotation{Visible: true, Name: "dashboard", Value: "http://localhost/dashboard.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -522,9 +504,6 @@ var groupTests = []groupTest{
|
||||
"instance": "server5",
|
||||
"job": "node_exporter",
|
||||
},
|
||||
Links: map[string]string{
|
||||
"dashboard": "http://localhost/dashboard.html",
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
@@ -545,8 +524,9 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
models.Annotation{Visible: true, Name: "url", Value: "http://localhost/example.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -562,15 +542,12 @@ var groupTests = []groupTest{
|
||||
"instance": "server1",
|
||||
"job": "node_ping",
|
||||
},
|
||||
Links: map[string]string{
|
||||
"url": "http://localhost/example.html",
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -586,7 +563,6 @@ var groupTests = []groupTest{
|
||||
"instance": "server2",
|
||||
"job": "node_ping",
|
||||
},
|
||||
Links: map[string]string{},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
@@ -606,9 +582,10 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
"help": "Example help annotation",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "help", Value: "Example help annotation"},
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
models.Annotation{Visible: true, Name: "url", Value: "http://localhost/example.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -629,15 +606,12 @@ var groupTests = []groupTest{
|
||||
"instance": "web1",
|
||||
"job": "node_exporter",
|
||||
},
|
||||
Links: map[string]string{
|
||||
"url": "http://localhost/example.html",
|
||||
},
|
||||
State: models.AlertStateSuppressed,
|
||||
Receiver: "by-name",
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -653,7 +627,6 @@ var groupTests = []groupTest{
|
||||
"instance": "web2",
|
||||
"job": "node_exporter",
|
||||
},
|
||||
Links: map[string]string{},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-name",
|
||||
},
|
||||
@@ -673,8 +646,9 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"alert": "Less than 10% disk space is free",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "alert", Value: "Less than 10% disk space is free"},
|
||||
models.Annotation{Visible: true, Name: "dashboard", Value: "http://localhost/dashboard.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -690,9 +664,6 @@ var groupTests = []groupTest{
|
||||
"instance": "server5",
|
||||
"job": "node_exporter",
|
||||
},
|
||||
Links: map[string]string{
|
||||
"dashboard": "http://localhost/dashboard.html",
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-name",
|
||||
},
|
||||
@@ -713,9 +684,10 @@ var groupTests = []groupTest{
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"help": "Example help annotation",
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "help", Value: "Example help annotation"},
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
models.Annotation{Visible: true, Name: "url", Value: "http://localhost/example.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -736,15 +708,12 @@ var groupTests = []groupTest{
|
||||
"instance": "web1",
|
||||
"job": "node_exporter",
|
||||
},
|
||||
Links: map[string]string{
|
||||
"url": "http://localhost/example.html",
|
||||
},
|
||||
State: models.AlertStateSuppressed,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"summary": "Example summary",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "summary", Value: "Example summary"},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
@@ -760,7 +729,6 @@ var groupTests = []groupTest{
|
||||
"instance": "web2",
|
||||
"job": "node_exporter",
|
||||
},
|
||||
Links: map[string]string{},
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
@@ -875,10 +843,6 @@ func testAlert(version string, t *testing.T, expectedAlert, gotAlert models.Aler
|
||||
t.Errorf("[%s] Labels mismatch on alert receiver='%s', expected labels=%v but got %v",
|
||||
version, expectedAlert.Receiver, expectedAlert.Labels, gotAlert.Labels)
|
||||
}
|
||||
if !reflect.DeepEqual(gotAlert.Links, expectedAlert.Links) {
|
||||
t.Errorf("[%s] Links mismatch on alert receiver='%s' labels=%v expected %v but got %v",
|
||||
version, expectedAlert.Receiver, expectedAlert.Labels, expectedAlert.Links, gotAlert.Links)
|
||||
}
|
||||
if len(gotAlert.Alertmanager) != len(expectedAlert.Alertmanager) {
|
||||
t.Errorf("[%s] Expected %d alertmanager instances but got %d on alert receiver='%s' labels=%v",
|
||||
version, len(expectedAlert.Alertmanager), len(gotAlert.Alertmanager), gotAlert.Receiver, expectedAlert.Labels)
|
||||
|
||||
@@ -355,20 +355,32 @@ var tests = []filterTest{
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Annotations: map[string]string{"key": "abc"}},
|
||||
IsMatch: true,
|
||||
Alert: models.Alert{
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Name: "key", Value: "abc"},
|
||||
},
|
||||
},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Annotations: map[string]string{"key": "ccc abc"}},
|
||||
IsMatch: true,
|
||||
Alert: models.Alert{
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Name: "key", Value: "ccc abc"},
|
||||
},
|
||||
},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Annotations: map[string]string{"abc": "zzz"}},
|
||||
IsMatch: false,
|
||||
Alert: models.Alert{
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Name: "abc", Value: "zzz"},
|
||||
},
|
||||
},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
|
||||
@@ -72,9 +72,17 @@ func BenchmarkLabelsFingerprint(b *testing.B) {
|
||||
|
||||
func BenchmarkLabelsContent(b *testing.B) {
|
||||
alert := models.Alert{
|
||||
Annotations: map[string]string{
|
||||
"foo": "bar",
|
||||
"abc": "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{
|
||||
Name: "foo",
|
||||
Value: "bar",
|
||||
Visible: true,
|
||||
},
|
||||
models.Annotation{
|
||||
Name: "abc",
|
||||
Value: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
|
||||
Visible: true,
|
||||
},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"foo1": "bar1",
|
||||
|
||||
+8
-2
@@ -163,8 +163,14 @@ func TestAlerts(t *testing.T) {
|
||||
}
|
||||
for _, ag := range ur.AlertGroups {
|
||||
for _, a := range ag.Alerts {
|
||||
if len(a.Links) != 1 {
|
||||
t.Errorf("Invalid number of links, got %d, expected 1, %v", len(a.Links), a)
|
||||
linkCount := 0
|
||||
for _, annotation := range a.Annotations {
|
||||
if annotation.IsLink {
|
||||
linkCount++
|
||||
}
|
||||
}
|
||||
if linkCount != 1 {
|
||||
t.Errorf("Invalid number of links, got %d, expected 1, %v", linkCount, a)
|
||||
}
|
||||
if len(a.Alertmanager) == 0 {
|
||||
t.Errorf("Alertmanager instance list is empty, %v", a)
|
||||
|
||||
Reference in New Issue
Block a user