don't raise error if unaggregated empty

new lz4 library doesn't like handling empty binary. if we kill
agent during computation of aggregates, the unaggregated object
might have been created (in ceph/redis case) but it may not have saved
unaggregated measures leaving the object blank.

this patch returns None and let's workflow proceed as if new if
object is empty since in scenario above, the original raw measures
will not have been cleared from unprocessed so they will still be
processed again.

also, fixes redis issue where passing in None makes the redis actually
store 'None'.

Change-Id: I358e50ccadff721348630688c47544db6553e96b
Closes-Bug: #1676519
This commit is contained in:
gord chung 2017-03-27 19:54:57 +00:00
parent 3841edcb10
commit 4ac9d53383
3 changed files with 23 additions and 1 deletions

View File

@ -96,6 +96,8 @@ class CarbonaraBasedStorage(storage.StorageDriver):
self._get_unaggregated_timeserie(
metric)
)
if not raw_measures:
return
LOG.debug(
"Retrieve unaggregated measures "
"for %s in %.2fs",

View File

@ -55,7 +55,7 @@ class RedisStorage(_carbonara.CarbonaraBasedStorage):
key = self._metric_key(metric)
if self._client.exists(key):
raise storage.MetricAlreadyExists(metric)
self._client.hset(key, self._unaggregated_field(), None)
self._client.hset(key, self._unaggregated_field(), '')
def _store_unaggregated_timeserie(self, metric, data, version=3):
self._client.hset(self._metric_key(metric),

View File

@ -76,6 +76,26 @@ class TestStorageDriver(tests_base.TestCase):
self.assertIn((utils.datetime_utc(2014, 1, 1, 13), 3600.0, 1), m)
self.assertIn((utils.datetime_utc(2014, 1, 1, 13), 300.0, 1), m)
def test_aborted_initial_processing(self):
self.storage.incoming.add_measures(self.metric, [
storage.Measure(utils.dt_to_unix_ns(2014, 1, 1, 12, 0, 1), 5),
])
with mock.patch.object(self.storage, '_store_unaggregated_timeserie',
side_effect=Exception):
try:
self.trigger_processing()
except Exception:
pass
with mock.patch('gnocchi.storage._carbonara.LOG') as LOG:
self.trigger_processing()
self.assertFalse(LOG.error.called)
m = self.storage.get_measures(self.metric)
self.assertIn((utils.datetime_utc(2014, 1, 1), 86400.0, 5.0), m)
self.assertIn((utils.datetime_utc(2014, 1, 1, 12), 3600.0, 5.0), m)
self.assertIn((utils.datetime_utc(2014, 1, 1, 12), 300.0, 5.0), m)
def test_list_metric_with_measures_to_process(self):
metrics = self.storage.incoming.list_metric_with_measures_to_process(
None, None, full=True)