Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds alias field to the Elastic target datasource #18

Merged
merged 5 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions grafana_dashboards/client/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions grafana_dashboards/components/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion grafana_dashboards/components/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions samples/elastic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
targets:
- elastic-target:
query: '(status: "succeeded")'
alias: 'Alias'
bucketAggs:
- field: finishedAt
type: date_histogram
Expand Down
1 change: 1 addition & 0 deletions samples/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

- name: overview
dashboard:
uid: 'uid{dashboard-prefix}'
title: '{dashboard-prefix} Overview'
tags:
- tag1
Expand Down
4 changes: 2 additions & 2 deletions tests/grafana_dashboards/client/test_grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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