Merge "Fix YAML configuration usage in monasca collector"

This commit is contained in:
Zuul 2018-02-09 17:34:09 +00:00 committed by Gerrit Code Review
commit 9afc3472ea
1 changed files with 38 additions and 40 deletions

View File

@ -65,21 +65,21 @@ class MonascaCollector(collector.BaseCollector):
} }
metrics_mappings = { metrics_mappings = {
'compute': [ 'compute': [
('cpu', 'max'), {'cpu': 'max'},
('vpcus', 'max'), {'vpcus': 'max'},
('memory', 'max')], {'memory': 'max'}],
'image': [ 'image': [
('image.size', 'max'), {'image.size': 'max'},
('image.download', 'max'), {'image.download': 'max'},
('image.serve', 'max')], {'image.serve': 'max'}],
'volume': [ 'volume': [
('volume.size', 'max')], {'volume.size': 'max'}],
'network.bw.in': [ 'network.bw.in': [
('network.incoming.bytes', 'max')], {'network.incoming.bytes': 'max'}],
'network.bw.out': [ 'network.bw.out': [
('network.outgoing.bytes', 'max')], {'network.outgoing.bytes': 'max'}],
'network.floating': [ 'network.floating': [
('ip.floating', 'max')], {'ip.floating': 'max'}],
} }
# (qty, unit). qty must be either a metric name, an integer # (qty, unit). qty must be either a metric name, an integer
# or a decimal.Decimal object # or a decimal.Decimal object
@ -156,7 +156,9 @@ class MonascaCollector(collector.BaseCollector):
info['metadata'] = metadata.keys() info['metadata'] = metadata.keys()
try: try:
for metric, statistics in METRICS_CONF['services_metrics']: service_metrics = METRICS_CONF['services_metrics'][resource_type]
for service_metric in service_metrics:
metric, statistics = list(service_metric.items())[0]
info['metadata'].append(metric) info['metadata'].append(metric)
# NOTE(mc): deprecated second try kept for backward compatibility. # NOTE(mc): deprecated second try kept for backward compatibility.
except KeyError: except KeyError:
@ -268,8 +270,8 @@ class MonascaCollector(collector.BaseCollector):
def _expand_metrics(self, resource, resource_id, def _expand_metrics(self, resource, resource_id,
mappings, start, end, resource_type): mappings, start, end, resource_type):
try: for mapping in mappings:
for name, statistics in mappings.items(): name, statistics = list(mapping.items())[0]
qty = self._get_resource_qty( qty = self._get_resource_qty(
name, name,
start, start,
@ -278,7 +280,10 @@ class MonascaCollector(collector.BaseCollector):
statistics, statistics,
) )
conv_data = METRICS_CONF['metrics_units'][resource_type][name] try:
conv_data = METRICS_CONF['metrics_units'][resource_type]
conv_data = conv_data.get(name)
if conv_data:
resource[name] = ck_utils.convert_unit( resource[name] = ck_utils.convert_unit(
qty, qty,
conv_data.get('factor', 1), conv_data.get('factor', 1),
@ -286,17 +291,9 @@ class MonascaCollector(collector.BaseCollector):
) )
# NOTE(mc): deprecated except part kept for backward compatibility. # NOTE(mc): deprecated except part kept for backward compatibility.
except KeyError: except KeyError:
LOG.warning('Error when trying to use yaml metrology conf.') LOG.warning(
LOG.warning('Fallback on the deprecated hardcoded dict method.') 'Error when trying to use yaml metrology conf.\n'
'Fallback on the deprecated hardcoded dict method.')
for name, statistics in mappings:
qty = self._get_resource_qty(
name,
start,
end,
resource_id,
statistics,
)
names = ['network.outgoing.bytes', 'network.incoming.bytes'] names = ['network.outgoing.bytes', 'network.incoming.bytes']
if name in names: if name in names:
@ -348,7 +345,8 @@ class MonascaCollector(collector.BaseCollector):
resource_qty = qty resource_qty = qty
if not (isinstance(qty, int) or isinstance(qty, decimal.Decimal)): if not (isinstance(qty, int) or isinstance(qty, decimal.Decimal)):
try: try:
resource_qty = METRICS_CONF['services_objects'] resource_qty \
= METRICS_CONF['services_objects'][resource_type]
# NOTE(mc): deprecated except part kept for backward compat. # NOTE(mc): deprecated except part kept for backward compat.
except KeyError: except KeyError:
LOG.warning('Error when trying to use yaml metrology conf') LOG.warning('Error when trying to use yaml metrology conf')