Merge "Fix Metric Statistics period call"
This commit is contained in:
commit
a38b00eaf2
|
@ -1,4 +1,4 @@
|
|||
# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP
|
||||
# (C) Copyright 2014-2018 Hewlett Packard Enterprise Development LP
|
||||
# Copyright 2015 Cray Inc. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
|
@ -777,7 +777,7 @@ class MetricsRepository(metrics_repository.AbstractMetricsRepository):
|
|||
if group_by:
|
||||
items.extend(group_by)
|
||||
if period:
|
||||
items.append("time(" + str(period) + "s)")
|
||||
items.append("time(" + str(period) + "s) fill(none)")
|
||||
clause = " group by " + ','.join(items)
|
||||
else:
|
||||
clause = ""
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright 2015 Cray Inc. All Rights Reserved.
|
||||
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
||||
# (C) Copyright 2016-2018 Hewlett Packard Enterprise Development LP
|
||||
# Copyright 2017 Fujitsu LIMITED
|
||||
# (C) Copyright 2017 SUSE LLC
|
||||
#
|
||||
|
@ -131,6 +131,47 @@ class TestRepoMetricsInfluxDB(base.BaseTestCase):
|
|||
},
|
||||
}])
|
||||
|
||||
@patch('monasca_api.common.repositories.influxdb.'
|
||||
'metrics_repository.client.InfluxDBClient')
|
||||
def test_metrics_statistics(self, influxdb_client_mock):
|
||||
mock_client = influxdb_client_mock.return_value
|
||||
mock_client.query.return_value.raw = {
|
||||
u'series': [{
|
||||
u'values': [[
|
||||
u'1970-01-01T00:00:00Z', 0.047
|
||||
]],
|
||||
u'name': u'cpu.utilization',
|
||||
u'columns': [u'time', u'mean']}],
|
||||
u'statement_id': 0
|
||||
}
|
||||
|
||||
tenant_id = '1'
|
||||
region = 'USA'
|
||||
name = 'cpu.utilization'
|
||||
start_timestamp = 1484036107.86
|
||||
statistics = [u"avg"]
|
||||
limit = 10000
|
||||
dimensions = None
|
||||
end_timestamp = None
|
||||
period = None
|
||||
offset = None
|
||||
merge_metrics_flag = None
|
||||
group_by = None
|
||||
|
||||
repo = influxdb_repo.MetricsRepository()
|
||||
stats_list = repo.metrics_statistics(tenant_id, region, name,
|
||||
dimensions, start_timestamp,
|
||||
end_timestamp, statistics,
|
||||
period, offset, limit,
|
||||
merge_metrics_flag, group_by)
|
||||
expected_result = [{
|
||||
u'columns': [u'timestamp', u'avg'],
|
||||
u'dimensions': {u'mean': 0.047, u'time': u'1970-01-01T00:00:00Z'},
|
||||
u'id': '0',
|
||||
u'name': u'cpu.utilization',
|
||||
u'statistics': [[u'1970-01-01T00:00:00Z', 0.047]]}]
|
||||
self.assertEqual(stats_list, expected_result)
|
||||
|
||||
@patch("monasca_api.common.repositories.influxdb."
|
||||
"metrics_repository.client.InfluxDBClient")
|
||||
def test_list_dimension_values(self, influxdb_client_mock):
|
||||
|
|
|
@ -384,6 +384,25 @@ class TestStatistics(base.BaseMonascaTest):
|
|||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(expected_elements, response_body['elements'])
|
||||
|
||||
@decorators.attr(type="gate")
|
||||
def test_list_statistics_with_long_start_time(self):
|
||||
query_parms = '?name=' + str(self._test_name) + \
|
||||
'&statistics=' + urlparse.quote('avg,sum,min,max,count') + \
|
||||
'&start_time=' + "2017-01-01T00:00:00.00Z" + \
|
||||
'&end_time=' + str(self._end_time_iso) + \
|
||||
'&merge_metrics=true' + '&period=100000'
|
||||
resp, response_body = self.monasca_client.list_statistics(
|
||||
query_parms)
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertTrue(set(['links', 'elements']) == set(response_body))
|
||||
element = response_body['elements'][0]
|
||||
self._verify_element(element)
|
||||
column = element['columns']
|
||||
num_statistics_method = 5
|
||||
statistics = element['statistics'][0]
|
||||
self._verify_column_and_statistics(
|
||||
column, num_statistics_method, statistics, self.metric_values)
|
||||
|
||||
@decorators.attr(type="gate")
|
||||
@decorators.attr(type=['negative'])
|
||||
def test_list_statistics_with_no_merge_metrics(self):
|
||||
|
|
Loading…
Reference in New Issue