6 from dashboard.common import elastic_access
7 from dashboard.common import logger_utils
8 from dashboard.conf import config
9 from dashboard.conf import testcases
10 from dashboard_assembler import DashboardAssembler
11 from visualization_assembler import VisualizationAssembler
13 logger = logger_utils.DashboardLogger('elastic2kibana').get
15 parser = argparse.ArgumentParser()
16 parser.add_argument("-c", "--config-file",
18 help="Config file location")
20 args = parser.parse_args()
21 CONF = config.APIConfig().parse(args.config_file)
23 _installers = {'fuel', 'apex', 'compass', 'joid'}
26 class KibanaConstructor(object):
28 super(KibanaConstructor, self).__init__()
32 for project, case_dicts in testcases.testcases_yaml.items():
33 for case in case_dicts:
34 self._construct_by_case(project, case)
37 def _construct_by_case(self, project, case):
38 case_name = case.get('name')
39 vis_ps = case.get('visualizations')
40 family = case.get('test_family')
42 self._construct_by_vis(project, case_name, family, vis_p)
44 def _construct_by_vis(self, project, case, family, vis_p):
45 for installer in _installers:
46 pods_and_scenarios = self._get_pods_and_scenarios(project,
49 for pod, scenarios in pods_and_scenarios.iteritems():
50 visualizations = self._construct_visualizations(project,
58 dashboard = DashboardAssembler(project,
66 self._set_js_dict(case,
74 def _construct_visualizations(project,
83 for scenario in scenarios:
84 visualizations.append(VisualizationAssembler(project,
94 def _set_js_dict(self, case, pod, installer, family, metric, id):
95 test_label = '{} {}'.format(case, metric)
96 if family not in self.js_dict:
97 self.js_dict[family] = {}
99 js_test_family = self.js_dict[family]
101 if test_label not in js_test_family:
102 js_test_family[test_label] = {}
104 js_test_label = js_test_family[test_label]
106 if installer not in js_test_label:
107 js_test_label[installer] = {}
109 js_installer = js_test_label[installer]
110 js_installer[pod] = CONF.kibana_url + '#/dashboard/' + id
113 with open(CONF.js_path, 'w+') as conf_js_fdesc:
114 conf_js_fdesc.write('var kibana_dashboard_links = ')
115 conf_js_fdesc.write(str(self.js_dict).replace("u'", "'"))
117 def _get_pods_and_scenarios(self, project, case, installer):
118 query = json.JSONEncoder().encode({
125 {"match": {"installer": installer}},
126 {"match": {"project_name": project}},
127 {"match": {"case_name": case}}
133 elastic_data = elastic_access.get_docs(CONF.index_url,
137 pods_and_scenarios = {}
139 for data in elastic_data:
140 pod = data['pod_name']
141 if pod in pods_and_scenarios:
142 pods_and_scenarios[pod].add(data['scenario'])
144 pods_and_scenarios[pod] = {data['scenario']}
146 if 'all' in pods_and_scenarios:
147 pods_and_scenarios['all'].add(data['scenario'])
149 pods_and_scenarios['all'] = {data['scenario']}
151 return pods_and_scenarios
155 KibanaConstructor().construct().config_js()