Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #132 from att/T101/cpu_metrics
Browse files Browse the repository at this point in the history
remove cpu cores usage from response
  • Loading branch information
kaylarizi authored Feb 15, 2024
2 parents b1fc89e + b43023a commit 9a8d15e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
12 changes: 4 additions & 8 deletions api/src/utils/test_suite_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ def __get_test_runs_metrics(test_runs):
test_runs_list = []
for test_run in test_runs:
metrics = test_run.test_run_metrics
cpu_cores_avg, cpu_avg, memory_avg = __calculate_cpu_memory_avg(metrics)
cpu_avg, memory_avg = __calculate_cpu_memory_avg(metrics)
request_throughput, bytes_throughput = get_throughput_metrics(metrics)
results = {
"id": test_run.id,
"algorithm": test_run.algorithm,
"iterations": test_run.iterations,
"message_size": test_run.message_size,
"results": {
"average_cpu_cores": round(cpu_cores_avg, 2),
"average_cpu": round(cpu_avg, 2),
"average_memory": int(memory_avg),
"request_throughput": round(request_throughput, 2),
Expand All @@ -50,17 +49,14 @@ def __get_test_runs_metrics(test_runs):


def __calculate_cpu_memory_avg(test_run_metrics):
cpu_cores_avg, cpu_avg, memory_avg = 0.00, 0.00, 0

cpu_avg, memory_avg = 0.00, 0
for metric in test_run_metrics:
if metric.metric_name in (Metric.CLIENT_AVERAGE_CPU_CORES, Metric.SERVER_AVERAGE_CPU_CORES):
cpu_cores_avg += metric.value
elif metric.metric_name in (Metric.CLIENT_AVERAGE_MEMORY, Metric.SERVER_AVERAGE_MEMORY):
if metric.metric_name in (Metric.CLIENT_AVERAGE_MEMORY, Metric.SERVER_AVERAGE_MEMORY):
memory_avg += metric.value
elif metric.metric_name in (Metric.CLIENT_AVERAGE_CPU, Metric.SERVER_AVERAGE_CPU):
cpu_avg += metric.value

return cpu_cores_avg, cpu_avg, memory_avg
return cpu_avg, memory_avg


def get_throughput_metrics(test_run_metrics):
Expand Down
4 changes: 2 additions & 2 deletions api/tests/test_analyze_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ def test_analyze(self, mock_parser, mock_start_collecting, mock_stop_collecting,
self.assertEqual(db_call[7].args[0].metric_name, Metric.SERVER_AVERAGE_CPU)
self.assertEqual(db_call[7].args[0].value, 8.0)
self.assertEqual(db_call[8].args[0].metric_name, Metric.MESSAGES_THROUGHPUT_PER_SECOND)
self.assertEqual(db_call[8].args[0].value, 8.0)
self.assertEqual(db_call[8].args[0].value, 8.33)
self.assertEqual(db_call[9].args[0].metric_name, Metric.BYTES_THROUGHPUT_PER_SECOND)
self.assertEqual(db_call[9].args[0].value, 83.0)
self.assertEqual(db_call[17].args[0].metric_name, Metric.MESSAGES_THROUGHPUT_PER_SECOND)
self.assertEqual(db_call[17].args[0].value, 33.0)
self.assertEqual(db_call[17].args[0].value, 33.33)
self.assertEqual(db_call[18].args[0].metric_name, Metric.BYTES_THROUGHPUT_PER_SECOND)
self.assertEqual(db_call[18].args[0].value, 167.0)

Expand Down
2 changes: 1 addition & 1 deletion api/tests/test_tests_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_get_test_suite(self):
self.app.database_manager.get_by_id.return_value = test_suite
response = self.client.get(TEST_SUITES_GET_URL)
result = json.loads(response.data)
expected = {'code_release': '1.1.0', 'description': 'description', 'end_time': None, 'environment_info': {'cpu': None, 'cpu_architecture': None, 'cpu_clock_speed': None, 'cpu_cores': None, 'node_size': None, 'operating_system': None, 'resource_name': None}, 'id': None, 'name': 'name', 'start_time': None, 'test_runs': [{'algorithm': None, 'id': 1, 'iterations': None, 'message_size': None, 'results': {'average_cpu': 0.8, 'average_cpu_cores': 9.0, 'average_memory': 14, 'request_throughput': 50, 'bytes_throughput': 4500}}]}
expected = {'code_release': '1.1.0', 'description': 'description', 'end_time': None, 'environment_info': {'cpu': None, 'cpu_architecture': None, 'cpu_clock_speed': None, 'cpu_cores': None, 'node_size': None, 'operating_system': None, 'resource_name': None}, 'id': None, 'name': 'name', 'start_time': None, 'test_runs': [{'algorithm': None, 'id': 1, 'iterations': None, 'message_size': None, 'results': {'average_cpu': 0.8, 'average_memory': 14, 'request_throughput': 50, 'bytes_throughput': 4500}}]}
self.assertEqual(result, expected)

def test_get_test_suite_return_not_found(self):
Expand Down

0 comments on commit 9a8d15e

Please sign in to comment.