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

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,35 +270,30 @@ 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,
end, end,
resource_id, resource_id,
statistics, statistics,
) )
conv_data = METRICS_CONF['metrics_units'][resource_type][name] try:
resource[name] = ck_utils.convert_unit( conv_data = METRICS_CONF['metrics_units'][resource_type]
qty, conv_data = conv_data.get(name)
conv_data.get('factor', 1), if conv_data:
conv_data.get('offset', 0), resource[name] = ck_utils.convert_unit(
) qty,
# NOTE(mc): deprecated except part kept for backward compatibility. conv_data.get('factor', 1),
except KeyError: conv_data.get('offset', 0),
LOG.warning('Error when trying to use yaml metrology conf.') )
LOG.warning('Fallback on the deprecated hardcoded dict method.') # NOTE(mc): deprecated except part kept for backward compatibility.
except KeyError:
for name, statistics in mappings: LOG.warning(
qty = self._get_resource_qty( 'Error when trying to use yaml metrology conf.\n'
name, 'Fallback on the deprecated hardcoded dict method.')
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')