from n2vc.exceptions import N2VCException, N2VCNotFound, K8sException
from osm_lcm.lcm_helm_conn import LCMHelmConn
+from osm_lcm.prometheus import parse_job
from copy import copy, deepcopy
from time import time
SUBOPERATION_STATUS_SKIP = -3
task_name_deploy_vca = "Deploying VCA"
- def __init__(self, msg, lcm_tasks, config, loop, prometheus=None):
+ def __init__(self, msg, lcm_tasks, config, loop):
"""
Init, Connect to database, filesystem storage, and messaging
:param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
"helm-v3": self.conn_helm_ee,
}
- self.prometheus = prometheus
-
# create RO client
self.RO = NgRoClient(self.loop, **self.ro_config)
# STEP 7 Configure metrics
if vca_type == "helm" or vca_type == "helm-v3":
- prometheus_jobs = await self.add_prometheus_metrics(
+ prometheus_jobs = await self.extract_prometheus_scrape_jobs(
ee_id=ee_id,
artifact_path=artifact_path,
ee_config_descriptor=ee_config_descriptor,
{db_update_entry + "prometheus_jobs": prometheus_jobs},
)
+ for job in prometheus_jobs:
+ self.db.set_one(
+ "prometheus_jobs",
+ {
+ "job_name": job["job_name"]
+ },
+ job,
+ upsert=True,
+ fail_on_empty=False
+ )
+
step = "instantiated at VCA"
self.logger.debug(logging_text + step)
"nsrs", db_nslcmop["nsInstanceId"], {db_update_entry: False}
)
- if vca_deployed.get("prometheus_jobs") and self.prometheus:
- await self.prometheus.update(remove_jobs=vca_deployed["prometheus_jobs"])
+ # Delete Prometheus Jobs if any
+ # This uses NSR_ID, so it will destroy any jobs under this index
+ self.db.del_list("prometheus_jobs", {"nsr_id": db_nslcmop["nsInstanceId"]})
if destroy_ee:
await self.vca_map[vca_type].delete_execution_environment(
db_vnfr, None, vdu_scaling_info["vdu-delete"], mark_delete=False
)
- async def add_prometheus_metrics(
- self, ee_id, artifact_path, ee_config_descriptor, vnfr_id, nsr_id, target_ip
+ async def extract_prometheus_scrape_jobs(
+ self,
+ ee_id,
+ artifact_path,
+ ee_config_descriptor,
+ vnfr_id,
+ nsr_id,
+ target_ip
):
- if not self.prometheus:
- return
# look if exist a file called 'prometheus*.j2' and
artifact_content = self.fs.dir_ls(artifact_path)
job_file = next(
"EXPORTER_POD_IP": host_name,
"EXPORTER_POD_PORT": host_port,
}
- job_list = self.prometheus.parse_job(job_data, variables)
+ job_list = parse_job(job_data, variables)
# ensure job_name is using the vnfr_id. Adding the metadata nsr_id
for job in job_list:
if (
):
job["job_name"] = vnfr_id + "_" + str(randint(1, 10000))
job["nsr_id"] = nsr_id
- job_dict = {jl["job_name"]: jl for jl in job_list}
- if await self.prometheus.update(job_dict):
- return list(job_dict.keys())
+ job["vnfr_id"] = vnfr_id
+ return job_list
def get_vca_cloud_and_credentials(self, vim_account_id: str) -> (str, str):
"""