Commit d8687c1c 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 aca1fe1b
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -70,8 +70,7 @@ class KpiDB:
            session.rollback()
            if "psycopg2.errors.UniqueViolation" in str(e):
                LOGGER.error(f"Unique key voilation: {row.__class__.__name__} table. {str(e)}")
                raise AlreadyExistsException(row.__class__.__name__, row,
                                             extra_details=["Unique key voilation: {:}".format(e)] )
                raise AlreadyExistsException(row.__class__.__name__, row, extra_details=["Unique key voilation: {:}".format(e)] )
            else:
                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)])
@@ -90,7 +89,6 @@ class KpiDB:
                print("{:} ID not found, No matching row: {:}".format(model.__name__, id_to_search))
                return None
        except Exception as e:
            session.rollback()
            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)])
        finally:
+3 −2
Original line number Diff line number Diff line
@@ -18,8 +18,9 @@ from common.proto.kpi_value_api_pb2 import KpiValue, KpiValueList

def create_kpi_value_list():
    _create_kpi_value_list = KpiValueList()
    # To run this experiment sucessfully, already existing UUID in KPI DB in necessary.
    # because the UUID is used to get the descriptor form KPI DB.
    # To run this experiment sucessfully, add an existing UUID of a KPI Descriptor from the 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",
                        str(uuid.uuid4()), 
                        str(uuid.uuid4())]
+2 −2
Original line number Diff line number Diff line
@@ -63,8 +63,8 @@ class MetricWriterToPrometheus:
    def create_and_expose_cooked_kpi(self, kpi_descriptor: KpiDescriptor, kpi_value: KpiValue):
        # merge both gRPC messages into single varible.
        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
        metric_tags = [tag for tag in cooked_kpi.keys() if tag not in tags_to_exclude]
        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]  # These values will be used as metric tags
        metric_name = cooked_kpi['kpi_sample_type']
        try:
            if metric_name not in PROM_METRICS:     # Only register the metric, when it doesn't exists