Skip to content
Snippets Groups Projects
Commit 56f93420 authored by sguazt's avatar sguazt
Browse files

Core: small optimization (avoid collecting measures for sinks if the...

Core: small optimization (avoid collecting measures for sinks if the associated thread is not running, that is when no sink is active)
parent 6b55524f
No related branches found
No related tags found
No related merge requests found
......@@ -141,7 +141,15 @@ class MetaMonitor(ABC):
#[ALTERNATIVE #2]
def _measures_sink_runner(self, sinks):
if sinks is None or len(sinks) == 0:
#TODO: in the future, support the possibility to add sinks at runtime.
# In this case, this runner should be changed as follows:
# 1. it does not terminate if the `sinks` parameter is empty (see
# the `if` statement below),
# 2. it appends measures (extracted from `_measures_sink_queue`) to
# `meaures` only if there is at least a sink to which sending them.
if not sinks:
# Terminate this runner as there is no sink to which sending measures
return
#FIXME makes these two settings a parameter
......@@ -250,14 +258,15 @@ class MetaMonitor(ABC):
granularity=self.conf.granularity)
if samples is not None:
_metrics_samples.append(samples)
for sample in samples['values']:
measure = Measure(object_ns = self.conf.platform + '-generic', #TODO: let the subclass decide what the object namespace should be (e.g., to consider the project ID, the region, etc.)
object_id = _instance,
metric = _requested_metric,
timestamp = sample['timestamp'],
unit = sample['unit'] if 'unit' in sample else None,
value = sample['value'] if 'value' in sample else sample['error']) #TODO: add a conf option to decide whether or not to send errors to sinks
self._measures_sink_queue.put(measure)
if self._measures_sink_thread.is_alive():
for sample in samples['values']:
measure = Measure(object_ns = self.conf.platform + '-generic', #TODO: let the subclass decide what the object namespace should be (e.g., to consider the project ID, the region, etc.)
object_id = _instance,
metric = _requested_metric,
timestamp = sample['timestamp'],
unit = sample['unit'] if 'unit' in sample else None,
value = sample['value'] if 'value' in sample else sample['error']) #TODO: add a conf option to decide whether or not to send errors to sinks
self._measures_sink_queue.put(measure)
#logging.debug("[" + self.__class__.__name__ + "] Sending message: " + str({"instance_id": _instance, "measurements": _metrics_samples}))
self.measurements_queue.put({"instance_id": _instance, "measurements": _metrics_samples})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment