From 6b2230f5b54bb34b871c5d610b6c1690a7d417cb Mon Sep 17 00:00:00 2001 From: Manuel Pintaldi Date: Tue, 12 Nov 2019 18:28:13 +0100 Subject: [PATCH 1/5] add uid --- grafana_dashboards/client/grafana.py | 3 +++ grafana_dashboards/components/dashboards.py | 2 ++ samples/project.yaml | 1 + 3 files changed, 6 insertions(+) diff --git a/grafana_dashboards/client/grafana.py b/grafana_dashboards/client/grafana.py index 046d5e7..a18bea8 100644 --- a/grafana_dashboards/client/grafana.py +++ b/grafana_dashboards/client/grafana.py @@ -51,5 +51,8 @@ def process_dashboard(self, project_name, dashboard_name, dashboard_data): if 'folderId' in dashboard_data: body.update({'folderId': dashboard_data['folderId']}) + if 'uid' in dashboard_data: + body.update({'uid': dashboard_data['uid']}) + logger.info("Uploading dashboard '%s' to %s", dashboard_name, self._host) self._connection.make_request('/api/dashboards/db', body) diff --git a/grafana_dashboards/components/dashboards.py b/grafana_dashboards/components/dashboards.py index 7ac9975..caf4a72 100644 --- a/grafana_dashboards/components/dashboards.py +++ b/grafana_dashboards/components/dashboards.py @@ -54,6 +54,8 @@ def gen_json_from_data(self, data, context): json_data['refresh'] = data.get('refresh') if 'folderId' in data: json_data['folderId'] = data.get('folderId') + if 'uid' in data: + json_data['uid'] = data.get('uid') if get_component_type(Annotations) in data: json_data['annotations'] = {'list': self.registry.create_component(Annotations, data).gen_json()} if get_component_type(Rows) in data: diff --git a/samples/project.yaml b/samples/project.yaml index f322522..b01b6f9 100644 --- a/samples/project.yaml +++ b/samples/project.yaml @@ -20,6 +20,7 @@ - name: overview dashboard: + uid: 'uid{dashboard-prefix}' title: '{dashboard-prefix} Overview' tags: - tag1 From 8124b9497c060d711bc970bf21ee5bee79af0446 Mon Sep 17 00:00:00 2001 From: "pavel.panyushov" Date: Mon, 20 Jan 2020 21:37:13 +0100 Subject: [PATCH 2/5] Fixes Grafana exporter tests --- tests/grafana_dashboards/client/test_grafana.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From 73e08e72e769850a9dfae3519859cb31114522c3 Mon Sep 17 00:00:00 2001 From: "pavel.panyushov" Date: Mon, 20 Jan 2020 21:38:36 +0100 Subject: [PATCH 3/5] Adds alias field to the elastic target --- grafana_dashboards/components/targets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 11fc58f5edb54616dc5c4bf6e8ee380c375527ce Mon Sep 17 00:00:00 2001 From: "pavel.panyushov" Date: Mon, 20 Jan 2020 22:23:03 +0100 Subject: [PATCH 4/5] Adds elastic target component test with alias --- .../elastic-target/full_with_alias.json | 27 +++++++++++++++++++ .../elastic-target/full_with_alias.yaml | 19 +++++++++++++ 2 files changed, 46 insertions(+) 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/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 From 0c5503fc321fa0779216eb379bf4c9faf8c02bc8 Mon Sep 17 00:00:00 2001 From: "pavel.panyushov" Date: Mon, 20 Jan 2020 22:32:32 +0100 Subject: [PATCH 5/5] Adds alias field to the elastic sample --- samples/elastic.yaml | 1 + 1 file changed, 1 insertion(+) 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