diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 01f40af..67cdeaa 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -5,6 +5,8 @@ import ( "fmt" "io" "net/http" + "os" + "path/filepath" "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/dom" @@ -108,6 +110,50 @@ var _ = Describe("The plugin", func() { } } + createFolder := "weather/alerts/create-folder" + createRuleGroup := "weather/alerts/create-rule-group" + It(fmt.Sprintf("should execute the %s query", createFolder), func() { + f, err := os.Open(filepath.Join("../integration-test/queries", createFolder+".json")) + Expect(err).ToNot(HaveOccurred()) + + req, err := http.NewRequest(http.MethodPost, "http://grafana.grafana-mongodb-it.cluster/api/folders", f) + Expect(err).ToNot(HaveOccurred()) + req.SetBasicAuth("admin", "adminPassword") + req.Header.Set("accept", "application/json, text/plain, */*") + req.Header.Set("content-type", "application/json") + resp, err := clusterHTTPClient.Do(req) + Expect(err).ToNot(HaveOccurred()) + _, err = io.Copy(GinkgoWriter, resp.Body) + Expect(err).ToNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusOK)) + }) + It(fmt.Sprintf("should execute the %s query", createRuleGroup), func() { + f, err := os.Open(filepath.Join("../integration-test/queries", createRuleGroup+".json")) + Expect(err).ToNot(HaveOccurred()) + + req, err := http.NewRequest(http.MethodPost, "http://grafana.grafana-mongodb-it.cluster/api/ruler/grafana/api/v1/rules/alerts?subtype=cortex", f) + Expect(err).ToNot(HaveOccurred()) + req.SetBasicAuth("admin", "adminPassword") + req.Header.Set("accept", "application/json, text/plain, */*") + req.Header.Set("content-type", "application/json") + resp, err := clusterHTTPClient.Do(req) + Expect(err).ToNot(HaveOccurred()) + _, err = io.Copy(GinkgoWriter, resp.Body) + Expect(err).ToNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusAccepted)) + }) + It(fmt.Sprintf("should execute the alerts evaluation query"), func() { + req, err := http.NewRequest(http.MethodGet, "http://grafana.grafana-mongodb-it.cluster/api/prometheus/grafana/api/v1/rules", nil) + Expect(err).ToNot(HaveOccurred()) + req.SetBasicAuth("admin", "adminPassword") + req.Header.Set("accept", "application/json, text/plain, */*") + resp, err := clusterHTTPClient.Do(req) + Expect(err).ToNot(HaveOccurred()) + _, err = io.Copy(GinkgoWriter, resp.Body) + Expect(err).ToNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusOK)) + }) + }) func nodes(sel interface{}) []*cdp.Node { diff --git a/integration-test/queries/weather/alerts/create-folder.json b/integration-test/queries/weather/alerts/create-folder.json new file mode 100644 index 0000000..ee69d00 --- /dev/null +++ b/integration-test/queries/weather/alerts/create-folder.json @@ -0,0 +1 @@ +{"title":"alerts","uid":"c0a02352-8f64-4b5e-a40c-3d19780d45a4"} \ No newline at end of file diff --git a/integration-test/queries/weather/alerts/create-rule-group.json b/integration-test/queries/weather/alerts/create-rule-group.json new file mode 100644 index 0000000..a80f7b2 --- /dev/null +++ b/integration-test/queries/weather/alerts/create-rule-group.json @@ -0,0 +1 @@ +{"name":"alert_rule","interval":"5m","rules":[{"grafana_alert":{"title":"sensoralert","condition":"C","no_data_state":"NoData","exec_err_state":"Error","data":[{"refId":"A","datasourceUid":"P1CC9A79BDAF09793","queryType":"Timeseries","relativeTimeRange":{"from":600,"to":0},"model":{"refId":"A","database":"test","collection":"tweets","queryType":"Timeseries","timestampField":"timestamp","timestampFormat":"","labelFields":["sensorID"],"legendFormat":"","valueFields":["temperature"],"valueFieldTypes":["int32"],"aggregation":"[{\"$project\":{\"timestamp\":1,\"sensorID\":\"$metadata.sensorId\",\"temperature\":\"$temp\"}}]","autoTimeBound":false,"autoTimeSort":false,"schemaInference":false,"schemaInferenceDepth":20}},{"refId":"B","datasourceUid":"__expr__","queryType":"","model":{"refId":"B","type":"reduce","datasource":{"uid":"__expr__","type":"__expr__"},"conditions":[{"type":"query","evaluator":{"params":[],"type":"gt"},"operator":{"type":"and"},"query":{"params":["B"]},"reducer":{"params":[],"type":"last"}}],"reducer":"last","expression":"A"},"relativeTimeRange":{"from":600,"to":0}},{"refId":"C","datasourceUid":"__expr__","queryType":"","model":{"refId":"C","type":"threshold","datasource":{"uid":"__expr__","type":"__expr__"},"conditions":[{"type":"query","evaluator":{"params":[0],"type":"gt"},"operator":{"type":"and"},"query":{"params":["C"]},"reducer":{"params":[],"type":"last"}}],"expression":"B"},"relativeTimeRange":{"from":600,"to":0}}],"is_paused":false},"for":"5m","annotations":{},"labels":{}}]} \ No newline at end of file diff --git a/src/plugin.json b/src/plugin.json index a28df9c..c5beaf3 100644 --- a/src/plugin.json +++ b/src/plugin.json @@ -6,6 +6,7 @@ "metrics": true, "backend": true, "executable": "gpx_mongodb-community", + "alerting": true, "info": { "description": "Community-supported MongoDB Datasource Plugin", "author": {