From 56b7a56f6fac5a92a0cc35a02e67182c2d7bdf42 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Wed, 26 Mar 2025 17:04:13 +0100 Subject: [PATCH] Add VIM configuration option to model the label to identify VM ids in Prometheus backend Change-Id: Iffcb7050f833c9ac2b227528dce27bebd02b36bc Signed-off-by: garciadeblas --- src/osm_ngsa/osm_mon/vim_connectors/openstack.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/osm_ngsa/osm_mon/vim_connectors/openstack.py b/src/osm_ngsa/osm_mon/vim_connectors/openstack.py index 2aea5e8..249e2b6 100644 --- a/src/osm_ngsa/osm_mon/vim_connectors/openstack.py +++ b/src/osm_ngsa/osm_mon/vim_connectors/openstack.py @@ -291,6 +291,9 @@ class PrometheusTSDBBackend(OpenstackBackend): def __init__(self, vim_account: dict): self.map = self._build_map(vim_account) self.cred = vim_account["prometheus-config"].get("prometheus-cred") + self.resource_id_label = vim_account["prometheus-config"].get( + "resource-id-label", "resource_id" + ) self.client = self._build_prometheus_client( vim_account["prometheus-config"]["prometheus-url"] ) @@ -325,8 +328,10 @@ class PrometheusTSDBBackend(OpenstackBackend): if resource_id: log.info(f"Getting the metric for the resource_id: {resource_id}") metric = next( - # TODO: The label to identify the metric should be standard or read from VIM config - filter(lambda x: resource_id in x["metric"]["resource_id"], metrics) + filter( + lambda x: resource_id in x["metric"][self.resource_id_label], + metrics, + ) ) log.debug(f"Resource metric {metric_name} for {resource_id}: {metric}") return metric -- 2.25.1