forked from mordechai/benchmark-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stressng_pod.py
90 lines (85 loc) · 5.14 KB
/
stressng_pod.py
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
import os
from typeguard import typechecked
from benchmark_runner.common.logger.logger_time_stamp import logger_time_stamp, logger
from benchmark_runner.common.elasticsearch.elasticsearch_exceptions import ElasticSearchDataNotUploaded
from benchmark_runner.main.environment_variables import environment_variables
from benchmark_runner.benchmark_operator.benchmark_operator_workloads_operations import BenchmarkOperatorWorkloadsOperations
class StressngPod(BenchmarkOperatorWorkloadsOperations):
"""
This class runs stressng workload
"""
def __init__(self):
"""
All inherit from BenchmarkOperatorWorkloadsOperations
"""
super().__init__()
self.__name = ''
self.__workload_name = ''
self.__es_index = ''
self.__kind = ''
self.__status = ''
@logger_time_stamp
def run(self):
"""
This method runs stressng workload
:return:
"""
try:
self._prometheus_metrics_operation.init_prometheus()
if 'kata' in self._workload:
self.__kind = 'kata'
self.__name = self._workload.replace('kata', 'pod')
else:
self.__kind = 'pod'
self.__name = self._workload
self.__workload_name = self._workload.replace('_', '-')
if self._run_type == 'test_ci':
self.__es_index = 'stressng-test-ci-results'
else:
self.__es_index = 'stressng-results'
environment_variables.environment_variables_dict['kind'] = self.__kind
self._oc.create_pod_sync(yaml=os.path.join(f'{self._run_artifacts_path}', f'{self.__name}.yaml'), pod_name=f'{self.__workload_name}-workload')
self._oc.wait_for_initialized(label='app=stressng_workload', workload=self.__workload_name)
self._oc.wait_for_ready(label='app=stressng_workload', workload=self.__workload_name)
self.__status = self._oc.wait_for_pod_completed(label='app=stressng_workload', workload=self.__workload_name)
self.__status = 'complete' if self.__status else 'failed'
# prometheus queries
self._prometheus_metrics_operation.finalize_prometheus()
metric_results = self._prometheus_metrics_operation.run_prometheus_queries()
prometheus_result = self._prometheus_metrics_operation.parse_prometheus_metrics(data=metric_results)
# system metrics
if environment_variables.environment_variables_dict['system_metrics']:
self.system_metrics_collector(workload=self.__workload_name)
# save run artifacts logs
run_artifacts_url = self._create_run_artifacts(workload=self.__workload_name)
if self._es_host:
# verify that data upload to elastic search according to unique uuid
ids = self._verify_elasticsearch_data_uploaded(index=self.__es_index, uuid=self._oc.get_long_uuid(workload=self.__workload_name))
# update metadata
for id in ids:
self._update_elasticsearch_index(index=self.__es_index, id=id, kind=self.__kind, status=self.__status, run_artifacts_url=run_artifacts_url, prometheus_result=prometheus_result)
self._oc.delete_pod_sync(
yaml=os.path.join(f'{self._run_artifacts_path}', f'{self.__name}.yaml'),
pod_name=f'{self.__workload_name}-workload')
except ElasticSearchDataNotUploaded as err:
self.tear_down_pod_after_error(yaml=os.path.join(f'{self._run_artifacts_path}', f'{self.__name}.yaml'),
pod_name=f'{self.__workload_name}-workload')
raise err
except Exception as err:
# save run artifacts logs
if self._oc.pod_exists(pod_name='benchmark-controller-manager'):
self._create_pod_log(label='benchmark-controller-manager')
if self._oc.pod_exists(pod_name=self.__workload_name):
self._create_pod_log(label=self.__workload_name)
run_artifacts_url = os.path.join(self._environment_variables_dict.get('run_artifacts_url', ''), f'{self._get_run_artifacts_hierarchy(workload_name=self.__workload_name, is_file=True)}-{self._time_stamp_format}.tar.gz')
if self._es_host:
ids = self._verify_elasticsearch_data_uploaded(index=self.__es_index, uuid=self._oc.get_long_uuid(workload=self.__workload_name), timeout=3)
if ids:
for id in ids:
self._update_elasticsearch_index(index=self.__es_index, id=id, kind=self.__kind, status='failed', run_artifacts_url=run_artifacts_url)
else:
self._upload_to_elasticsearch(index=self.__es_index, kind=self.__kind, status='failed', run_artifacts_url=run_artifacts_url, uuid=self._uuid)
self._verify_elasticsearch_data_uploaded(index=self.__es_index, uuid=self._uuid)
self.tear_down_pod_after_error(yaml=os.path.join(f'{self._run_artifacts_path}', f'{self.__name}.yaml'),
pod_name=f'{self.__workload_name}-workload')
raise err