Fix empty metadata exception in Prometheus collector

Metadata defined in metrics.yml may be non-existent in data['metric']
from Prometheus results. Deal with the exception similarly to the
Gnocchi collector.

Change-Id: I02ee50793f3c46050250ca1c4094dd4ef0736ca6
Signed-off-by: Ning Yao <yaoning@unitedstack.com>
Story: 2008123
Task: 40845
This commit is contained in:
Ning Yao
2020-02-29 01:56:07 +08:00
committed by Pierre Riteau
parent cbcdacac61
commit 89dfb91dd4
2 changed files with 6 additions and 1 deletions

View File

@@ -130,7 +130,7 @@ class PrometheusCollector(collector.BaseCollector):
"""
metadata = {}
for meta in self.conf[metric_name]['metadata']:
metadata[meta] = data['metric'][meta]
metadata[meta] = data['metric'].get(meta, '')
groupby = {scope_key: scope_id}
for meta in self.conf[metric_name]['groupby']:

View File

@@ -0,0 +1,5 @@
---
issues:
- |
Fixes exceptions in Prometheus collector when metadata defined in
``metrics.yml`` is not present on metrics retrieved from Prometheus.