From 783355f1d61ae53ebb5e86a4d320b6cb2e79e92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 21 Nov 2017 11:27:53 +0100 Subject: [PATCH] fix: alert list panel now works correctly after adding manual annotation on dashboard, fixes #9951 (cherry picked from commit 0d12b37dfdbc4763e31394f621aa0c1b527f71f1) --- docker/docker-compose.yaml | 77 ++++++++++++++++++++++++ pkg/api/annotations.go | 1 + pkg/services/annotations/annotations.go | 1 + pkg/services/sqlstore/annotation.go | 4 ++ pkg/services/sqlstore/annotation_test.go | 14 +++++ 5 files changed, 97 insertions(+) create mode 100644 docker/docker-compose.yaml diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 00000000000..3549836d6b9 --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,77 @@ +version: "2" +services: + graphite: + build: + context: blocks/graphite1 + args: + version: master + ports: + - "8080:80" + - "2003:2003" + - "8125:8125/udp" + - "8126:8126" + volumes: + - /etc/localtime:/etc/localtime:ro + - /etc/timezone:/etc/timezone:ro + + fake-graphite-data: + image: grafana/fake-data-gen + network_mode: bridge + environment: + FD_DATASOURCE: graphite + FD_PORT: 2003 + + + prometheus: + build: blocks/prometheus + network_mode: host + ports: + - "9090:9090" + + node_exporter: + image: prom/node-exporter + network_mode: host + ports: + - "9100:9100" + + fake-prometheus-data: + image: grafana/fake-data-gen + network_mode: host + ports: + - "9091:9091" + environment: + FD_DATASOURCE: prom + + alertmanager: + image: quay.io/prometheus/alertmanager + network_mode: host + ports: + - "9093:9093" + + influxdb: + image: influxdb:latest + container_name: influxdb + ports: + - "2004:2004" + - "8083:8083" + - "8086:8086" + volumes: + - ./blocks/influxdb/influxdb.conf:/etc/influxdb/influxdb.conf + + fake-influxdb-data: + image: grafana/fake-data-gen + network_mode: bridge + environment: + FD_DATASOURCE: influxdb + FD_PORT: 8086 + + +# You need to run 'sysctl -w vm.max_map_count=262144' on the host machine + + elasticsearch5: + image: elasticsearch:5 + command: elasticsearch + ports: + - "10200:9200" + - "10300:9300" + diff --git a/pkg/api/annotations.go b/pkg/api/annotations.go index e6454e9cf86..93aebafafef 100644 --- a/pkg/api/annotations.go +++ b/pkg/api/annotations.go @@ -21,6 +21,7 @@ func GetAnnotations(c *middleware.Context) Response { PanelId: c.QueryInt64("panelId"), Limit: c.QueryInt64("limit"), Tags: c.QueryStrings("tags"), + Type: c.Query("type"), } repo := annotations.GetRepository() diff --git a/pkg/services/annotations/annotations.go b/pkg/services/annotations/annotations.go index 2fdc824f172..02f927a76ba 100644 --- a/pkg/services/annotations/annotations.go +++ b/pkg/services/annotations/annotations.go @@ -17,6 +17,7 @@ type ItemQuery struct { DashboardId int64 `json:"dashboardId"` PanelId int64 `json:"panelId"` Tags []string `json:"tags"` + Type string `json:"type"` Limit int64 `json:"limit"` } diff --git a/pkg/services/sqlstore/annotation.go b/pkg/services/sqlstore/annotation.go index d97db10f630..effffb8bab4 100644 --- a/pkg/services/sqlstore/annotation.go +++ b/pkg/services/sqlstore/annotation.go @@ -158,6 +158,10 @@ func (r *SqlAnnotationRepo) Find(query *annotations.ItemQuery) ([]*annotations.I params = append(params, query.From, query.To) } + if query.Type == "alert" { + sql.WriteString(` AND annotation.alert_id > 0`) + } + if len(query.Tags) > 0 { keyValueFilters := []string{} diff --git a/pkg/services/sqlstore/annotation_test.go b/pkg/services/sqlstore/annotation_test.go index 3f7415a952b..a1dea622fb2 100644 --- a/pkg/services/sqlstore/annotation_test.go +++ b/pkg/services/sqlstore/annotation_test.go @@ -42,6 +42,7 @@ func TestAnnotations(t *testing.T) { UserId: 1, DashboardId: 1, Text: "hello", + Type: "alert", Epoch: 10, Tags: []string{"outage", "error", "type:outage", "server:server-1"}, }) @@ -89,6 +90,19 @@ func TestAnnotations(t *testing.T) { So(items, ShouldHaveLength, 0) }) + Convey("Should not find one when type filter does not match", func() { + items, err := repo.Find(&annotations.ItemQuery{ + OrgId: 1, + DashboardId: 1, + From: 1, + To: 15, + Type: "alert", + }) + + So(err, ShouldBeNil) + So(items, ShouldHaveLength, 0) + }) + Convey("Should find one when all tag filters does match", func() { items, err := repo.Find(&annotations.ItemQuery{ OrgId: 1,