Feature 11016: Service KPI Metric Based Scaling of VNF using exporter endpoint in... 67/14367/7
authorRahul Kumar <rahul.k4@tataelxsi.co.in>
Thu, 9 May 2024 10:04:01 +0000 (15:34 +0530)
committercubag <gcuba@whitestack.com>
Mon, 15 Jul 2024 06:42:38 +0000 (08:42 +0200)
Change-Id: Ia70cca4768651667c9de929e9dcdd97c8767e4ab
Signed-off-by: Rahul Kumar <rahul.k4@tataelxsi.co.in>
osm_lcm/data_utils/lcm_config.py
osm_lcm/ns.py

index 4384021..1c8ef49 100644 (file)
@@ -201,6 +201,10 @@ class TsdbConfig(OsmConfigman):
         self.logger_name = "lcm.prometheus"
 
 
+class MonitoringConfig(OsmConfigman):
+    old_sa: bool = True
+
+
 # Main configuration Template
 
 
@@ -213,6 +217,7 @@ class LcmCfg(OsmConfigman):
     storage: StorageConfig = StorageConfig()
     message: MessageConfig = MessageConfig()
     tsdb: TsdbConfig = TsdbConfig()
+    servicekpi: MonitoringConfig = MonitoringConfig()
 
     def transform(self):
         for attribute in dir(self):
index bad1b1f..3225f3e 100644 (file)
@@ -157,6 +157,7 @@ class NsLcm(LcmBase):
         self.timeout = config.timeout
         self.ro_config = config.RO
         self.vca_config = config.VCA
+        self.service_kpi = config.servicekpi
 
         # create N2VC connector
         self.n2vc = N2VCJujuConnector(
@@ -2302,7 +2303,8 @@ class NsLcm(LcmBase):
                         for vdur in monitored_vdurs:
                             vdu_id = vdur["vdu-id-ref"]
                             metric_name = vnf_monitoring_param.get("performance-metric")
-                            metric_name = f"osm_{metric_name}"
+                            if "exporters-endpoints" not in df:
+                                metric_name = f"osm_{metric_name}"
                             vnf_member_index = vnfr["member-vnf-index-ref"]
                             scalein_threshold = scaling_criteria.get(
                                 "scale-in-threshold"
@@ -2336,6 +2338,22 @@ class NsLcm(LcmBase):
                                 )
                                 metric_selector = f'{metric_name}{{ns_id="{nsr_id}", vnf_member_index="{vnf_member_index}", vdu_id="{vdu_id}"}}'
                                 expression = f"(count ({metric_selector}) > {instances_min_number}) and (avg({metric_selector}) {rel_operator} {scalein_threshold})"
+                                if (
+                                    "exporters-endpoints" in df
+                                    and metric_name.startswith("kpi_")
+                                ):
+                                    new_metric_name = (
+                                        f'osm_{metric_name.replace("kpi_", "").strip()}'
+                                    )
+                                    metric_port = df["exporters-endpoints"].get(
+                                        "metric-port", 9100
+                                    )
+                                    vdu_ip = vdur["ip-address"]
+                                    ip_port = str(vdu_ip) + ":" + str(metric_port)
+                                    metric_selector = (
+                                        f'{new_metric_name}{{instance="{ip_port}"}}'
+                                    )
+                                    expression = f"({metric_selector} {rel_operator} {scalein_threshold})"
                                 labels = {
                                     "ns_id": nsr_id,
                                     "vnf_member_index": vnf_member_index,
@@ -2379,6 +2397,22 @@ class NsLcm(LcmBase):
                                 )
                                 metric_selector = f'{metric_name}{{ns_id="{nsr_id}", vnf_member_index="{vnf_member_index}", vdu_id="{vdu_id}"}}'
                                 expression = f"(count ({metric_selector}) < {instances_max_number}) and (avg({metric_selector}) {rel_operator} {scaleout_threshold})"
+                                if (
+                                    "exporters-endpoints" in df
+                                    and metric_name.startswith("kpi_")
+                                ):
+                                    new_metric_name = (
+                                        f'osm_{metric_name.replace("kpi_", "").strip()}'
+                                    )
+                                    metric_port = df["exporters-endpoints"].get(
+                                        "metric-port", 9100
+                                    )
+                                    vdu_ip = vdur["ip-address"]
+                                    ip_port = str(vdu_ip) + ":" + str(metric_port)
+                                    metric_selector = (
+                                        f'{new_metric_name}{{instance="{ip_port}"}}'
+                                    )
+                                    expression = f"({metric_selector} {rel_operator} {scaleout_threshold})"
                                 labels = {
                                     "ns_id": nsr_id,
                                     "vnf_member_index": vnf_member_index,
@@ -4707,6 +4741,8 @@ class NsLcm(LcmBase):
                 operation_state=nslcmop_operation_state,
                 other_update=db_nslcmop_update,
             )
+            if nslcmop_operation_state == "COMPLETED":
+                self.db.del_list("prometheus_jobs", {"nsr_id": nsr_id})
             if ns_state == "NOT_INSTANTIATED":
                 try:
                     self.db.set_list(
@@ -7318,7 +7354,7 @@ class NsLcm(LcmBase):
                         scale_process = None
             # POST-SCALE END
             # Check if each vnf has exporter for metric collection if so update prometheus job records
-            if scaling_type == "SCALE_OUT":
+            if scaling_type == "SCALE_OUT" and bool(self.service_kpi.old_sa):
                 if "exporters-endpoints" in db_vnfd.get("df")[0]:
                     vnfr_id = db_vnfr["id"]
                     db_vnfr = self.db.get_one("vnfrs", {"_id": vnfr_id})