From 78e4fd3062e59e1e6d75ed49982f30f9a5d14ad4 Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 13 Jul 2017 12:57:16 -0300 Subject: [elastic] add support for date ranges --- elastic/generate-config.py | 64 ++++++++++++++++----------- elastic/templates/dashboard-per-test.mustache | 4 +- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/elastic/generate-config.py b/elastic/generate-config.py index 9ff1210..b1389e1 100755 --- a/elastic/generate-config.py +++ b/elastic/generate-config.py @@ -67,9 +67,6 @@ def generate_visualizations(tests): for type, title, host, template_visState in graphs: - out_file = os.path.join(out_dir, test_name + '_' + type + '.json') - logger.info('Generating ' + out_file) - query = "commit_info.project:soledad" \ " AND machine_info.host='" + host + "'" \ " AND name='" + test_name + "'" @@ -85,26 +82,39 @@ def generate_visualizations(tests): if type == 'cpu': query += " AND _exists_:extra_info.cpu_percent" - context = { - 'title': title + test_name, - 'test_name': test_name, - 'query': query, - } + # create visualization for many ranges + for r in ['', '-1w', '-1M', '-1y']: + + rmod = "" + tmod = "" + if r: + rmod = " AND commit_info.time:[\\\"now%s\\\" TO \\\"now\\\"]" % r + tmod = ' (' + r + ')' + + context = { + 'title': title + test_name + tmod, + 'test_name': test_name, + 'query': query + rmod, + } - visState = pystache.render(template_visState, context) - assert json.loads(visState) - context['visState'] = json.dumps(visState) + file_name = test_name + '_' + type + r + '.json' + out_file = os.path.join(out_dir, file_name) + logger.info('Generating ' + out_file) - searchSourceJSON = pystache.render( - template_searchSourceJSON, context) - assert json.loads(searchSourceJSON) - context['searchSourceJSON'] = json.dumps(searchSourceJSON) + visState = pystache.render(template_visState, context) + assert json.loads(visState) + context['visState'] = json.dumps(visState) - rendered = pystache.render(template, context) - assert json.loads(rendered) + searchSourceJSON = pystache.render( + template_searchSourceJSON, context) + assert json.loads(searchSourceJSON) + context['searchSourceJSON'] = json.dumps(searchSourceJSON) - with open(out_file, 'w') as out: - out.write(rendered) + rendered = pystache.render(template, context) + assert json.loads(rendered) + + with open(out_file, 'w') as out: + out.write(rendered) def _dashboard_for_all_tests(tests): @@ -142,21 +152,23 @@ def _dashboard_for_all_tests(tests): f.write(rendered) -def _dashboard_for_one_test(test): +def _dashboards_for_one_test(test): path = os.path.join('templates', 'dashboard-per-test.mustache') with open(path, 'r') as f: template = f.read() - context = {'test_name': test} - rendered = pystache.render(template, context) - out_file = os.path.join('dashboard', 'dashboard-%s.json' % test) - with open(out_file, 'w') as out: - out.write(rendered) + for r in ['', '-1w', '-1M', '-1y']: + context = {'test_name': test, 'range_modifier': r} + rendered = pystache.render(template, context) + name = test + r + out_file = os.path.join('dashboard', 'dashboard-%s.json' % name) + with open(out_file, 'w') as out: + out.write(rendered) def generate_dashboards(tests): _dashboard_for_all_tests(tests) for test in tests: - _dashboard_for_one_test(test) + _dashboards_for_one_test(test) def _get_test_names(): diff --git a/elastic/templates/dashboard-per-test.mustache b/elastic/templates/dashboard-per-test.mustache index a397546..c2f8f3f 100644 --- a/elastic/templates/dashboard-per-test.mustache +++ b/elastic/templates/dashboard-per-test.mustache @@ -1,8 +1,8 @@ { - "title": "Benchmarks for {{{test_name}}}", + "title": "Benchmarks for {{{test_name}}} ({{{range_modifier}}})", "hits": 0, "description": "Per-test benchmarks for {{{test_name}}}", - "panelsJSON": "[{\"col\":1,\"id\":\"{{{test_name}}}_time\",\"panelIndex\":1,\"row\":1,\"size_x\":6,\"size_y\":3,\"type\":\"visualization\"},{\"col\":1,\"id\":\"{{{test_name}}}_cpu\",\"panelIndex\":3,\"row\":4,\"size_x\":6,\"size_y\":3,\"type\":\"visualization\"},{\"size_x\":6,\"size_y\":3,\"panelIndex\":4,\"type\":\"visualization\",\"id\":\"{{{test_name}}}_memory\",\"col\":7,\"row\":1}]", + "panelsJSON": "[{\"col\":1,\"id\":\"{{{test_name}}}_time{{{range_modifier}}}\",\"panelIndex\":1,\"row\":1,\"size_x\":6,\"size_y\":3,\"type\":\"visualization\"},{\"col\":1,\"id\":\"{{{test_name}}}_cpu{{{range_modifier}}}\",\"panelIndex\":3,\"row\":4,\"size_x\":6,\"size_y\":3,\"type\":\"visualization\"},{\"size_x\":6,\"size_y\":3,\"panelIndex\":4,\"type\":\"visualization\",\"id\":\"{{{test_name}}}_memory{{{range_modifier}}}\",\"col\":7,\"row\":1}]", "optionsJSON": "{\"darkTheme\":true}", "uiStateJSON": "{}", "version": 1, -- cgit v1.2.3