7 from common import elastic_access
8 from common import logger_utils
9 from conf import config
10 from conf import testcases
11 from dashboard_assembler import DashboardAssembler
12 from visualization_assembler import VisualizationAssembler
14 logger = logger_utils.DashboardLogger('elastic2kibana').get
16 parser = argparse.ArgumentParser()
17 parser.add_argument("-c", "--config-file",
19 help="Config file location")
21 args = parser.parse_args()
22 CONF = config.APIConfig().parse(args.config_file)
24 _installers = {'fuel', 'apex', 'compass', 'joid'}
27 class KibanaConstructor(object):
29 super(KibanaConstructor, self).__init__()
33 for project, case_dicts in testcases.testcases_yaml.items():
34 for case in case_dicts:
35 self._construct_by_case(project, case)
38 def _construct_by_case(self, project, case):
39 case_name = case.get('name')
40 vis_ps = case.get('visualizations')
41 family = case.get('test_family')
43 self._construct_by_vis(project, case_name, family, vis_p)
45 def _construct_by_vis(self, project, case, family, vis_p):
46 for installer in _installers:
47 pods_and_scenarios = self._get_pods_and_scenarios(project,
50 for pod, scenarios in pods_and_scenarios.iteritems():
51 visualizations = self._construct_visualizations(project,
59 dashboard = DashboardAssembler(project,
67 self._set_js_dict(case,
75 def _construct_visualizations(project,
84 for scenario in scenarios:
85 visualizations.append(VisualizationAssembler(project,
95 def _set_js_dict(self, case, pod, installer, family, metric, id):
96 test_label = '{} {}'.format(case, metric)
97 if family not in self.js_dict:
98 self.js_dict[family] = {}
100 js_test_family = self.js_dict[family]
102 if test_label not in js_test_family:
103 js_test_family[test_label] = {}
105 js_test_label = js_test_family[test_label]
107 if installer not in js_test_label:
108 js_test_label[installer] = {}
110 js_installer = js_test_label[installer]
111 js_installer[pod] = CONF.kibana_url + '#/dashboard/' + id
114 with open(CONF.js_path, 'w+') as conf_js_fdesc:
115 conf_js_fdesc.write('var kibana_dashboard_links = ')
116 conf_js_fdesc.write(str(self.js_dict).replace("u'", "'"))
118 def _get_pods_and_scenarios(self, project, case, installer):
119 query = json.JSONEncoder().encode({
126 {"match": {"installer": installer}},
127 {"match": {"project_name": project}},
128 {"match": {"case_name": case}}
134 elastic_data = elastic_access.get_docs(
135 urlparse.urljoin(CONF.es_url, '/testapi/results'),
139 pods_and_scenarios = {}
141 for data in elastic_data:
142 pod = data['pod_name']
143 if pod in pods_and_scenarios:
144 pods_and_scenarios[pod].add(data['scenario'])
146 pods_and_scenarios[pod] = {data['scenario']}
148 if 'all' in pods_and_scenarios:
149 pods_and_scenarios['all'].add(data['scenario'])
151 pods_and_scenarios['all'] = {data['scenario']}
153 return pods_and_scenarios
157 KibanaConstructor().construct().config_js()