Refactors Prometheus exporter to group metrics correctly by name

Metric names were appearing duplicated in the exporter which generated issues
integrating with external tools such as Metricbeat and Kibana.

Signed-off-by: Benjamin Diaz <bdiaz@whitestack.com>
diff --git a/Jenkinsfile b/Jenkinsfile
index 6afef69..635a5e6 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -5,7 +5,7 @@
         string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC'),
         string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION'),
         string(defaultValue: 'https://osm.etsi.org/gerrit', description: '', name: 'PROJECT_URL_PREFIX'),
-        booleanParam(defaultValue: false, description: '', name: 'TEST_INSTALL'),
+        booleanParam(defaultValue: true, description: '', name: 'TEST_INSTALL'),
         string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER'),
     ])
 ])
diff --git a/osm_mon/collector/backends/prometheus.py b/osm_mon/collector/backends/prometheus.py
index 1bc3ff4..31f3122 100644
--- a/osm_mon/collector/backends/prometheus.py
+++ b/osm_mon/collector/backends/prometheus.py
@@ -43,16 +43,17 @@
     def handle(self, metrics: List[Metric]):
         log.debug('handle')
         log.debug('metrics: %s', metrics)
-        prometheus_metrics = []
+        prometheus_metrics = {}
         for metric in metrics:
-            prometheus_metric = GaugeMetricFamily(
-                OSM_METRIC_PREFIX + metric.name,
-                'OSM metric',
-                labels=['ns_id', 'vnf_member_index', 'vdu_name']
-            )
-            prometheus_metric.add_metric([metric.nsr_id, metric.vnf_member_index, metric.vdur_name], metric.value)
-            prometheus_metrics.append(prometheus_metric)
-        self.custom_collector.metrics = prometheus_metrics
+            if metric.name not in prometheus_metrics:
+                prometheus_metrics[metric.name] = GaugeMetricFamily(
+                    OSM_METRIC_PREFIX + metric.name,
+                    'OSM metric',
+                    labels=['ns_id', 'vnf_member_index', 'vdu_name']
+                )
+            prometheus_metrics[metric.name].add_metric([metric.nsr_id, metric.vnf_member_index, metric.vdur_name],
+                                                       metric.value)
+        self.custom_collector.metrics = prometheus_metrics.values()
 
     def _start_exporter(self, port):
         log.debug('_start_exporter')