Skip to content

Commit

Permalink
IOPS Values from Rules (#168)
Browse files Browse the repository at this point in the history
Changes are based on the assumption that IOPS values are actuals from rules

Co-authored-by: Sagnik Dutta <sdutta@redhat.com>
  • Loading branch information
saltgen and saltgen authored Jan 10, 2022
1 parent cb7ab98 commit 46f06a7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
10 changes: 5 additions & 5 deletions ros/api/v1/hosts.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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':
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
24 changes: 11 additions & 13 deletions ros/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions ros/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
"type": "integer"
},
"max_io": {
"type": "integer"
"type": "number"
},
"io_all": {
"type": "object"
Expand Down Expand Up @@ -400,7 +400,7 @@
"type": "integer"
},
"max_io": {
"type": "integer"
"type": "number"
},
"io_all": {
"type": "object"
Expand Down Expand Up @@ -458,7 +458,7 @@
"type": "integer"
},
"max_io": {
"type": "integer"
"type": "number"
},
"io_all": {
"type": "object"
Expand Down
4 changes: 2 additions & 2 deletions ros/processor/insights_engine_result_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 46f06a7

Please sign in to comment.