Skip to content
Snippets Groups Projects
Commit 05978993 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

minor changes in code.

- refine Kpi_DB.py methods.
- improve description of messages.
- imporve the text description.
parent 8c5c1286
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!261(CTTC) New Analytics Component
...@@ -70,8 +70,7 @@ class KpiDB: ...@@ -70,8 +70,7 @@ class KpiDB:
session.rollback() session.rollback()
if "psycopg2.errors.UniqueViolation" in str(e): if "psycopg2.errors.UniqueViolation" in str(e):
LOGGER.error(f"Unique key voilation: {row.__class__.__name__} table. {str(e)}") LOGGER.error(f"Unique key voilation: {row.__class__.__name__} table. {str(e)}")
raise AlreadyExistsException(row.__class__.__name__, row, raise AlreadyExistsException(row.__class__.__name__, row, extra_details=["Unique key voilation: {:}".format(e)] )
extra_details=["Unique key voilation: {:}".format(e)] )
else: else:
LOGGER.error(f"Failed to insert new row into {row.__class__.__name__} table. {str(e)}") LOGGER.error(f"Failed to insert new row into {row.__class__.__name__} table. {str(e)}")
raise OperationFailedException ("Deletion by column id", extra_details=["unable to delete row {:}".format(e)]) raise OperationFailedException ("Deletion by column id", extra_details=["unable to delete row {:}".format(e)])
...@@ -90,7 +89,6 @@ class KpiDB: ...@@ -90,7 +89,6 @@ class KpiDB:
print("{:} ID not found, No matching row: {:}".format(model.__name__, id_to_search)) print("{:} ID not found, No matching row: {:}".format(model.__name__, id_to_search))
return None return None
except Exception as e: except Exception as e:
session.rollback()
LOGGER.debug(f"Failed to retrieve {model.__name__} ID. {str(e)}") LOGGER.debug(f"Failed to retrieve {model.__name__} ID. {str(e)}")
raise OperationFailedException ("search by column id", extra_details=["unable to search row {:}".format(e)]) raise OperationFailedException ("search by column id", extra_details=["unable to search row {:}".format(e)])
finally: finally:
......
...@@ -18,8 +18,9 @@ from common.proto.kpi_value_api_pb2 import KpiValue, KpiValueList ...@@ -18,8 +18,9 @@ from common.proto.kpi_value_api_pb2 import KpiValue, KpiValueList
def create_kpi_value_list(): def create_kpi_value_list():
_create_kpi_value_list = KpiValueList() _create_kpi_value_list = KpiValueList()
# To run this experiment sucessfully, already existing UUID in KPI DB in necessary. # To run this experiment sucessfully, add an existing UUID of a KPI Descriptor from the KPI DB.
# because the UUID is used to get the descriptor form KPI DB. # This UUID is used to get the descriptor form the KPI DB. If the Kpi ID does not exists,
# some part of the code won't execute.
EXISTING_KPI_IDs = ["725ce3ad-ac67-4373-bd35-8cd9d6a86e09", EXISTING_KPI_IDs = ["725ce3ad-ac67-4373-bd35-8cd9d6a86e09",
str(uuid.uuid4()), str(uuid.uuid4()),
str(uuid.uuid4())] str(uuid.uuid4())]
......
...@@ -63,8 +63,8 @@ class MetricWriterToPrometheus: ...@@ -63,8 +63,8 @@ class MetricWriterToPrometheus:
def create_and_expose_cooked_kpi(self, kpi_descriptor: KpiDescriptor, kpi_value: KpiValue): def create_and_expose_cooked_kpi(self, kpi_descriptor: KpiDescriptor, kpi_value: KpiValue):
# merge both gRPC messages into single varible. # merge both gRPC messages into single varible.
cooked_kpi = self.merge_kpi_descriptor_and_kpi_value(kpi_descriptor, kpi_value) cooked_kpi = self.merge_kpi_descriptor_and_kpi_value(kpi_descriptor, kpi_value)
tags_to_exclude = {'kpi_description', 'kpi_sample_type', 'kpi_value'} # extracted values will be used as metric tag tags_to_exclude = {'kpi_description', 'kpi_sample_type', 'kpi_value'}
metric_tags = [tag for tag in cooked_kpi.keys() if tag not in tags_to_exclude] metric_tags = [tag for tag in cooked_kpi.keys() if tag not in tags_to_exclude] # These values will be used as metric tags
metric_name = cooked_kpi['kpi_sample_type'] metric_name = cooked_kpi['kpi_sample_type']
try: try:
if metric_name not in PROM_METRICS: # Only register the metric, when it doesn't exists if metric_name not in PROM_METRICS: # Only register the metric, when it doesn't exists
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment