From 594b94c7d63844dca8d74cebd3a34c43b48c3db2 Mon Sep 17 00:00:00 2001 From: Witold Bedyk Date: Tue, 5 Dec 2017 15:24:51 +0100 Subject: [PATCH] Allow parentheses '()' in dimensions Update tempest tests to allow parentheses in dimensions. Update documentation. Change-Id: Idceed9a6cf2deff2c60bc865dc6a8fb2d0640412 Story: 2001385 Task: 5960 --- docs/monasca-api-spec.md | 7 ++++++- monasca_tempest_tests/tests/api/constants.py | 3 ++- monasca_tempest_tests/tests/api/test_metrics.py | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/monasca-api-spec.md b/docs/monasca-api-spec.md index 4c492f0f3..cb467b5d2 100644 --- a/docs/monasca-api-spec.md +++ b/docs/monasca-api-spec.md @@ -386,7 +386,12 @@ A metric is uniquely identified by a name and set of dimensions. Defines the name of a metric. A name is of type string(255). The name may include any characters except the following: `> < = { } ( ) , ' " \ ; &`. Note that JSON does allow control characters (such as `\n`), however these should not be used in metric names. ### Dimensions -A dictionary of (key, value) pairs. The key and value are of type string(255). Dimension keys may not begin with '_' (underscore). The dimension key and value strings may include any characters except the following: `> < = { } ( ) , ' " \ ; &`. Note that JSON does allow control characters (such as `\n`), however these should not be used in dimension keys or values. Dimension keys and values must not be empty. +A dictionary of (key, value) pairs. The key and value are of type string(255). +Dimension keys may not begin with '_' (underscore). The dimension key and value +strings may include any characters except the following: +`> < = { } , ' " \ ; &`. Note that JSON does allow control characters (such as +`\n`), however these should not be used in dimension keys or values. Dimension +keys and values must not be empty. ### Text Representation In this document, metrics will be represented in the form `name{name=value,name=value}` where name is the metric name and the name=value pairs in the curly braces are the dimensions. For example, `cpu.idle_perc{service=monitoring,hostname=mini-mon}` represents a metric with the name "cpu.idle_perc" and the dimensions "service=monitoring" and "hostname=mini-mon". diff --git a/monasca_tempest_tests/tests/api/constants.py b/monasca_tempest_tests/tests/api/constants.py index ee41f2f76..2ce3f458a 100644 --- a/monasca_tempest_tests/tests/api/constants.py +++ b/monasca_tempest_tests/tests/api/constants.py @@ -21,7 +21,8 @@ ALARM_DEFINITION_CREATION_WAIT = 1 MAX_METRIC_NAME_LENGTH = 255 MAX_DIMENSION_KEY_LENGTH = 255 MAX_DIMENSION_VALUE_LENGTH = 255 -INVALID_CHARS = "<>={}(),\"\;&" +INVALID_DIMENSION_CHARS = "<>={},\"\;&" +INVALID_NAME_CHARS = INVALID_DIMENSION_CHARS + "()" MAX_ALARM_DEFINITION_NAME_LENGTH = 255 MAX_ALARM_DEFINITION_DESCRIPTION_LENGTH = 255 diff --git a/monasca_tempest_tests/tests/api/test_metrics.py b/monasca_tempest_tests/tests/api/test_metrics.py index d611e5093..fd9f63b8b 100644 --- a/monasca_tempest_tests/tests/api/test_metrics.py +++ b/monasca_tempest_tests/tests/api/test_metrics.py @@ -318,7 +318,7 @@ class TestMetrics(base.BaseMonascaTest): @decorators.attr(type='gate') @decorators.attr(type=['negative']) def test_create_metric_with_invalid_chars_in_name(self): - for invalid_char in constants.INVALID_CHARS: + for invalid_char in constants.INVALID_NAME_CHARS: metric = helpers.create_metric(invalid_char) self.assertRaises(exceptions.UnprocessableEntity, self.monasca_client.create_metrics, @@ -327,12 +327,12 @@ class TestMetrics(base.BaseMonascaTest): @decorators.attr(type='gate') @decorators.attr(type=['negative']) def test_create_metric_with_invalid_chars_in_dimensions(self): - for invalid_char in constants.INVALID_CHARS: + for invalid_char in constants.INVALID_DIMENSION_CHARS: metric = helpers.create_metric('name-1', {'key-1': invalid_char}) self.assertRaises(exceptions.UnprocessableEntity, self.monasca_client.create_metrics, metric) - for invalid_char in constants.INVALID_CHARS: + for invalid_char in constants.INVALID_DIMENSION_CHARS: metric = helpers.create_metric('name-1', {invalid_char: 'value-1'}) self.assertRaises(exceptions.UnprocessableEntity, self.monasca_client.create_metrics,