Bugfix: Forbid colon in dimension name

Monasca-Agent http_check plugin creates
dimensions which contain multiple colon:
url:http://192.168.10.4:5601

This bugfix makes it possible to query for
metrics with such dimensions. Until now an
exception was thrown.

Closes-Bug: 1668937
Change-Id: I39ed6fba99491630f6a7e0c67743b807e3529461
This commit is contained in:
Kamil Choroba 2017-03-01 14:50:29 +01:00
parent 515f8ee86b
commit a05f8998e6
1 changed files with 36 additions and 0 deletions

View File

@ -216,6 +216,42 @@ class TestMetrics(base.BaseMonascaTest):
"metrics = 0"
self.fail(error_msg)
@test.attr(type='gate')
def test_create_metric_with_colon_in_dimension_value(self):
name = data_utils.rand_name('name')
key = 'url'
value = 'http://localhost:8070/v2.0'
timestamp = int(round(time.time() * 1000))
time_iso = helpers.timestamp_to_iso(timestamp)
end_timestamp = int(round((time.time() + 3600 * 24) * 1000))
end_time_iso = helpers.timestamp_to_iso(end_timestamp)
metric = helpers.create_metric(name=name,
dimensions={key: value})
resp, response_body = self.monasca_client.create_metrics(metric)
self.assertEqual(204, resp.status)
query_param = '?name=' + name + '&start_time=' + time_iso + \
'&end_time=' + end_time_iso + \
'&dimensions=' + key + ':' + value
for i in xrange(constants.MAX_RETRIES):
resp, response_body = self.monasca_client. \
list_measurements(query_param)
self.assertEqual(200, resp.status)
elements = response_body['elements']
for element in elements:
if str(element['name']) == name:
self._verify_list_measurements_element(element, key, value)
measurement = element['measurements'][0]
self._verify_list_measurements_measurement(
measurement, metric, None, None)
return
time.sleep(constants.RETRY_WAIT_SECS)
if i == constants.MAX_RETRIES - 1:
error_msg = "Failed test_create_metric: " \
"timeout on waiting for metrics: at least " \
"one metric is needed. Current number of " \
"metrics = 0"
self.fail(error_msg)
@test.attr(type='gate')
@test.attr(type=['negative'])
def test_create_metric_with_no_timestamp(self):