Increment Panel index again
[scripts.git] / elastic / generate-config.py
1 #!/usr/bin/env python3
2
3 import pystache
4 import requests
5 import json
6
7 URL='https://moose.leap.se:9200'
8
9
10 # Generate visualizations
11 def generate_visualizations():
12     dir = './visualization/'
13     template = open(dir + 'template.mustache', 'r').read()
14
15     # test_names = tests.
16     for test_name in tests:
17         out_file = dir + test_name + '.json'
18         print('Generating ' + out_file)
19         context = {
20            'title': test_name,
21            'query': "commit_info.project:soledad AND commit_info.branch='master' AND machine_info.host='weasel' AND name='" + test_name + "'"
22         }
23
24         rendered = pystache.render(template, context)
25
26         # verify we generated valid JSON visualizations
27         content = json.loads(rendered)
28         visState = content['visState']
29         searchSourceJSON = content['kibanaSavedObjectMeta']['searchSourceJSON']
30         assert json.loads(visState)
31         assert json.loads(searchSourceJSON)
32
33         out = open(out_file, 'w')
34         out.write(rendered)
35         out.flush()
36
37 # Generate Dashboard
38 def generate_dashboards():
39     dir = './dashboard/'
40     template = open(dir + 'template.mustache', 'r').read()
41     out_file = dir + 'soledad-benchmarks.json'
42     print('Generating ' + out_file)
43
44     panels = '['
45     count = 0
46     for test_name in tests:
47         count += 1
48         panels += '{\\"id\\":\\"' + test_name + '\\",\\"panelIndex\\":' + str(count) + ',\\"col\\":1,\\"row\\":' + str(count) + ',\\"size_x\\":6,\\"size_y\\":3,\\"type\\":\\"visualization\\"}, '
49     panels = panels[:-2]
50     panels += ']'
51
52     panels_json = { 'panels_json': panels }
53     rendered = pystache.render(template, panels_json)
54     #print(rendered)
55
56     out = open(out_file, 'w')
57     out.write(rendered)
58     out.flush()
59
60
61 # Main
62
63 # Get all test names
64 with open('./query/test_names.json') as f:
65     response = requests.get(URL + '/_search', data=f)
66     buckets = response.json()['aggregations']['test_names']['buckets']
67
68 tests = []
69 for d in buckets:
70     name = d['key']
71     tests.append(name)
72 tests = sorted(tests)
73
74 generate_dashboards()
75 print()
76 generate_visualizations()