Add support for empty or missing "extra_args" in metrics config file

This allow to have an empty or missing "extra_args" key in the monasca
and prometheus collectors, which allows lighter configuration.

Change-Id: I4d384ed980b82f530f9a7ddca32955c5d6be932e
This commit is contained in:
Luka Peschke 2019-08-19 16:38:18 +02:00
parent 2b0735d776
commit 262de1d755
3 changed files with 34 additions and 12 deletions

View File

@ -57,7 +57,7 @@ CONF.register_opts(collector_monasca_opts, COLLECTOR_MONASCA_OPTS)
METRICS_CONF = ck_utils.load_conf(CONF.collect.metrics_conf)
MONASCA_EXTRA_SCHEMA = {
Required('extra_args'): {
Required('extra_args', default={}): {
# Key corresponding to the resource id in a metric's dimensions
# Allows to adapt the resource identifier. Should not need to be
# modified in a standard OpenStack installation

View File

@ -62,7 +62,7 @@ cfg.CONF.register_opts(collector_prometheus_opts, PROMETHEUS_COLLECTOR_OPTS)
CONF = cfg.CONF
PROMETHEUS_EXTRA_SCHEMA = {
Required('extra_args'): {
Required('extra_args', default={}): {
Required('aggregation_method', default='max'):
In([
'avg', 'count', 'max',

View File

@ -81,11 +81,17 @@ class MetricConfigValidationTest(tests.TestCase):
def test_monasca_minimal_config_no_extra_args(self):
data = copy.deepcopy(self.base_data)
self.assertRaises(
verror.MultipleInvalid,
collector.monasca.MonascaCollector.check_configuration,
data,
expected_output = copy.deepcopy(self.base_output)
expected_output['metric_one']['groupby'].extend(
['project_id', 'resource_id'])
expected_output['metric_one']['extra_args'] = {
'resource_key': 'resource_id',
'aggregation_method': 'max',
'forced_project_id': ''
}
self.assertEqual(
collector.monasca.MonascaCollector.check_configuration(data),
expected_output,
)
def test_monasca_minimal_config_minimal_extra_args(self):
@ -107,12 +113,28 @@ class MetricConfigValidationTest(tests.TestCase):
def test_prometheus_minimal_config_empty_extra_args(self):
data = copy.deepcopy(self.base_data)
data['extra_args'] = {}
data['metrics']['metric_one']['extra_args'] = {}
self.assertRaises(
verror.MultipleInvalid,
collector.prometheus.PrometheusCollector.check_configuration,
data,
expected_output = copy.deepcopy(self.base_output)
expected_output['metric_one']['groupby'].append('project_id')
expected_output['metric_one']['extra_args'] = {
'aggregation_method': 'max',
}
self.assertEqual(
collector.prometheus.PrometheusCollector.check_configuration(data),
expected_output,
)
def test_prometheus_minimal_config_no_extra_args(self):
data = copy.deepcopy(self.base_data)
expected_output = copy.deepcopy(self.base_output)
expected_output['metric_one']['groupby'].append('project_id')
expected_output['metric_one']['extra_args'] = {
'aggregation_method': 'max',
}
self.assertEqual(
collector.prometheus.PrometheusCollector.check_configuration(data),
expected_output,
)
def test_prometheus_minimal_config_minimal_extra_args(self):