Merge "Avoid DivByZero if there is no metrics to collect"
This commit is contained in:
commit
249ea00192
@ -324,17 +324,45 @@ class Worker(BaseWorker):
|
|||||||
# system in workers
|
# system in workers
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
with futurist.ThreadPoolExecutor(
|
return self._do_execute_collection(_get_result, metrics)
|
||||||
max_workers=CONF.orchestrator.max_threads) as tpool:
|
|
||||||
futs = [tpool.submit(_get_result, metric) for metric in metrics]
|
def _do_execute_collection(self, _get_result, metrics):
|
||||||
LOG.debug(self._log_prefix +
|
"""Execute the metric measurement collection
|
||||||
'Collecting {} metrics.'.format(len(metrics)))
|
|
||||||
results = [r.result() for r in waiters.wait_for_all(futs).done]
|
When executing this method a ZeroDivisionError might be raised.
|
||||||
LOG.debug(self._log_prefix + 'Collecting {} metrics took {}s '
|
This happens when no executions have happened in the
|
||||||
'total, with {}s average'.format(
|
`futurist.ThreadPoolExecutor`; then, when calling the
|
||||||
tpool.statistics.executed,
|
`average_runtime`, the exception is thrown. In such a case, there is
|
||||||
tpool.statistics.runtime,
|
no need for further actions, and we can ignore the error.
|
||||||
tpool.statistics.average_runtime))
|
|
||||||
|
:param _get_result: the method to execute and get the metrics
|
||||||
|
:param metrics: the list of metrics to be collected
|
||||||
|
:return: the metrics measurements
|
||||||
|
"""
|
||||||
|
results = []
|
||||||
|
try:
|
||||||
|
with futurist.ThreadPoolExecutor(
|
||||||
|
max_workers=CONF.orchestrator.max_threads) as tpool:
|
||||||
|
|
||||||
|
futs = [tpool.submit(_get_result, metric)
|
||||||
|
for metric in metrics]
|
||||||
|
|
||||||
|
LOG.debug(self._log_prefix +
|
||||||
|
'Collecting [{}] metrics.'.format(metrics))
|
||||||
|
|
||||||
|
results = [r.result() for r in waiters.wait_for_all(futs).done]
|
||||||
|
|
||||||
|
log_message = self._log_prefix + \
|
||||||
|
"Collecting {} metrics took {}s total, with {}s average"
|
||||||
|
|
||||||
|
LOG.debug(log_message.format(tpool.statistics.executed,
|
||||||
|
tpool.statistics.runtime,
|
||||||
|
tpool.statistics.average_runtime))
|
||||||
|
|
||||||
|
except ZeroDivisionError as zeroDivisionError:
|
||||||
|
LOG.debug("Ignoring ZeroDivisionError for metrics [%s]: [%s].",
|
||||||
|
metrics, zeroDivisionError)
|
||||||
|
|
||||||
return dict(filter(lambda x: x[1] is not None, results))
|
return dict(filter(lambda x: x[1] is not None, results))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user