diff --git a/cmd/alert_test.go b/cmd/alert_test.go index 9f4cfa4..d8dc80e 100644 --- a/cmd/alert_test.go +++ b/cmd/alert_test.go @@ -1,7 +1,6 @@ package cmd import ( - "fmt" "net/http" "net/http/httptest" "net/url" @@ -32,222 +31,13 @@ type AlertTest struct { func TestAlertCmd(t *testing.T) { - alertTestDataSet1 := fmt.Sprintf(` - { - "status": "success", - "data": { - "groups": [ - { - "name": "Foo", - "file": "alerts.yaml", - "rules": [ - { - "state": "inactive", - "name": "HostOutOfMemory", - "query": "up", - "duration": 120, - "labels": { - "severity": "critical" - }, - "annotations": { - "description": "Foo", - "summary": "Foo" - }, - "alerts": [], - "health": "ok", - "evaluationTime": 0.000553928, - "lastEvaluation": "2022-11-24T14:08:17.597083058Z", - "type": "alerting" - } - ], - "interval": 10, - "limit": 0, - "evaluationTime": 0.000581212, - "lastEvaluation": "2022-11-24T14:08:17.59706083Z" - }, - { - "name": "SQL", - "file": "alerts.yaml", - "rules": [ - { - "state": "pending", - "name": "SqlAccessDeniedRate", - "query": "mysql", - "duration": 17280000, - "labels": { - "severity": "warning" - }, - "annotations": { - "description": "MySQL", - "summary": "MySQL" - }, - "alerts": [ - { - "labels": { - "alertname": "SqlAccessDeniedRate", - "instance": "localhost", - "job": "mysql", - "severity": "warning" - }, - "annotations": { - "description": "MySQL", - "summary": "MySQL" - }, - "state": "pending", - "activeAt": "2022-11-21T10:38:35.373483748Z", - "value": "4.03448275862069e-01" - } - ], - "health": "ok", - "evaluationTime": 0.002909617, - "lastEvaluation": "2022-11-24T14:08:25.375220595Z", - "type": "alerting" - } - ], - "interval": 10, - "limit": 0, - "evaluationTime": 0.003046259, - "lastEvaluation": "2022-11-24T14:08:25.375096825Z" - }, - { - "name": "TLS", - "file": "alerts.yaml", - "rules": [ - { - "state": "firing", - "name": "BlackboxTLS", - "query": "SSL", - "duration": 0, - "labels": { - "severity": "critical" - }, - "annotations": { - "description": "TLS", - "summary": "TLS" - }, - "alerts": [ - { - "labels": { - "alertname": "TLS", - "instance": "https://localhost:443", - "job": "blackbox", - "severity": "critical" - }, - "annotations": { - "description": "TLS", - "summary": "TLS" - }, - "state": "firing", - "activeAt": "2022-11-24T05:11:27.211699259Z", - "value": "-6.065338210999966e+06" - } - ], - "health": "ok", - "evaluationTime": 0.000713955, - "lastEvaluation": "2022-11-24T14:08:17.212720815Z", - "type": "alerting" - } - ], - "interval": 10, - "limit": 0, - "evaluationTime": 0.000738927, - "lastEvaluation": "2022-11-24T14:08:17.212700182Z" - } - ] - } - }`) + alertTestDataSet1 := "../testdata/unittest/alertDataset1.json" - alertTestDataSet2 := fmt.Sprintf(` - { - "status": "success", - "data": { - "groups": [ - { - "name": "Foo", - "file": "alerts.yaml", - "rules": [ - { - "state": "inactive", - "name": "InactiveAlert", - "query": "foo", - "duration": 120, - "labels": { - "severity": "critical" - }, - "annotations": { - "description": "Inactive", - "summary": "Inactive" - }, - "alerts": [], - "health": "ok", - "evaluationTime": 0.000462382, - "lastEvaluation": "2022-11-18T14:01:07.597034323Z", - "type": "alerting" - } - ], - "interval": 10, - "limit": 0, - "evaluationTime": 0.000478395, - "lastEvaluation": "2022-11-18T14:01:07.597021953Z" - } - ] - } - }`) + alertTestDataSet2 := "../testdata/unittest/alertDataset2.json" - alertTestDataSet3 := fmt.Sprintf(` - { - "status": "success", - "data": { - "groups": [ - { - "name": "k8s", - "file": "/etc/prometheus/rules/al.yaml", - "rules": [ - { - "state": "inactive", - "name": "NodeHasMemoryPressure", - "query": "kube_node{condition=\"MemoryPressure\",status=\"true\"} == 1", - "duration": 300, - "keepFiringFor": 0, - "labels": {}, - "annotations": { - "summary": "Memory pressure on instance {{ $labels.instance }}" - }, - "alerts": [], - "health": "ok", - "evaluationTime": 0.00023339, - "lastEvaluation": "2024-12-18T17:50:01.483161228Z", - "type": "alerting" - } - ], - "interval": 15, - "limit": 0, - "evaluationTime": 0.000262616, - "lastEvaluation": "2024-12-18T17:50:01.483135426Z" - }, - { - "name": "example", - "file": "/etc/prometheus/rules/rec.yaml", - "rules": [ - { - "name": "rule:prometheus_http_requests_total:sum", - "query": "sum by (code) (rate(prometheus_http_requests_total[5m]))", - "health": "ok", - "evaluationTime": 0.000472562, - "lastEvaluation": "2024-12-18T17:50:12.420737469Z", - "type": "recording" - } - ], - "interval": 15, - "limit": 0, - "evaluationTime": 0.000497618, - "lastEvaluation": "2024-12-18T17:50:12.42071533Z" - } - ], - "groupNextToken:omitempty": "" - } - } - `) + alertTestDataSet3 := "../testdata/unittest/alertDataset3.json" + + alertTestDataSet4 := "../testdata/unittest/alertDataset4.json" tests := []AlertTest{ { @@ -290,7 +80,7 @@ func TestAlertCmd(t *testing.T) { name: "alert-default", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet1)) + w.Write(loadTestdata(alertTestDataSet1)) })), args: []string{"run", "../main.go", "alert"}, expected: `[CRITICAL] - 3 Alerts: 1 Firing - 1 Pending - 1 Inactive @@ -306,7 +96,7 @@ exit status 2 name: "alert-problems-only", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet1)) + w.Write(loadTestdata(alertTestDataSet1)) })), args: []string{"run", "../main.go", "alert", "--problems"}, expected: `[CRITICAL] - 2 Alerts: 1 Firing - 1 Pending - 0 Inactive @@ -321,7 +111,7 @@ exit status 2 name: "alert-problems-only-with-exlude-on-one-group", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet1)) + w.Write(loadTestdata(alertTestDataSet1)) })), args: []string{"run", "../main.go", "alert", "--problems", "-g", "TLS"}, expected: `[CRITICAL] - 1 Alerts: 1 Firing - 0 Pending - 0 Inactive @@ -334,7 +124,7 @@ exit status 2 name: "alert-problems-only-with-exlude-on-two-groups", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet1)) + w.Write(loadTestdata(alertTestDataSet1)) })), args: []string{"run", "../main.go", "alert", "--problems", "-g", "SQL", "-g", "TLS"}, expected: `[CRITICAL] - 2 Alerts: 1 Firing - 1 Pending - 0 Inactive @@ -349,7 +139,7 @@ exit status 2 name: "alert-problems-only-with-exlude", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet1)) + w.Write(loadTestdata(alertTestDataSet1)) })), args: []string{"run", "../main.go", "alert", "--problems", "--exclude-alert", "Sql.*DeniedRate"}, expected: `[CRITICAL] - 1 Alerts: 1 Firing - 0 Pending - 0 Inactive @@ -362,7 +152,7 @@ exit status 2 name: "alert-with-exclude-error", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet3)) + w.Write(loadTestdata(alertTestDataSet3)) })), args: []string{"run", "../main.go", "alert", "--exclude-alert", "[a-z"}, expected: "[UNKNOWN] - Invalid regular expression provided: error parsing regexp: missing closing ]: `[a-z`\nexit status 3\n", @@ -371,7 +161,7 @@ exit status 2 name: "alert-no-such-alert", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet2)) + w.Write(loadTestdata(alertTestDataSet2)) })), args: []string{"run", "../main.go", "alert", "--name", "NoSuchAlert"}, expected: "[UNKNOWN] - 0 Alerts: 0 Firing - 0 Pending - 0 Inactive\n\nexit status 3\n", @@ -380,7 +170,7 @@ exit status 2 name: "alert-inactive-with-problems", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet2)) + w.Write(loadTestdata(alertTestDataSet2)) })), args: []string{"run", "../main.go", "alert", "--name", "InactiveAlert", "--problems"}, expected: "[UNKNOWN] - 0 Alerts: 0 Firing - 0 Pending - 0 Inactive\n\nexit status 3\n", @@ -389,7 +179,7 @@ exit status 2 name: "alert-multiple-alerts", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet1)) + w.Write(loadTestdata(alertTestDataSet1)) })), args: []string{"run", "../main.go", "alert", "--name", "HostOutOfMemory", "--name", "BlackboxTLS"}, expected: `[CRITICAL] - 2 Alerts: 1 Firing - 0 Pending - 1 Inactive @@ -404,7 +194,7 @@ exit status 2 name: "alert-multiple-alerts-problems-only", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet1)) + w.Write(loadTestdata(alertTestDataSet1)) })), args: []string{"run", "../main.go", "alert", "--name", "HostOutOfMemory", "--name", "BlackboxTLS", "--problems"}, expected: `[CRITICAL] - 1 Alerts: 1 Firing - 0 Pending - 0 Inactive @@ -418,7 +208,7 @@ exit status 2 name: "alert-inactive", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(alertTestDataSet2)) + w.Write(loadTestdata(alertTestDataSet2)) })), args: []string{"run", "../main.go", "alert", "--name", "InactiveAlert"}, expected: "[OK] - 1 Alerts: 0 Firing - 0 Pending - 1 Inactive\n\\_ [OK] [InactiveAlert] is inactive\n|firing=0 pending=0 inactive=1\n\n", @@ -427,7 +217,7 @@ exit status 2 name: "alert-recording-rule", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(`{"status":"success","data":{"groups":[{"name":"example","file":"recoding.yaml","rules":[{"name":"job:foo","query":"sum by(job) (requests_total)","health":"ok","evaluationTime":0.000391321,"lastEvaluation":"2023-01-13T14:26:08.687065894Z","type":"recording"}],"interval":10,"evaluationTime":0.000403777,"lastEvaluation":"2023-01-13T14:26:08.687058029Z"},{"name":"Foo","file":"alerts.yaml","rules":[{"state":"inactive","name":"InactiveAlert","query":"foo","duration":120,"labels":{"severity":"critical"},"annotations":{"description":"Inactive","summary":"Inactive"},"alerts":[],"health":"ok","evaluationTime":0.000462382,"lastEvaluation":"2022-11-18T14:01:07.597034323Z","type":"alerting"}],"interval":10,"limit":0,"evaluationTime":0.000478395,"lastEvaluation":"2022-11-18T14:01:07.597021953Z"}]}}`)) + w.Write(loadTestdata(alertTestDataSet4)) })), args: []string{"run", "../main.go", "alert", "--name", "InactiveAlert"}, expected: "[OK] - 1 Alerts: 0 Firing - 0 Pending - 1 Inactive\n\\_ [OK] [InactiveAlert] is inactive\n|firing=0 pending=0 inactive=1\n\n", diff --git a/cmd/config_test.go b/cmd/config_test.go index 52a4dae..f04f308 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -1,9 +1,15 @@ package cmd import ( + "os" "testing" ) +func loadTestdata(filepath string) []byte { + data, _ := os.ReadFile(filepath) + return data +} + func TestConfig(t *testing.T) { c := cliConfig.NewClient() expected := "http://localhost:9090/" diff --git a/cmd/query_test.go b/cmd/query_test.go index 767475d..c375d85 100644 --- a/cmd/query_test.go +++ b/cmd/query_test.go @@ -44,6 +44,15 @@ type QueryTest struct { } func TestQueryCmd(t *testing.T) { + + queryTestDataSet1 := "../testdata/unittest/queryDataset1.json" + + queryTestDataSet2 := "../testdata/unittest/queryDataset2.json" + + queryTestDataSet3 := "../testdata/unittest/queryDataset3.json" + + queryTestDataSet4 := "../testdata/unittest/queryDataset4.json" + tests := []QueryTest{ { name: "query-warning", @@ -94,7 +103,7 @@ func TestQueryCmd(t *testing.T) { name: "query-matrix-exists", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(`{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"up","instance":"localhost","job":"node"},"values":[[1670340712.988,"1"],[1670340772.988,"1"],[1670340832.990,"1"],[1670340892.990,"1"],[1670340952.990,"1"]]}]}}`)) + w.Write(loadTestdata(queryTestDataSet1)) })), args: []string{"run", "../main.go", "query", "--query", "up{job=\"prometheus\"}[5m]"}, expected: "[OK] - states: ok=1\n\\_ [OK] 1 @[1670340952.99] - value: 1\n|up_instance_localhost_job_node=1;10;20\n\n", @@ -103,7 +112,7 @@ func TestQueryCmd(t *testing.T) { name: "query-metric-exists2", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","instance":"localhost","job":"prometheus"},"value":[1668782473.835,"1"]}]}}`)) + w.Write(loadTestdata(queryTestDataSet2)) })), args: []string{"run", "../main.go", "query", "--query", "up{job=\"prometheus\"}"}, expected: "[OK] - states: ok=1\n\\_ [OK] up{instance=\"localhost\", job=\"prometheus\"} - value: 1\n|up_instance_localhost_job_prometheus=1;10;20\n\n", @@ -112,7 +121,7 @@ func TestQueryCmd(t *testing.T) { name: "query-threshold-ok", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","instance":"localhost","job":"prometheus"},"value":[1668782473.835,"100"]}]}}`)) + w.Write(loadTestdata(queryTestDataSet3)) })), args: []string{"run", "../main.go", "query", "--query", "up{job=\"prometheus\"}", "-w", "0:", "-c", "0:"}, expected: "[OK] - states: ok=1\n\\_ [OK] up{instance=\"localhost\", job=\"prometheus\"} - value: 100\n|up_instance_localhost_job_prometheus=100\n\n", @@ -121,7 +130,7 @@ func TestQueryCmd(t *testing.T) { name: "query-threshold-critical", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - w.Write([]byte(`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","instance":"localhost","job":"prometheus"},"value":[1668782473.835,"-100"]}]}}`)) + w.Write(loadTestdata(queryTestDataSet4)) })), args: []string{"run", "../main.go", "query", "--query", "up{job=\"prometheus\"}", "-w", "0:", "-c", "0:"}, expected: "[CRITICAL] - states: critical=1\n\\_ [CRITICAL] up{instance=\"localhost\", job=\"prometheus\"} - value: -100\n|up_instance_localhost_job_prometheus=-100\n\nexit status 2\n", diff --git a/tests/README.md b/testdata/README.md similarity index 100% rename from tests/README.md rename to testdata/README.md diff --git a/tests/alertmanager/alert.rules b/testdata/alertmanager/alert.rules similarity index 100% rename from tests/alertmanager/alert.rules rename to testdata/alertmanager/alert.rules diff --git a/tests/alertmanager/alertmanager.yml b/testdata/alertmanager/alertmanager.yml similarity index 100% rename from tests/alertmanager/alertmanager.yml rename to testdata/alertmanager/alertmanager.yml diff --git a/tests/docker-compose.yml b/testdata/docker-compose.yml similarity index 100% rename from tests/docker-compose.yml rename to testdata/docker-compose.yml diff --git a/tests/prometheus.yml b/testdata/prometheus.yml similarity index 100% rename from tests/prometheus.yml rename to testdata/prometheus.yml diff --git a/testdata/unittest/alertDataset1.json b/testdata/unittest/alertDataset1.json new file mode 100644 index 0000000..7e46bff --- /dev/null +++ b/testdata/unittest/alertDataset1.json @@ -0,0 +1,123 @@ +{ + "status": "success", + "data": { + "groups": [ + { + "name": "Foo", + "file": "alerts.yaml", + "rules": [ + { + "state": "inactive", + "name": "HostOutOfMemory", + "query": "up", + "duration": 120, + "labels": { + "severity": "critical" + }, + "annotations": { + "description": "Foo", + "summary": "Foo" + }, + "alerts": [], + "health": "ok", + "evaluationTime": 0.000553928, + "lastEvaluation": "2022-11-24T14:08:17.597083058Z", + "type": "alerting" + } + ], + "interval": 10, + "limit": 0, + "evaluationTime": 0.000581212, + "lastEvaluation": "2022-11-24T14:08:17.59706083Z" + }, + { + "name": "SQL", + "file": "alerts.yaml", + "rules": [ + { + "state": "pending", + "name": "SqlAccessDeniedRate", + "query": "mysql", + "duration": 17280000, + "labels": { + "severity": "warning" + }, + "annotations": { + "description": "MySQL", + "summary": "MySQL" + }, + "alerts": [ + { + "labels": { + "alertname": "SqlAccessDeniedRate", + "instance": "localhost", + "job": "mysql", + "severity": "warning" + }, + "annotations": { + "description": "MySQL", + "summary": "MySQL" + }, + "state": "pending", + "activeAt": "2022-11-21T10:38:35.373483748Z", + "value": "4.03448275862069e-01" + } + ], + "health": "ok", + "evaluationTime": 0.002909617, + "lastEvaluation": "2022-11-24T14:08:25.375220595Z", + "type": "alerting" + } + ], + "interval": 10, + "limit": 0, + "evaluationTime": 0.003046259, + "lastEvaluation": "2022-11-24T14:08:25.375096825Z" + }, + { + "name": "TLS", + "file": "alerts.yaml", + "rules": [ + { + "state": "firing", + "name": "BlackboxTLS", + "query": "SSL", + "duration": 0, + "labels": { + "severity": "critical" + }, + "annotations": { + "description": "TLS", + "summary": "TLS" + }, + "alerts": [ + { + "labels": { + "alertname": "TLS", + "instance": "https://localhost:443", + "job": "blackbox", + "severity": "critical" + }, + "annotations": { + "description": "TLS", + "summary": "TLS" + }, + "state": "firing", + "activeAt": "2022-11-24T05:11:27.211699259Z", + "value": "-6.065338210999966e+06" + } + ], + "health": "ok", + "evaluationTime": 0.000713955, + "lastEvaluation": "2022-11-24T14:08:17.212720815Z", + "type": "alerting" + } + ], + "interval": 10, + "limit": 0, + "evaluationTime": 0.000738927, + "lastEvaluation": "2022-11-24T14:08:17.212700182Z" + } + ] + } +} diff --git a/testdata/unittest/alertDataset2.json b/testdata/unittest/alertDataset2.json new file mode 100644 index 0000000..d9775ac --- /dev/null +++ b/testdata/unittest/alertDataset2.json @@ -0,0 +1,35 @@ +{ + "status": "success", + "data": { + "groups": [ + { + "name": "Foo", + "file": "alerts.yaml", + "rules": [ + { + "state": "inactive", + "name": "InactiveAlert", + "query": "foo", + "duration": 120, + "labels": { + "severity": "critical" + }, + "annotations": { + "description": "Inactive", + "summary": "Inactive" + }, + "alerts": [], + "health": "ok", + "evaluationTime": 0.000462382, + "lastEvaluation": "2022-11-18T14:01:07.597034323Z", + "type": "alerting" + } + ], + "interval": 10, + "limit": 0, + "evaluationTime": 0.000478395, + "lastEvaluation": "2022-11-18T14:01:07.597021953Z" + } + ] + } +} diff --git a/testdata/unittest/alertDataset3.json b/testdata/unittest/alertDataset3.json new file mode 100644 index 0000000..a440ca8 --- /dev/null +++ b/testdata/unittest/alertDataset3.json @@ -0,0 +1,52 @@ +{ + "status": "success", + "data": { + "groups": [ + { + "name": "k8s", + "file": "/etc/prometheus/rules/al.yaml", + "rules": [ + { + "state": "inactive", + "name": "NodeHasMemoryPressure", + "query": "kube_node{condition=\"MemoryPressure\",status=\"true\"} == 1", + "duration": 300, + "keepFiringFor": 0, + "labels": {}, + "annotations": { + "summary": "Memory pressure on instance {{ $labels.instance }}" + }, + "alerts": [], + "health": "ok", + "evaluationTime": 0.00023339, + "lastEvaluation": "2024-12-18T17:50:01.483161228Z", + "type": "alerting" + } + ], + "interval": 15, + "limit": 0, + "evaluationTime": 0.000262616, + "lastEvaluation": "2024-12-18T17:50:01.483135426Z" + }, + { + "name": "example", + "file": "/etc/prometheus/rules/rec.yaml", + "rules": [ + { + "name": "rule:prometheus_http_requests_total:sum", + "query": "sum by (code) (rate(prometheus_http_requests_total[5m]))", + "health": "ok", + "evaluationTime": 0.000472562, + "lastEvaluation": "2024-12-18T17:50:12.420737469Z", + "type": "recording" + } + ], + "interval": 15, + "limit": 0, + "evaluationTime": 0.000497618, + "lastEvaluation": "2024-12-18T17:50:12.42071533Z" + } + ], + "groupNextToken:omitempty": "" + } +} diff --git a/testdata/unittest/alertDataset4.json b/testdata/unittest/alertDataset4.json new file mode 100644 index 0000000..a37e725 --- /dev/null +++ b/testdata/unittest/alertDataset4.json @@ -0,0 +1,52 @@ +{ + "status": "success", + "data": { + "groups": [ + { + "name": "example", + "file": "recoding.yaml", + "rules": [ + { + "name": "job:foo", + "query": "sum by(job) (requests_total)", + "health": "ok", + "evaluationTime": 0.000391321, + "lastEvaluation": "2023-01-13T14:26:08.687065894Z", + "type": "recording" + } + ], + "interval": 10, + "evaluationTime": 0.000403777, + "lastEvaluation": "2023-01-13T14:26:08.687058029Z" + }, + { + "name": "Foo", + "file": "alerts.yaml", + "rules": [ + { + "state": "inactive", + "name": "InactiveAlert", + "query": "foo", + "duration": 120, + "labels": { + "severity": "critical" + }, + "annotations": { + "description": "Inactive", + "summary": "Inactive" + }, + "alerts": [], + "health": "ok", + "evaluationTime": 0.000462382, + "lastEvaluation": "2022-11-18T14:01:07.597034323Z", + "type": "alerting" + } + ], + "interval": 10, + "limit": 0, + "evaluationTime": 0.000478395, + "lastEvaluation": "2022-11-18T14:01:07.597021953Z" + } + ] + } +} diff --git a/testdata/unittest/queryDataset1.json b/testdata/unittest/queryDataset1.json new file mode 100644 index 0000000..10961e8 --- /dev/null +++ b/testdata/unittest/queryDataset1.json @@ -0,0 +1,37 @@ +{ + "status": "success", + "data": { + "resultType": "matrix", + "result": [ + { + "metric": { + "__name__": "up", + "instance": "localhost", + "job": "node" + }, + "values": [ + [ + 1670340712.988, + "1" + ], + [ + 1670340772.988, + "1" + ], + [ + 1670340832.99, + "1" + ], + [ + 1670340892.99, + "1" + ], + [ + 1670340952.99, + "1" + ] + ] + } + ] + } +} diff --git a/testdata/unittest/queryDataset2.json b/testdata/unittest/queryDataset2.json new file mode 100644 index 0000000..abb7f13 --- /dev/null +++ b/testdata/unittest/queryDataset2.json @@ -0,0 +1,19 @@ +{ + "status": "success", + "data": { + "resultType": "vector", + "result": [ + { + "metric": { + "__name__": "up", + "instance": "localhost", + "job": "prometheus" + }, + "value": [ + 1668782473.835, + "1" + ] + } + ] + } +} diff --git a/testdata/unittest/queryDataset3.json b/testdata/unittest/queryDataset3.json new file mode 100644 index 0000000..a8ec751 --- /dev/null +++ b/testdata/unittest/queryDataset3.json @@ -0,0 +1,19 @@ +{ + "status": "success", + "data": { + "resultType": "vector", + "result": [ + { + "metric": { + "__name__": "up", + "instance": "localhost", + "job": "prometheus" + }, + "value": [ + 1668782473.835, + "100" + ] + } + ] + } +} diff --git a/testdata/unittest/queryDataset4.json b/testdata/unittest/queryDataset4.json new file mode 100644 index 0000000..3d6255c --- /dev/null +++ b/testdata/unittest/queryDataset4.json @@ -0,0 +1,19 @@ +{ + "status": "success", + "data": { + "resultType": "vector", + "result": [ + { + "metric": { + "__name__": "up", + "instance": "localhost", + "job": "prometheus" + }, + "value": [ + 1668782473.835, + "-100" + ] + } + ] + } +}