[MongoDB] Improves get_meter_statistics method

Now period_end that returns in get_meter_statistic method
doesn't have correct value on MongoDB backend if period
doesn't set in query.

This patch improves that.

Change-Id: I980f630e0a113638d4b06608ae999ae56d92338f
Closes-Bug: #1372442
This commit is contained in:
Igor Degtiarov 2015-01-22 16:25:36 +02:00
parent 3a58d322fd
commit 262e2cf2f3
2 changed files with 11 additions and 4 deletions

View File

@ -330,7 +330,10 @@ class Connection(pymongo_base.Connection):
res.duration_start = values[i].duration_start;
if ( values[i].duration_end > res.duration_end )
res.duration_end = values[i].duration_end;
}
if ( values[i].period_start < res.period_start )
res.period_start = values[i].period_start;
if ( values[i].period_end > res.period_end )
res.period_end = values[i].period_end; }
return res;
}
""")
@ -339,8 +342,7 @@ class Connection(pymongo_base.Connection):
function (key, value) {
%(aggregate_val)s
value.duration = (value.duration_end - value.duration_start) / 1000;
value.period = NumberInt((value.period_end - value.period_start)
/ 1000);
value.period = NumberInt(%(period)d);
return value;
}""")
@ -894,7 +896,8 @@ class Connection(pymongo_base.Connection):
)
reduce_stats = self.REDUCE_STATS % reduce_params
finalize_params = dict(aggregate_val=sub('finalize', aggregate))
finalize_params = dict(aggregate_val=sub('finalize', aggregate),
period=(period if period else 0))
finalize_stats = self.FINALIZE_STATS % finalize_params
results = self.db.meter.map_reduce(

View File

@ -1182,6 +1182,10 @@ class StatisticsTest(DBTestBase,
self.assertEqual(10, results.max)
self.assertEqual(27, results.sum)
self.assertEqual(9, results.avg)
self.assertEqual(datetime.datetime(2012, 9, 25, 10, 30),
results.period_start)
self.assertEqual(datetime.datetime(2012, 9, 25, 12, 32),
results.period_end)
def test_by_user(self):
f = storage.SampleFilter(