From f2e1f03fc834d2accdfc642c69b43f07e4319fcc Mon Sep 17 00:00:00 2001 From: Joseph Davis Date: Tue, 6 Nov 2018 10:21:33 -0800 Subject: [PATCH] Improve metric error handling flush() should not produce a metric if value is None (causes exception in monasca-api). Fix the exception message in flush() to use the correct data structure. Change-Id: I62d31270db9e70f16d2a38a73856009c52c098e6 Story: 2004276 Task: 27825 --- monasca_agent/common/aggregator.py | 2 +- monasca_agent/common/metrics.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/monasca_agent/common/aggregator.py b/monasca_agent/common/aggregator.py index 9ed9d8a2..afe37380 100644 --- a/monasca_agent/common/aggregator.py +++ b/monasca_agent/common/aggregator.py @@ -54,7 +54,7 @@ class MetricsAggregator(object): try: metrics.extend(metric.flush()) except Exception: - log.exception('Error flushing {0} metrics.'.format(metric.name)) + log.exception('Error flushing {0} metrics.'.format(metric.metric['name'])) # Log a warning regarding metrics with old timestamps being submitted if self.num_discarded_old_points > 0: diff --git a/monasca_agent/common/metrics.py b/monasca_agent/common/metrics.py index f25d9e20..3f30768e 100644 --- a/monasca_agent/common/metrics.py +++ b/monasca_agent/common/metrics.py @@ -53,6 +53,13 @@ class Metric(object): def flush(self): if self.timestamp is None: return [] + if self.value is None: + log.error('Value of None is not supported, will not send. ' + 'Metric %s with dimensions %s at time %d', + self.metric['name'], + self.metric['dimensions'], + self.timestamp) + return [] envelope = self.measurement(self.value, self.timestamp) self.timestamp = None