Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHISOS 470 | IOPS Values from Rules are actuals #168

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 = {
Expand Down Expand Up @@ -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),)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PreetiW Change on line 202, will handle the previous sort error, tested ✅


if order_method == 'number_of_suggestions':
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
24 changes: 11 additions & 13 deletions ros/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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 @@ -403,7 +403,7 @@
"type": "integer"
},
"max_io": {
"type": "integer"
"type": "number"
},
"io_all": {
"type": "object"
Expand Down Expand Up @@ -464,7 +464,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 @@ -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(
Expand Down