Bug Fix - 2305: Automated scaling of Vnf is not happening through metrics collected... 28/14028/1 v14.0.2
authorRahul Kumar <rahul.k4@tataelxsi.co.in>
Thu, 9 Nov 2023 08:45:38 +0000 (08:45 +0000)
committerrahulkumarr <rahul.k4@tataelxsi.co.in>
Thu, 16 Nov 2023 13:50:09 +0000 (15:50 +0200)
Change-Id: I5cbb13919539d8727aba2519a50be47f618f24c2
Signed-off-by: Rahul Kumar <rahul.k4@tataelxsi.co.in>
osm_policy_module/alarming/service.py
osm_policy_module/autoscaling/service.py
osm_policy_module/common/mon_client.py
osm_policy_module/tests/integration/test_policy_agent.py

index fceffda..2ec78cc 100644 (file)
@@ -128,6 +128,8 @@ class AlarmingService:
                                     threshold=alarm_descriptor["value"],
                                     operation=alarm_descriptor["operation"],
                                     action=str(alarm_action),
+                                    vnfr=vnfr,
+                                    vnfd=vnfd,
                                 )
                                 alarm = VnfAlarmRepository.create(
                                     alarm_id=alarm_descriptor["alarm-id"],
index 5869785..bad3ea0 100644 (file)
@@ -195,6 +195,8 @@ class AutoscalingService:
                                                         "scale-in-relational-operation"
                                                     ],
                                                     action="scale_in",
+                                                    vnfr=vnfr,
+                                                    vnfd=vnfd,
                                                 )
                                             )
                                             alarm = ScalingAlarmRepository.create(
@@ -221,6 +223,8 @@ class AutoscalingService:
                                                 "scale-out-relational-operation"
                                             ],
                                             action="scale_out",
+                                            vnfr=vnfr,
+                                            vnfd=vnfd,
                                         )
                                         alarm = ScalingAlarmRepository.create(
                                             alarm_uuid=alarm_uuid,
index d5e8dfc..e9216aa 100644 (file)
@@ -50,6 +50,8 @@ class MonClient:
         operation: str,
         statistic: str = "AVERAGE",
         action: str = "",
+        vnfr: object = None,
+        vnfd: object = None,
     ):
         cor_id = random.randint(1, 10e7)
         msg = self._build_create_alarm_payload(
@@ -62,6 +64,8 @@ class MonClient:
             statistic,
             operation,
             action,
+            vnfr,
+            vnfd,
         )
         log.debug("Sending create_alarm_request %s", msg)
         producer = AIOKafkaProducer(
@@ -165,7 +169,26 @@ class MonClient:
         statistic: str,
         operation: str,
         action: str,
+        vnfr=None,
+        vnfd=None,
     ):
+        tags = {
+            "ns_id": ns_id,
+            "vdu_name": vdu_name,
+            "vnf_member_index": vnf_member_index,
+        }
+        if vnfr and vnfd:
+            # TODO: Change for multiple DF support
+            df = vnfd.get("df", [{}])[0]
+            if "exporters-endpoints" in df:
+                metric_port = df["exporters-endpoints"].get("metric-port", 9100)
+            if metric_name.startswith("kpi_"):
+                metric_name = metric_name.replace("kpi_", "")
+                metric_name.strip()
+                for vdu in vnfr["vdur"]:
+                    if vdu["name"] == vdu_name:
+                        vdu_ip = vdu["ip-address"]
+                        tags = {"instance": vdu_ip + ":" + str(metric_port)}
         alarm_create_request = {
             "correlation_id": cor_id,
             "alarm_name": "osm_alarm_{}_{}_{}_{}".format(
@@ -177,11 +200,7 @@ class MonClient:
             "threshold_value": threshold,
             "statistic": statistic,
             "action": action,
-            "tags": {
-                "ns_id": ns_id,
-                "vdu_name": vdu_name,
-                "vnf_member_index": vnf_member_index,
-            },
+            "tags": tags,
         }
         msg = {
             "alarm_create_request": alarm_create_request,
index e96c7e6..54b4e79 100644 (file)
@@ -525,6 +525,8 @@ class PolicyModuleAgentTest(unittest.TestCase):
             vdu_name="cirros_ns-1-cirros_vnfd-VM-1",
             vnf_member_index="1",
             action="scale_out",
+            vnfr=vnfr_record_mocks[0],
+            vnfd=vnfd_record_mock,
         )
         create_alarm.assert_not_called_with(
             metric_name="average_memory_utilization",
@@ -534,6 +536,8 @@ class PolicyModuleAgentTest(unittest.TestCase):
             vdu_name="cirros_ns-1-cirros_vnfd-VM-1",
             vnf_member_index="1",
             action="scale_out",
+            vnfr=vnfr_record_mocks[0],
+            vnfd=vnfd_record_mock,
         )
         create_alarm.assert_any_call(
             metric_name="average_memory_utilization",
@@ -543,6 +547,8 @@ class PolicyModuleAgentTest(unittest.TestCase):
             vdu_name="cirros_ns-2-cirros_vnfd-VM-1",
             vnf_member_index="2",
             action="scale_out",
+            vnfr=vnfr_record_mocks[1],
+            vnfd=vnfd_record_mock,
         )
         create_alarm.assert_not_called_with(
             metric_name="average_memory_utilization",
@@ -552,6 +558,8 @@ class PolicyModuleAgentTest(unittest.TestCase):
             vdu_name="cirros_ns-2-cirros_vnfd-VM-1",
             vnf_member_index="2",
             action="scale_out",
+            vnfr=vnfr_record_mocks[1],
+            vnfd=vnfd_record_mock,
         )
         scaling_record = ScalingGroup.get()
         self.assertEqual(scaling_record.name, "scale_cirros_vnfd-VM")
@@ -593,6 +601,8 @@ class PolicyModuleAgentTest(unittest.TestCase):
             threshold=20.0,
             operation="LT",
             action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}",
+            vnfr=vnfr_record_mocks[0],
+            vnfd=vnfd_record_mock,
         )
         create_alarm.assert_any_call(
             metric_name="average_memory_utilization",
@@ -602,6 +612,8 @@ class PolicyModuleAgentTest(unittest.TestCase):
             threshold=20.0,
             operation="LT",
             action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}",
+            vnfr=vnfr_record_mocks[1],
+            vnfd=vnfd_record_mock,
         )
 
     @patch.object(DbMongo, "db_connect", Mock())