Skip to content

Commit

Permalink
Fix top 5 charts values in reports by calculating the correct average…
Browse files Browse the repository at this point in the history
… query duration
  • Loading branch information
VitaliStupin authored Oct 18, 2024
1 parent 9751967 commit aadd1b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
24 changes: 19 additions & 5 deletions reports_module/opmon_reports/report_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,10 @@ def get_succeeded_top(self, data, produced_service):
if count <= 0:
continue

if name not in result_dict or result_dict[name] < count:
if name not in result_dict:
result_dict[name] = count
else:
result_dict[name] += count

sorted_pairs = sorted(result_dict.items(), key=operator.itemgetter(1))
return sorted_pairs if len(sorted_pairs) < 6 else sorted_pairs[-5:]
Expand All @@ -421,16 +423,28 @@ def create_duration_plot(self, data, produced_service, file_name):
return self.create_plot(names, durations, translated_title, file_name)

def get_duration_top(self, data, produced_service):
sum_dict = dict()
count_dict = dict()
result_dict = dict()
for key1 in data:
for key2 in data[key1]:
duration = data[key1][key2].duration_avg.rounded_average
duration_sum = data[key1][key2].duration_avg.sum
query_count = data[key1][key2].duration_avg.count
duration_mean = data[key1][key2].duration_avg.rounded_average
name = f"{self.target.subsystem_code}: {key1}" if produced_service else f"{key1}: {key2}"
if duration is None:
if duration_mean is None:
continue

if name not in result_dict or result_dict[name] < duration:
result_dict[name] = duration
if name not in result_dict:
sum_dict[name] = duration_sum
count_dict[name] = query_count
result_dict[name] = duration_mean
else:
# Calculating the average duration of a produced service by summing
# the client report rows
sum_dict[name] += duration_sum
count_dict[name] += query_count
result_dict[name] = round(sum_dict[name] / count_dict[name])

sorted_pairs = sorted(result_dict.items(), key=operator.itemgetter(1))
return sorted_pairs if len(sorted_pairs) < 6 else sorted_pairs[-5:]
Expand Down
12 changes: 6 additions & 6 deletions reports_module/opmon_reports/tests/test_report_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ def test_get_succeeded_top(mocker, basic_args, target_subsystem):
test_data = map_rows_to_producer_services(rows)
succeeded_top = report_manager.get_succeeded_top(test_data, produced_service=True)
assert succeeded_top == [
('TEST_SUB: service_2', 12),
('TEST_SUB: service_3', 14),
('TEST_SUB: service_1', 15)
('TEST_SUB: service_1', 32),
('TEST_SUB: service_2', 32),
('TEST_SUB: service_3', 35)
]

test_data = map_rows_to_consumer_services(rows)
Expand Down Expand Up @@ -264,9 +264,9 @@ def test_get_duration(mocker, basic_args, target_subsystem):
test_data = map_rows_to_producer_services(rows)
duration_top = report_manager.get_duration_top(test_data, produced_service=True)
assert duration_top == [
('TEST_SUB: service_2', 90),
('TEST_SUB: service_1', 100),
('TEST_SUB: service_3', 110)
('TEST_SUB: service_2', 39),
('TEST_SUB: service_1', 43),
('TEST_SUB: service_3', 47)
]

test_data = map_rows_to_consumer_services(rows)
Expand Down

0 comments on commit aadd1b4

Please sign in to comment.