Fixes statistics API when timestamp is specified
When timestamp/timestamp range is specified, statistics API fails because timestamps are not being converted to ISO 8601 formatted times, also when parsing the response, the timezone offsets are not being dropped. Monasca API expects timestamps in ISO 8601 format and ceilometer statistics API expects timestamp in response in a timezone-naive format. This patch fixes that so that statistics API works when timestamps are specified in input filter. Change-Id: I67055a661478fc15a06c3714f431c484f303658c
This commit is contained in:
parent
4b572024da
commit
948d96f76c
|
@ -554,6 +554,11 @@ class Connection(base.Connection):
|
|||
if not filter.start_timestamp:
|
||||
filter.start_timestamp = timeutils.isotime(
|
||||
datetime.datetime(1970, 1, 1))
|
||||
else:
|
||||
filter.start_timestamp = timeutils.isotime(filter.start_timestamp)
|
||||
|
||||
if filter.end_timestamp:
|
||||
filter.end_timestamp = timeutils.isotime(filter.end_timestamp)
|
||||
|
||||
# TODO(monasca): Add this a config parameter
|
||||
allowed_stats = ['avg', 'min', 'max', 'sum', 'count']
|
||||
|
@ -596,8 +601,10 @@ class Connection(base.Connection):
|
|||
for stats in stats_list:
|
||||
for s in stats['statistics']:
|
||||
stats_dict = self._convert_to_dict(s, stats['columns'])
|
||||
ts_start = timeutils.parse_isotime(stats_dict['timestamp'])
|
||||
ts_end = ts_start + datetime.timedelta(0, period)
|
||||
ts_start = timeutils.parse_isotime(
|
||||
stats_dict['timestamp']).replace(tzinfo=None)
|
||||
ts_end = (ts_start + datetime.timedelta(
|
||||
0, period)).replace(tzinfo=None)
|
||||
del stats_dict['timestamp']
|
||||
if 'count' in stats_dict:
|
||||
stats_dict['count'] = int(stats_dict['count'])
|
||||
|
|
|
@ -609,6 +609,8 @@ class MeterStatisticsTest(base.BaseTestCase):
|
|||
|
||||
sf = storage.SampleFilter()
|
||||
sf.meter = "image"
|
||||
sf.start_timestamp = timeutils.parse_isotime(
|
||||
'2014-10-24T12:12:42').replace(tzinfo=None)
|
||||
stats = list(conn.get_meter_statistics(sf, period=30))
|
||||
|
||||
self.assertEqual(2, len(stats))
|
||||
|
@ -617,9 +619,9 @@ class MeterStatisticsTest(base.BaseTestCase):
|
|||
self.assertEqual(0.008, stats[0].min)
|
||||
self.assertEqual(0.018, stats[1].min)
|
||||
self.assertEqual(30, stats[0].period)
|
||||
self.assertEqual('2014-10-24T12:12:42+00:00',
|
||||
self.assertEqual('2014-10-24T12:12:42',
|
||||
stats[0].period_end.isoformat())
|
||||
self.assertEqual('2014-10-24T12:52:42+00:00',
|
||||
self.assertEqual('2014-10-24T12:52:42',
|
||||
stats[1].period_end.isoformat())
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue