Skip to content

Commit 46f06a7

Browse files
authored
IOPS Values from Rules (#168)
Changes are based on the assumption that IOPS values are actuals from rules Co-authored-by: Sagnik Dutta <[email protected]>
1 parent cb7ab98 commit 46f06a7

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

ros/api/v1/hosts.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from sqlalchemy import func, asc, desc
2-
from sqlalchemy.types import Integer
2+
from sqlalchemy.types import Float
33
from flask import request
44
from flask_restful import Resource, abort, fields, marshal_with
55

@@ -61,7 +61,7 @@ class HostsApi(Resource):
6161
performance_utilization_fields = {
6262
'cpu': fields.Integer,
6363
'memory': fields.Integer,
64-
'max_io': fields.Integer,
64+
'max_io': fields.Float,
6565
'io_all': fields.Raw
6666
}
6767
hosts_fields = {
@@ -198,7 +198,7 @@ def build_sort_expression(self, order_how, order_method):
198198
if order_method in score_methods:
199199
return (
200200
sort_order(PerformanceProfile.performance_utilization[
201-
order_method].astext.cast(Integer)),
201+
order_method].astext.cast(Float)),
202202
asc(PerformanceProfile.system_id),)
203203

204204
if order_method == 'number_of_suggestions':
@@ -217,7 +217,7 @@ class HostDetailsApi(Resource):
217217
performance_utilization_fields = {
218218
'cpu': fields.Integer,
219219
'memory': fields.Integer,
220-
'max_io': fields.Integer,
220+
'max_io': fields.Float,
221221
'io_all': fields.Raw
222222
}
223223
profile_fields = {
@@ -276,7 +276,7 @@ class HostHistoryApi(Resource):
276276
'cpu': fields.Integer,
277277
'memory': fields.Integer,
278278
'io_all': fields.Raw,
279-
'max_io': fields.Integer,
279+
'max_io': fields.Float,
280280
'report_date': fields.String
281281
}
282282
meta_fields = {

ros/lib/utils.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,19 @@ def validate_type(value, type_):
7979
return True if type(evaluated_value) == type_ else False
8080

8181

82-
def convert_to_iops_actuals(iops_dict):
82+
def cast_iops_as_float(iops_all_dict):
8383
"""
84-
Convert IOPS to MBPS fom percentage.
85-
In case IOPS values are actual,
86-
converts them to int from str
87-
:param iops_dict: IOPS dict to convert.
88-
:return: IOPS values converted to MBPS.
84+
Convert IOPS values from str to float
85+
:param iops_all_dict: IOPS dict to convert.
86+
:return: IOPS values as float
8987
"""
90-
iops_in_mbps = {}
91-
for key, value in iops_dict.items():
92-
if float(value) < 1.0:
93-
iops_in_mbps[key] = int(float(value) * 1000)
94-
else:
95-
iops_in_mbps[key] = int(value)
96-
return iops_in_mbps
88+
iops_all_dict_float = {}
89+
for key, value in iops_all_dict.items():
90+
try:
91+
iops_all_dict_float[key] = float(value)
92+
except ValueError:
93+
continue
94+
return iops_all_dict_float
9795

9896

9997
def sort_io_dict(performance_utilization: dict):

ros/openapi/openapi.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
"type": "integer"
351351
},
352352
"max_io": {
353-
"type": "integer"
353+
"type": "number"
354354
},
355355
"io_all": {
356356
"type": "object"
@@ -400,7 +400,7 @@
400400
"type": "integer"
401401
},
402402
"max_io": {
403-
"type": "integer"
403+
"type": "number"
404404
},
405405
"io_all": {
406406
"type": "object"
@@ -458,7 +458,7 @@
458458
"type": "integer"
459459
},
460460
"max_io": {
461-
"type": "integer"
461+
"type": "number"
462462
},
463463
"io_all": {
464464
"type": "object"

ros/processor/insights_engine_result_consumer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ros.lib.config import (INSIGHTS_KAFKA_ADDRESS, GROUP_ID,
55
ENGINE_RESULT_TOPIC, get_logger)
66
from ros.lib.models import RhAccount, System, PerformanceProfile
7-
from ros.lib.utils import get_or_create, convert_to_iops_actuals
7+
from ros.lib.utils import get_or_create, cast_iops_as_float
88
from confluent_kafka import Consumer, KafkaException
99
from ros.processor.metrics import (processor_requests_success,
1010
processor_requests_failures,
@@ -143,7 +143,7 @@ def process_report(self, host, reports, utilization_info, performance_record):
143143
performance_utilization = {
144144
'memory': int(utilization_info['mem_utilization']),
145145
'cpu': int(utilization_info['cpu_utilization']),
146-
'io': convert_to_iops_actuals(utilization_info['io_utilization'])
146+
'io': cast_iops_as_float(utilization_info['io_utilization'])
147147
}
148148
# max_io will be used to sort systems endpoint response instead of io
149149
performance_utilization.update(

0 commit comments

Comments
 (0)