Skip to content

Commit

Permalink
Adds alias field to the Elastic target datasource (#18)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
panyushov authored and trampfox committed Jan 21, 2020
1 parent 539eb51 commit 8085411
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
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
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

0 comments on commit 8085411

Please sign in to comment.