From: atici Date: Wed, 8 Sep 2021 09:18:42 +0000 (+0000) Subject: Bug 1651 fix X-Git-Tag: v12.0.0rc1~10 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FMON.git;a=commitdiff_plain;h=881f2ce1a5876782cbd939764a5bffcad28908f8 Bug 1651 fix Code revision is done after review. This fix is required to fix VCA metric collection for SOL006 compatible descriptors. Related bug: https://osm.etsi.org/bugzilla/show_bug.cgi?id=1651 Change-Id: I4de6e9ae368ba77a2e1e591eb220ea98ec7c9788 Signed-off-by: atici --- diff --git a/osm_mon/collector/vnf_collectors/juju.py b/osm_mon/collector/vnf_collectors/juju.py index 7e639b5..36aabab 100644 --- a/osm_mon/collector/vnf_collectors/juju.py +++ b/osm_mon/collector/vnf_collectors/juju.py @@ -78,77 +78,53 @@ class VCACollector(BaseCollector): tags["project_id"] = "" metrics = [] - for vdur in vnfr["vdur"]: - # This avoids errors when vdur records have not been completely filled - if "name" not in vdur: - continue - vdu = next(filter(lambda vdu: vdu["id"] == vdur["vdu-id-ref"], vnfd["vdu"])) - if "vdu-configuration" in vdu and "metrics" in vdu["vdu-configuration"]: - try: - vca_deployment_info = self.get_vca_deployment_info( - nsr_id, - vnf_member_index, - vdur["vdu-id-ref"], - vdur["count-index"], - ) - except VcaDeploymentInfoNotFound as e: - log.warning(repr(e)) - continue - measures = self.loop.run_until_complete( - self.n2vc.get_metrics( - vca_deployment_info["model"], - vca_deployment_info["application"], - vca_id=vnfr.get("vca-id"), - ) - ) - log.debug("Measures: %s", measures) - for measure_list in measures.values(): - for measure in measure_list: - log.debug("Measure: %s", measure) - metric = VnfMetric( + vdur = None + lcm_ops = vnfd["df"][0].get("lcm-operations-configuration") + if not lcm_ops: + return metrics + ops_config = lcm_ops.get("operate-vnf-op-config") + if not ops_config: + return metrics + day12ops = ops_config.get("day1-2", []) + for day12op in day12ops: + if day12op and "metrics" in day12op: + vdur = next(filter(lambda vdur: vdur["vdu-id-ref"] == day12op["id"], vnfr["vdur"])) + + # This avoids errors when vdur records have not been completely filled + if vdur and "name" in vdur: + try: + vca_deployment_info = self.get_vca_deployment_info( nsr_id, vnf_member_index, - vdur["name"], - measure["key"], - float(measure["value"]), - tags, + vdur["vdu-id-ref"], + vdur["count-index"], ) - metrics.append(metric) - if "vnf-configuration" in vnfd and "metrics" in vnfd["vnf-configuration"]: - try: - vca_deployment_info = self.get_vca_deployment_info( - nsr_id, vnf_member_index - ) - except VcaDeploymentInfoNotFound as e: - log.warning(repr(e)) - return metrics - measures = self.loop.run_until_complete( - self.n2vc.get_metrics( - vca_deployment_info["model"], - vca_deployment_info["application"], - vca_id=vnfr.get("vca-id"), - ) - ) - # Search for Mgmt VDU name, needed to query Prometheus based on alarm tags - # TODO: check a better way to look for Mgmt VDU - for vdur in vnfr["vdur"]: - for interface in vdur["interfaces"]: - if "mgmt-vnf" in interface: - vdu_name = vdur["name"] - break - log.debug("Measures: %s", measures) - for measure_list in measures.values(): - for measure in measure_list: - log.debug("Measure: %s", measure) - metric = VnfMetric( - nsr_id, - vnf_member_index, - vdu_name, - measure["key"], - float(measure["value"]), - tags, - ) - metrics.append(metric) + except VcaDeploymentInfoNotFound as e: + log.warning(repr(e)) + continue + # This avoids errors before application and model is not ready till they are occured + if vca_deployment_info.get("model") and vca_deployment_info.get("application"): + measures = self.loop.run_until_complete( + self.n2vc.get_metrics( + vca_deployment_info["model"], + vca_deployment_info["application"], + vca_id=vnfr.get("vca-id"), + ) + ) + log.debug("Measures: %s", measures) + for measure_list in measures.values(): + for measure in measure_list: + log.debug("Measure: %s", measure) + metric = VnfMetric( + nsr_id, + vnf_member_index, + vdur["name"], + measure["key"], + float(measure["value"]), + tags, + ) + metrics.append(metric) + return metrics def get_vca_deployment_info(