Add a "force_granularity" option to gnocchi collector's extra_args
This adds an option allowing to force the granularity to use when doing metric aggregations. If not specified or set to 0, the lowest available aggregation method will be used. Change-Id: I1ad36c3ac4125b4af285fddc3a4a649d5dc3b395
This commit is contained in:
parent
3c28781888
commit
3a47e50f09
@ -25,6 +25,7 @@ from oslo_log import log as logging
|
||||
from voluptuous import All
|
||||
from voluptuous import In
|
||||
from voluptuous import Length
|
||||
from voluptuous import Range
|
||||
from voluptuous import Required
|
||||
from voluptuous import Schema
|
||||
|
||||
@ -99,6 +100,7 @@ GNOCCHI_EXTRA_SCHEMA = {
|
||||
Required('resource_key', default='id'): All(str, Length(min=1)),
|
||||
Required('aggregation_method', default='max'):
|
||||
In(['max', 'mean', 'min', 'rate:max', 'rate:mean', 'rate:min']),
|
||||
Required('force_granularity', default=0): All(int, Range(min=0)),
|
||||
},
|
||||
}
|
||||
|
||||
@ -291,11 +293,11 @@ class GnocchiCollector(collector.BaseCollector):
|
||||
# Get gnocchi specific conf
|
||||
extra_args = self.conf[metric_name]['extra_args']
|
||||
|
||||
# get ressource type
|
||||
# get resource type
|
||||
resource_type = extra_args['resource_type']
|
||||
scope_key = CONF.collect.scope_key
|
||||
|
||||
# build search query using ressource type and project_id if provided
|
||||
# build search query using resource type and project_id if provided
|
||||
query_parameters = list()
|
||||
query_parameters.append(
|
||||
self.gen_filter(cop="=", type=resource_type))
|
||||
@ -313,14 +315,17 @@ class GnocchiCollector(collector.BaseCollector):
|
||||
# get groupby
|
||||
groupby = self.conf[metric_name]['groupby']
|
||||
|
||||
agg_kwargs = {
|
||||
'resource_type': resource_type,
|
||||
'start': start,
|
||||
'stop': end,
|
||||
'groupby': groupby,
|
||||
'search': self.extend_filter(*query_parameters),
|
||||
}
|
||||
if extra_args['force_granularity'] > 0:
|
||||
agg_kwargs['granularity'] = extra_args['force_granularity']
|
||||
try:
|
||||
return self._conn.aggregates.fetch(
|
||||
op,
|
||||
resource_type=resource_type,
|
||||
start=start,
|
||||
stop=end,
|
||||
groupby=groupby,
|
||||
search=self.extend_filter(*query_parameters))
|
||||
return self._conn.aggregates.fetch(op, **agg_kwargs)
|
||||
except (gexceptions.MetricNotFound, gexceptions.BadRequest) as e:
|
||||
# FIXME(peschk_l): gnocchiclient seems to be raising a BadRequest
|
||||
# when it should be raising MetricNotFound
|
||||
|
@ -70,6 +70,7 @@ class MetricConfigValidationTest(tests.TestCase):
|
||||
expected_output['metric_one']['groupby'] += ['project_id', 'id']
|
||||
expected_output['metric_one']['extra_args'] = {
|
||||
'aggregation_method': 'max',
|
||||
'force_granularity': 0,
|
||||
'resource_type': 'res',
|
||||
'resource_key': 'id',
|
||||
}
|
||||
@ -79,6 +80,19 @@ class MetricConfigValidationTest(tests.TestCase):
|
||||
expected_output,
|
||||
)
|
||||
|
||||
def test_gnocchi_minimal_config_negative_forced_aggregation(self):
|
||||
data = copy.deepcopy(self.base_data)
|
||||
data['metrics']['metric_one']['extra_args'] = {
|
||||
'resource_type': 'res',
|
||||
'force_aggregation': -42,
|
||||
}
|
||||
|
||||
self.assertRaises(
|
||||
verror.MultipleInvalid,
|
||||
collector.gnocchi.GnocchiCollector.check_configuration,
|
||||
data,
|
||||
)
|
||||
|
||||
def test_monasca_minimal_config_no_extra_args(self):
|
||||
data = copy.deepcopy(self.base_data)
|
||||
expected_output = copy.deepcopy(self.base_output)
|
||||
|
@ -255,6 +255,10 @@ Gnocchi
|
||||
when retrieving measures from gnocchi. Must be one of ``min``, ``max``,
|
||||
``mean``.
|
||||
|
||||
* ``force_granularity``: Defaults to ``0``. If > 0, this granularity will be
|
||||
used for metric aggregations. Else, the lowest available granularity will be
|
||||
used (meaning the granularity covering the longest period).
|
||||
|
||||
Monasca
|
||||
~~~~~~~
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
A ``force_granularity`` option has been added to the gnocchi collector's
|
||||
``extra_args``. It allows to force a granularity to use when doing metric
|
||||
aggregations. If not specified or set to 0, the lowest available
|
||||
granularity will be used.
|
Loading…
x
Reference in New Issue
Block a user