Skip to content

Commit

Permalink
Merge pull request #115 from jakubplichta/refresh
Browse files Browse the repository at this point in the history
By default refresh all queries in query string
  • Loading branch information
jakubplichta authored Oct 31, 2017
2 parents ee1a14d + b7ad109 commit c6b515d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions grafana_dashboards/components/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ def gen_json_from_data(self, data, context):
queries = []
if not data.get('query'):
return queries
refresh_only_first = data.get('refresh-only-first', False)
for query_part in data['query'].split('.'):
if query_part.startswith('$'):
is_first = False if queries else True
query = query_part[1:]
metric = '*'
template_json = {
'type': 'query',
'refresh_on_load': is_first,
'refresh_on_load': not refresh_only_first or is_first,
'name': query,
'refresh': is_first
'refresh': not refresh_only_first or is_first
}
if query in data:
query_config = data[query]
Expand Down
17 changes: 16 additions & 1 deletion tests/grafana_dashboards/components/query/defaults.json
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
[]
[
{
"name": "var1",
"query": "test.*",
"refresh": true,
"refresh_on_load": true,
"type": "query"
},
{
"name": "var2",
"query": "test.$var1.*",
"refresh": true,
"refresh_on_load": true,
"type": "query"
}
]
1 change: 1 addition & 0 deletions tests/grafana_dashboards/components/query/defaults.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
query:
query: test.$var1.$var2
1 change: 1 addition & 0 deletions tests/grafana_dashboards/components/query/empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions tests/grafana_dashboards/components/query/empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
query:
1 change: 1 addition & 0 deletions tests/grafana_dashboards/components/query/full.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query:
query: part1.$var1.part2.$var2.$var3
refresh-only-first: true
var1:
metric: '*x*'
current: o1
Expand Down

0 comments on commit c6b515d

Please sign in to comment.