Merge "Statistics api failure when end time is not used"
This commit is contained in:
commit
dbb0fcb67c
1
AUTHORS
1
AUTHORS
@ -8,6 +8,7 @@ Anh Tran <anhtt@vn.fujitsu.com>
|
||||
Artur Basiak <artur.basiak@ts.fujitsu.com>
|
||||
Ben Motz <bmotz@cray.com>
|
||||
Bertrand Lallau <bertrand.lallau@thalesgroup.com>
|
||||
Boris Bobrov <bbobrov@suse.com>
|
||||
Brad Klein <bradley.klein@twcable.com>
|
||||
Cao Xuan Hoang <hoangcx@vn.fujitsu.com>
|
||||
Christoph Held <christoph.held@est.fujitsu.com>
|
||||
|
@ -776,7 +776,10 @@ class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
||||
columns.extend([x for x in ['avg', 'min', 'max', 'count', 'sum'] if x in statistics])
|
||||
|
||||
start_time = datetime.utcfromtimestamp(start_timestamp)
|
||||
end_time = datetime.utcfromtimestamp(end_timestamp)
|
||||
if end_timestamp:
|
||||
end_time = datetime.utcfromtimestamp(end_timestamp)
|
||||
else:
|
||||
end_time = datetime.utcnow()
|
||||
|
||||
for series in series_list:
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Copyright 2015 Cray Inc. All Rights Reserved.
|
||||
# (C) Copyright 2016-2018 Hewlett Packard Enterprise Development LP
|
||||
# Copyright 2017 Fujitsu LIMITED
|
||||
# (C) Copyright 2017 SUSE LLC
|
||||
# (C) Copyright 2017-2018 SUSE LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@ -477,6 +477,54 @@ class TestRepoMetricsCassandra(base.BaseTestCase):
|
||||
}
|
||||
], result)
|
||||
|
||||
cassandra_future_mock.result.side_effect = [
|
||||
[
|
||||
Metric(
|
||||
metric_id=binascii.unhexlify(b"01d39f19798ed27bbf458300bf843edd17654614"),
|
||||
metric_name='cpu.idle_perc',
|
||||
dimensions=[
|
||||
'device\trootfs',
|
||||
'hostname\thost0',
|
||||
'hosttype\tnative',
|
||||
'mount_point\t/']
|
||||
)
|
||||
],
|
||||
[
|
||||
Measurement(self._convert_time_string("2016-05-19T11:58:24Z"), 95.0, '{}'),
|
||||
Measurement(self._convert_time_string("2016-05-19T11:58:25Z"), 97.0, '{}'),
|
||||
Measurement(self._convert_time_string("2016-05-19T11:58:26Z"), 94.0, '{}'),
|
||||
Measurement(self._convert_time_string("2016-05-19T11:58:27Z"), 96.0, '{}'),
|
||||
]
|
||||
]
|
||||
|
||||
result = repo.metrics_statistics(
|
||||
"tenant_id",
|
||||
"region",
|
||||
name="cpu.idle_perc",
|
||||
dimensions=None,
|
||||
start_timestamp=start_timestamp,
|
||||
end_timestamp=None,
|
||||
statistics=['avg', 'min', 'max', 'count', 'sum'],
|
||||
period=300,
|
||||
offset=None,
|
||||
limit=1,
|
||||
merge_metrics_flag=True,
|
||||
group_by=None)
|
||||
|
||||
self.assertEqual([
|
||||
{
|
||||
u'dimensions': {'device': 'rootfs',
|
||||
'hostname': 'host0',
|
||||
'hosttype': 'native',
|
||||
'mount_point': '/'},
|
||||
u'end_time': u'2016-05-19T12:03:23.999Z',
|
||||
u'statistics': [[u'2016-05-19T11:58:24.000Z', 95.5, 94.0, 97.0, 4, 382.0]],
|
||||
u'name': u'cpu.idle_perc',
|
||||
u'columns': [u'timestamp', 'avg', 'min', 'max', 'count', 'sum'],
|
||||
u'id': '01d39f19798ed27bbf458300bf843edd17654614'
|
||||
}
|
||||
], result)
|
||||
|
||||
@patch("monasca_api.common.repositories.cassandra."
|
||||
"metrics_repository.Cluster.connect")
|
||||
def test_alarm_history(self, cassandra_connect_mock):
|
||||
|
@ -1,5 +1,5 @@
|
||||
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
|
||||
# (C) Copyright 2017 SUSE LLC
|
||||
# (C) Copyright 2017-2018 SUSE LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@ -121,11 +121,20 @@ class TestStatistics(base.BaseMonascaTest):
|
||||
|
||||
@decorators.attr(type="gate")
|
||||
def test_list_statistics(self):
|
||||
self._test_list_statistic(with_end_time=True)
|
||||
|
||||
@decorators.attr(type="gate")
|
||||
def test_list_statistics_with_no_end_time(self):
|
||||
self._test_list_statistic(with_end_time=False)
|
||||
|
||||
def _test_list_statistic(self, with_end_time=True):
|
||||
query_parms = '?name=' + str(self._test_name) + \
|
||||
'&statistics=' + urlparse.quote('avg,sum,min,max,count') + \
|
||||
'&start_time=' + str(self._start_time_iso) + \
|
||||
'&end_time=' + str(self._end_time_iso) + \
|
||||
'&merge_metrics=true' + '&period=100000'
|
||||
if with_end_time is True:
|
||||
query_parms += '&end_time=' + str(self._end_time_iso)
|
||||
|
||||
resp, response_body = self.monasca_client.list_statistics(
|
||||
query_parms)
|
||||
self.assertEqual(200, resp.status)
|
||||
|
Loading…
Reference in New Issue
Block a user