Merge "Ensure missing period is treated consistently"
This commit is contained in:
commit
d9c4de87af
@ -399,7 +399,7 @@ class Connection(base.Connection):
|
|||||||
return make_query_from_filter(query, event_filter)
|
return make_query_from_filter(query, event_filter)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _stats_result_to_dict(result, period_start, period_end):
|
def _stats_result_to_dict(result, period, period_start, period_end):
|
||||||
return {'count': result.count,
|
return {'count': result.count,
|
||||||
'min': result.min,
|
'min': result.min,
|
||||||
'max': result.max,
|
'max': result.max,
|
||||||
@ -409,8 +409,7 @@ class Connection(base.Connection):
|
|||||||
'duration_end': result.tsmax,
|
'duration_end': result.tsmax,
|
||||||
'duration': timeutils.delta_seconds(result.tsmin,
|
'duration': timeutils.delta_seconds(result.tsmin,
|
||||||
result.tsmax),
|
result.tsmax),
|
||||||
'period': int(timeutils.delta_seconds(period_start,
|
'period': period,
|
||||||
period_end)),
|
|
||||||
'period_start': period_start,
|
'period_start': period_start,
|
||||||
'period_end': period_end}
|
'period_end': period_end}
|
||||||
|
|
||||||
@ -437,7 +436,7 @@ class Connection(base.Connection):
|
|||||||
res = self._make_stats_query(event_filter).all()[0]
|
res = self._make_stats_query(event_filter).all()[0]
|
||||||
|
|
||||||
if not period:
|
if not period:
|
||||||
return [self._stats_result_to_dict(res, res.tsmin, res.tsmax)]
|
return [self._stats_result_to_dict(res, 0, res.tsmin, res.tsmax)]
|
||||||
|
|
||||||
query = self._make_stats_query(event_filter)
|
query = self._make_stats_query(event_filter)
|
||||||
# HACK(jd) This is an awful method to compute stats by period, but
|
# HACK(jd) This is an awful method to compute stats by period, but
|
||||||
@ -455,9 +454,12 @@ class Connection(base.Connection):
|
|||||||
period_end = period_start + datetime.timedelta(seconds=period)
|
period_end = period_start + datetime.timedelta(seconds=period)
|
||||||
q = query.filter(Meter.timestamp >= period_start)
|
q = query.filter(Meter.timestamp >= period_start)
|
||||||
q = q.filter(Meter.timestamp < period_end)
|
q = q.filter(Meter.timestamp < period_end)
|
||||||
results.append(self._stats_result_to_dict(q.all()[0],
|
results.append(self._stats_result_to_dict(
|
||||||
period_start,
|
result=q.all()[0],
|
||||||
period_end))
|
period=int(timeutils.delta_seconds(period_start, period_end)),
|
||||||
|
period_start=period_start,
|
||||||
|
period_end=period_end,
|
||||||
|
))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
@ -774,6 +774,14 @@ class StatisticsTest(DBTestBase):
|
|||||||
assert results['sum'] == 27
|
assert results['sum'] == 27
|
||||||
assert results['avg'] == 9
|
assert results['avg'] == 9
|
||||||
|
|
||||||
|
def test_no_period_in_query(self):
|
||||||
|
f = storage.EventFilter(
|
||||||
|
user='user-5',
|
||||||
|
meter='volume.size',
|
||||||
|
)
|
||||||
|
results = self.conn.get_meter_statistics(f)[0]
|
||||||
|
assert results['period'] == 0
|
||||||
|
|
||||||
def test_period_is_int(self):
|
def test_period_is_int(self):
|
||||||
f = storage.EventFilter(
|
f = storage.EventFilter(
|
||||||
meter='volume.size',
|
meter='volume.size',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user