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

Randomize usage values for each ros-ocp line item #512

Merged
merged 3 commits into from
Jun 24, 2024
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
2 changes: 1 addition & 1 deletion nise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.5.5"
__version__ = "4.5.6"

VERSION = __version__.split(".")
34 changes: 34 additions & 0 deletions nise/generators/ocp/ocp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,43 @@ def _update_pod_data(self, row, start, end, **kwargs):
row.update(pod)
return row

def _randomize_ros_ocp_line_values(self, pod_in):
"""Randomize usage values for each line item or ROS report"""
values_to_randomize = [
"cpu_usage_container_avg",
"cpu_usage_container_min",
"cpu_usage_container_max",
"cpu_usage_container_sum",
"cpu_throttle_container_avg",
"cpu_throttle_container_max",
"cpu_throttle_container_sum",
"memory_usage_container_avg",
"memory_usage_container_min",
"memory_usage_container_max",
"memory_usage_container_sum",
"memory_rss_usage_container_avg",
"memory_rss_usage_container_min",
"memory_rss_usage_container_max",
"memory_rss_usage_container_sum",
]
randomization_value = uniform(0.9, 1.1)
cpu_limit = pod_in.get("cpu_limit_container_avg", 1000000)
memory_limit = pod_in.get("memory_limit_container_avg", 1e20)

pod_out = pod_in.copy()
for pod_key in values_to_randomize:
if pod_value := pod_in.get(pod_key):
if pod_key.startswith("cpu"):
pod_out[pod_key] = round(min(randomization_value * pod_value, cpu_limit), 5)
else:
pod_out[pod_key] = round(min(randomization_value * pod_value, memory_limit))
return pod_out

def _update_ros_ocp_pod_data(self, row, start, end, **kwargs):
"""Update data with generator specific data."""
pod = kwargs.get("pod")
if pod:
pod = self._randomize_ros_ocp_line_values(pod)
row.update(pod)
return row

Expand Down
Loading