diff --git a/ros/api/v1/hosts.py b/ros/api/v1/hosts.py index 9e3b2d93..409da856 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 @@ -61,7 +61,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 = { @@ -198,7 +198,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': @@ -217,7 +217,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 = { @@ -276,7 +276,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 1ff27550..e4d5d4d7 100644 --- a/ros/lib/utils.py +++ b/ros/lib/utils.py @@ -79,21 +79,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 8e83d0b5..d76ba51d 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" @@ -400,7 +400,7 @@ "type": "integer" }, "max_io": { - "type": "integer" + "type": "number" }, "io_all": { "type": "object" @@ -458,7 +458,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 55b0d9f4..707ab453 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, @@ -143,7 +143,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(