From ae940a67fa2af8d857f09c9c90467c08cffda92e Mon Sep 17 00:00:00 2001 From: Sagnik Dutta Date: Mon, 10 Jan 2022 16:21:14 +0530 Subject: [PATCH] IOPS Values from Rules Changes are based on the assumption that IOPS values are actuals from rules --- ros/api/v1/hosts.py | 10 ++++---- ros/lib/utils.py | 24 +++++++++---------- ros/openapi/openapi.json | 6 ++--- .../insights_engine_result_consumer.py | 4 ++-- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/ros/api/v1/hosts.py b/ros/api/v1/hosts.py index a2da53e2..f00997f6 100644 --- a/ros/api/v1/hosts.py +++ b/ros/api/v1/hosts.py @@ -1,5 +1,5 @@ from sqlalchemy import func, asc, desc -from sqlalchemy.types import Integer +from sqlalchemy.types import Float from flask import request from flask_restful import Resource, abort, fields, marshal_with @@ -58,7 +58,7 @@ class HostsApi(Resource): performance_utilization_fields = { 'cpu': fields.Integer, 'memory': fields.Integer, - 'max_io': fields.Integer, + 'max_io': fields.Float, 'io_all': fields.Raw } hosts_fields = { @@ -199,7 +199,7 @@ def build_sort_expression(self, order_how, order_method): if order_method in score_methods: return ( sort_order(PerformanceProfile.performance_utilization[ - order_method].astext.cast(Integer)), + order_method].astext.cast(Float)), asc(PerformanceProfile.system_id),) if order_method == 'number_of_suggestions': @@ -218,7 +218,7 @@ class HostDetailsApi(Resource): performance_utilization_fields = { 'cpu': fields.Integer, 'memory': fields.Integer, - 'max_io': fields.Integer, + 'max_io': fields.Float, 'io_all': fields.Raw } profile_fields = { @@ -280,7 +280,7 @@ class HostHistoryApi(Resource): 'cpu': fields.Integer, 'memory': fields.Integer, 'io_all': fields.Raw, - 'max_io': fields.Integer, + 'max_io': fields.Float, 'report_date': fields.String } meta_fields = { diff --git a/ros/lib/utils.py b/ros/lib/utils.py index 9054f6b8..27a9da62 100644 --- a/ros/lib/utils.py +++ b/ros/lib/utils.py @@ -78,21 +78,19 @@ def validate_type(value, type_): return True if type(evaluated_value) == type_ else False -def convert_to_iops_actuals(iops_dict): +def cast_iops_as_float(iops_all_dict): """ - Convert IOPS to MBPS fom percentage. - In case IOPS values are actual, - converts them to int from str - :param iops_dict: IOPS dict to convert. - :return: IOPS values converted to MBPS. + Convert IOPS values from str to float + :param iops_all_dict: IOPS dict to convert. + :return: IOPS values as float """ - iops_in_mbps = {} - for key, value in iops_dict.items(): - if float(value) < 1.0: - iops_in_mbps[key] = int(float(value) * 1000) - else: - iops_in_mbps[key] = int(value) - return iops_in_mbps + iops_all_dict_float = {} + for key, value in iops_all_dict.items(): + try: + iops_all_dict_float[key] = float(value) + except ValueError: + continue + return iops_all_dict_float def sort_io_dict(performance_utilization: dict): diff --git a/ros/openapi/openapi.json b/ros/openapi/openapi.json index 35697f6e..f8c1a46a 100644 --- a/ros/openapi/openapi.json +++ b/ros/openapi/openapi.json @@ -350,7 +350,7 @@ "type": "integer" }, "max_io": { - "type": "integer" + "type": "number" }, "io_all": { "type": "object" @@ -403,7 +403,7 @@ "type": "integer" }, "max_io": { - "type": "integer" + "type": "number" }, "io_all": { "type": "object" @@ -464,7 +464,7 @@ "type": "integer" }, "max_io": { - "type": "integer" + "type": "number" }, "io_all": { "type": "object" diff --git a/ros/processor/insights_engine_result_consumer.py b/ros/processor/insights_engine_result_consumer.py index e4ff4c1b..9106efcf 100644 --- a/ros/processor/insights_engine_result_consumer.py +++ b/ros/processor/insights_engine_result_consumer.py @@ -4,7 +4,7 @@ from ros.lib.config import (INSIGHTS_KAFKA_ADDRESS, GROUP_ID, ENGINE_RESULT_TOPIC, get_logger) from ros.lib.models import RhAccount, System, PerformanceProfile -from ros.lib.utils import get_or_create, convert_to_iops_actuals +from ros.lib.utils import get_or_create, cast_iops_as_float from confluent_kafka import Consumer, KafkaException from ros.processor.metrics import (processor_requests_success, processor_requests_failures, @@ -145,7 +145,7 @@ def process_report(self, host, reports, utilization_info, performance_record): performance_utilization = { 'memory': int(utilization_info['mem_utilization']), 'cpu': int(utilization_info['cpu_utilization']), - 'io': convert_to_iops_actuals(utilization_info['io_utilization']) + 'io': cast_iops_as_float(utilization_info['io_utilization']) } # max_io will be used to sort systems endpoint response instead of io performance_utilization.update(