From 8085411e9efaec363dde8d51b2da611d3a68dd52 Mon Sep 17 00:00:00 2001 From: Pavel Panyushov Date: Tue, 21 Jan 2020 10:40:34 +0100 Subject: [PATCH] Adds alias field to the Elastic target datasource (#18) * add uid * Fixes Grafana exporter tests * Adds alias field to the elastic target * Adds elastic target component test with alias * Adds alias field to the elastic sample --- grafana_dashboards/components/targets.py | 2 +- samples/elastic.yaml | 1 + .../grafana_dashboards/client/test_grafana.py | 4 +-- .../elastic-target/full_with_alias.json | 27 +++++++++++++++++++ .../elastic-target/full_with_alias.yaml | 19 +++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tests/grafana_dashboards/components/elastic-target/full_with_alias.json create mode 100644 tests/grafana_dashboards/components/elastic-target/full_with_alias.yaml diff --git a/grafana_dashboards/components/targets.py b/grafana_dashboards/components/targets.py index eb23d25..8e1f7eb 100644 --- a/grafana_dashboards/components/targets.py +++ b/grafana_dashboards/components/targets.py @@ -75,7 +75,7 @@ def gen_json_from_data(self, data, context): class ElasticTarget(TargetsItemBase): - _copy_fields = {'bucketAggs', 'hide', 'metrics', 'refId', 'timeField', 'datasource'} + _copy_fields = {'bucketAggs', 'hide', 'metrics', 'refId', 'timeField', 'datasource', 'alias'} def gen_json_from_data(self, data, context): template_json = super(ElasticTarget, self).gen_json_from_data(data, context) diff --git a/samples/elastic.yaml b/samples/elastic.yaml index 1fb9dda..3c1bd61 100644 --- a/samples/elastic.yaml +++ b/samples/elastic.yaml @@ -34,6 +34,7 @@ targets: - elastic-target: query: '(status: "succeeded")' + alias: 'Alias' bucketAggs: - field: finishedAt type: date_histogram diff --git a/tests/grafana_dashboards/client/test_grafana.py b/tests/grafana_dashboards/client/test_grafana.py index 1506cdb..10a9499 100644 --- a/tests/grafana_dashboards/client/test_grafana.py +++ b/tests/grafana_dashboards/client/test_grafana.py @@ -28,7 +28,7 @@ def test_grafana(): dashboard_data = {'title': 'title', 'tags': []} exporter.process_dashboard('project_name', 'dashboard_name', dashboard_data) - body = {'overwrite': True, 'dashboard': dashboard_data} + body = {'overwrite': True, 'dashboard': dashboard_data, 'message': ''} # noinspection PyProtectedMember exporter._connection.make_request.assert_called_once_with('/api/dashboards/db', body) @@ -41,7 +41,7 @@ def test_grafana_with_kerberos(): dashboard_data = {'title': 'title', 'tags': []} exporter.process_dashboard('project_name', 'dashboard_name', dashboard_data) - body = {'overwrite': True, 'dashboard': dashboard_data} + body = {'overwrite': True, 'dashboard': dashboard_data, 'message': ''} # noinspection PyProtectedMember exporter._connection.make_request.assert_called_once_with('/api/dashboards/db', body) diff --git a/tests/grafana_dashboards/components/elastic-target/full_with_alias.json b/tests/grafana_dashboards/components/elastic-target/full_with_alias.json new file mode 100644 index 0000000..817e706 --- /dev/null +++ b/tests/grafana_dashboards/components/elastic-target/full_with_alias.json @@ -0,0 +1,27 @@ +{ + "query": "(status: 'succeeded')", + "alias": "Alias", + "bucketAggs": [ + { + "field": "finishedAt", + "id": "2", + "settings": { + "interval": "auto", + "min_doc_count": 1, + "trimEdges": 0 + }, + "type": "date_histogram" + } + ], + "hide": false, + "metrics": [ + { + "field": "select metric", + "id": "1", + "type": "count" + } + ], + "refId": "A", + "timeField": "finishedAt", + "datasource": "default" +} diff --git a/tests/grafana_dashboards/components/elastic-target/full_with_alias.yaml b/tests/grafana_dashboards/components/elastic-target/full_with_alias.yaml new file mode 100644 index 0000000..944faad --- /dev/null +++ b/tests/grafana_dashboards/components/elastic-target/full_with_alias.yaml @@ -0,0 +1,19 @@ +elastic-target: + query: "(status: 'succeeded')" + alias: "Alias" + bucketAggs: + - field: finishedAt + type: date_histogram + id: "2" + settings: + interval: 'auto' + min_doc_count: 1 + trimEdges: 0 + hide: false + metrics: + - field: "select metric" + id: "1" + type: count + refId: "A" + timeField: finishedAt + datasource: default