diff --git a/ceilometer/polling/prom_exporter.py b/ceilometer/polling/prom_exporter.py index 99e80d22ca..89572e701d 100644 --- a/ceilometer/polling/prom_exporter.py +++ b/ceilometer/polling/prom_exporter.py @@ -75,48 +75,40 @@ def _gen_labels(sample): labels['keys'].append("type") labels['values'].append(ctype) - index = 3 if (sample.get('counter_name', '') != '' and sample.get('counter_name') is not None): labels['keys'].append("counter") labels['values'].append(sample['counter_name']) - index += 1 if (sample.get('project_id', '') != '' and sample.get('project_id') is not None): labels['keys'].append("project") labels['values'].append(sample['project_id']) - index += 1 if (sample.get('project_name', '') != '' and sample.get('project_name') is not None): labels['keys'].append("project_name") labels['values'].append(sample['project_name']) - index += 1 if (sample.get('user_id', '') != '' and sample.get('user_id') is not None): labels['keys'].append("user") labels['values'].append(sample['user_id']) - index += 1 if (sample.get('user_name', '') != '' and sample.get('user_name') is not None): labels['keys'].append("user_name") labels['values'].append(sample['user_name']) - index += 1 if (sample.get('counter_unit', '') != '' and sample.get('counter_unit') is not None): labels['keys'].append("unit") labels['values'].append(sample['counter_unit']) - index += 1 if (sample.get('resource_id', '') != '' and sample.get('resource_id') is not None): labels['keys'].append("resource") labels['values'].append(sample['resource_id']) - index += 1 if (sample.get('resource_metadata', '') != '' and sample.get('resource_metadata') is not None): @@ -125,17 +117,16 @@ def _gen_labels(sample): if (resource_metadata.get('host', '') != ''): labels['keys'].append("vm_instance") labels['values'].append(resource_metadata['host']) - index += 1 if (resource_metadata.get('display_name', '') != ''): labels['keys'].append("resource_name") labels['values'].append(resource_metadata['display_name']) if (resource_metadata.get('name', '') != ''): - labels['keys'].append("resource_name") - if (labels['values'][index] if index < len(labels['values']) - else '' != ''): - labels['values'].append(labels['values'][index] + ":" + + if labels['keys'][-1] != 'resource_name': + labels['keys'].append("resource_name") + if len(labels['keys']) == len(labels['values']): + labels['values'][-1] = (labels['values'][-1] + ":" + resource_metadata['name']) else: labels['values'].append(resource_metadata['name']) diff --git a/ceilometer/tests/unit/test_prom_exporter.py b/ceilometer/tests/unit/test_prom_exporter.py index bac9d6451b..e37d07be99 100644 --- a/ceilometer/tests/unit/test_prom_exporter.py +++ b/ceilometer/tests/unit/test_prom_exporter.py @@ -227,14 +227,14 @@ class TestPromExporter(base.BaseTestCase): slabels1['keys'] = ['disk', 'publisher', 'type', 'counter', 'project', 'user', 'unit', 'resource', 'vm_instance', 'resource_name', - 'resource_name', 'server_group'] + 'server_group'] slabels1['values'] = ['read', 'ceilometer', 'device', 'disk.device.read.latency', 'd965489b7f894cbda89cd2e25bfd85a0', '6e7d71415cd5401cbe103829c9c5dec2', 'ns', 'e536fff6-b20d-4aa5-ac2f-d15ac8b3af63-vda', - 'e0d297f5df3b62ec73c8d42b', 'myserver', + 'e0d297f5df3b62ec73c8d42b', 'myserver:instance-00000002', 'none'] label1 = prom_exporter._gen_labels(self.test_data[0]) self.assertDictEqual(label1, slabels1) @@ -243,14 +243,14 @@ class TestPromExporter(base.BaseTestCase): slabels2['keys'] = ['memory', 'publisher', 'type', 'counter', 'project', 'user', 'unit', 'resource', 'vm_instance', 'resource_name', - 'resource_name', 'server_group'] + 'server_group'] slabels2['values'] = ['e536fff6-b20d-4aa5-ac2f-d15ac8b3af63', 'ceilometer', 'usage', 'memory.usage', 'd965489b7f894cbda89cd2e25bfd85a0', '6e7d71415cd5401cbe103829c9c5dec2', 'MB', 'e536fff6-b20d-4aa5-ac2f-d15ac8b3af63', 'e0d297f5df3b62ec73c8d42b', - 'myserver', 'myserver:instance-00000002', 'none'] + 'myserver:instance-00000002', 'none'] label2 = prom_exporter._gen_labels(self.test_data[1]) self.assertDictEqual(label2, slabels2)