Handles input aggregate for statistics
When statistics API is used with custom aggregates as input, there is an attribute error in client as it expects an aggregate dict in response. This adds the aggregate dict in response when input has an aggregate function. Change-Id: Ide13f5d16b6e4ef11cdcb9c98d85200efaf0cb91
This commit is contained in:
parent
948d96f76c
commit
9c2c1e878e
|
@ -608,6 +608,13 @@ class Connection(base.Connection):
|
|||
del stats_dict['timestamp']
|
||||
if 'count' in stats_dict:
|
||||
stats_dict['count'] = int(stats_dict['count'])
|
||||
if aggregate:
|
||||
stats_dict['aggregate'] = {}
|
||||
for a in aggregate:
|
||||
key = '%s%s' % (a.func,
|
||||
'/%s' % a.param if a.param else '')
|
||||
stats_dict['aggregate'][key] = stats_dict.get(key)
|
||||
|
||||
yield api_models.Statistics(
|
||||
unit=stats['dimensions'].get('unit'),
|
||||
period=period,
|
||||
|
|
|
@ -22,6 +22,7 @@ from oslo_utils import timeutils
|
|||
from oslotest import base
|
||||
|
||||
import ceilometer
|
||||
from ceilometer.api.controllers.v2.meters import Aggregate
|
||||
import ceilometer.storage as storage
|
||||
from ceilometer.storage import impl_monasca
|
||||
|
||||
|
@ -609,9 +610,12 @@ class MeterStatisticsTest(base.BaseTestCase):
|
|||
|
||||
sf = storage.SampleFilter()
|
||||
sf.meter = "image"
|
||||
aggregate = Aggregate()
|
||||
aggregate.func = 'min'
|
||||
sf.start_timestamp = timeutils.parse_isotime(
|
||||
'2014-10-24T12:12:42').replace(tzinfo=None)
|
||||
stats = list(conn.get_meter_statistics(sf, period=30))
|
||||
stats = list(conn.get_meter_statistics(sf, aggregate=[aggregate],
|
||||
period=30))
|
||||
|
||||
self.assertEqual(2, len(stats))
|
||||
self.assertEqual('gb', stats[0].unit)
|
||||
|
@ -623,6 +627,8 @@ class MeterStatisticsTest(base.BaseTestCase):
|
|||
stats[0].period_end.isoformat())
|
||||
self.assertEqual('2014-10-24T12:52:42',
|
||||
stats[1].period_end.isoformat())
|
||||
self.assertIsNotNone(stats[0].as_dict().get('aggregate'))
|
||||
self.assertEqual({u'min': 0.008}, stats[0].as_dict()['aggregate'])
|
||||
|
||||
|
||||
class CapabilitiesTest(base.BaseTestCase):
|
||||
|
|
Loading…
Reference in New Issue