def test_get_all_rotations(self): rotation = 300 start = datetime.datetime(2013, 1, 1, 0, 0, 0) end = datetime.datetime(2013, 1, 1, 1, 1, 0) end_round = datetime.datetime(2013, 1, 1, 1, 0, 0) self.assertEqual(len(_get_all_rotations(start, end, rotation)), 12) self.assertEqual(len(_get_all_rotations(start, end, rotation, include_partial=True)), 13) self.assertEqual(len(_get_all_rotations(start, end_round, rotation, include_partial=True)), 12) self.assertEqual(len(_get_all_rotations(start, end, 3600)), 1)
def _run_for_metric(self, metric_id, ts_from, is_hot): if self._is_rollup_processed(metric_id, ts_from): return ts_to = ts_from + datetime.timedelta(seconds=self._rollup_out) values = [] for ts in _get_all_rotations(ts_from, ts_to, self._rollup_in): params = [metric_id, ts, ValueSequence(_get_all_shards(self._shard_from, self._shard_to))] values += self._CounterBase.session.execute(self._read_stmt, params) self._save_metric_rollup(metric_id, ts_from, values, is_hot)
def run_rollup(self): for metric in self._CounterBase.get_all_metrics(): ts_rotations = _get_all_rotations(self._start, self._end, self._rollup_out, include_partial=self._include_hot_counters) hot_rotation = self._include_hot_counters and ts_rotations[-1] or None for ts_from in ts_rotations: self._run_for_metric(metric, ts_from, ts_from == hot_rotation)