summaryrefslogtreecommitdiff
path: root/elastic/generate-config.py
blob: 0aa998fcbb2863bc8cbc59c13adfc0003c1407b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
#
# Todo:
#
# - Remove all json files from previous runs
import json
import logging
import os
import pystache
import requests
import sys


URL='https://moose.leap.se:9200'

# configure a logger
logger = logging.getLogger(__name__)
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
logger.addHandler(ch)
logger.setLevel(logging.INFO)


# Generate visualizations
def generate_visualizations():
    dir = './visualization/'
    with open(os.path.join(dir, 'template.mustache'), 'r') as f:
        template = f.read()

    # test_names = tests.
    for test_name in tests:
        out_file = os.path.join(dir, test_name + '.json')
        logger.info('Generating ' + out_file)

        context = {
           'title': test_name,
           'query': "commit_info.project:soledad "
                    "AND commit_info.branch='master' "
                    "AND machine_info.host='weasel' "
                    "AND name='" + test_name + "'"
        }
        rendered = pystache.render(template, context)

        # verify we generated valid JSON visualizations
        content = json.loads(rendered)
        visState = content['visState']
        searchSourceJSON = content['kibanaSavedObjectMeta']['searchSourceJSON']
        assert json.loads(visState)
        assert json.loads(searchSourceJSON)

        with open(out_file, 'w') as out:
            out.write(rendered)

# Generate Dashboard
def generate_dashboards():
    dir = './dashboard/'
    with open(os.path.join(dir, 'template.mustache'), 'r') as f:
        template = f.read()

    out_file = os.path.join(dir, 'soledad-benchmarks.json')
    logger.info('Generating ' + out_file)

    panels = []
    count = 0
    for test_name in tests:
        count += 1
        panels.append({
            'id': test_name,
            'panelIndex': count,
            'col': 1,
            'row': count,
            'size_x': 6,
            'size_y': 3,
            'type': 'visualization',
        })

    panels_json = {'panels_json': json.dumps(panels)}
    rendered = pystache.render(template, panels_json)

    with open(out_file, 'w') as f:
        f.write(rendered)


# Main

# Get all test names
with open('./query/test_names.json') as f:
    response = requests.get(URL + '/_search', data=f)
    buckets = response.json()['aggregations']['test_names']['buckets']

tests = []
for d in buckets:
    name = d['key']
    tests.append(name)
tests = sorted(tests)


if __name__ == '__main__':
    generate_dashboards()
    generate_visualizations()