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

feat: Output table sizes while calculating #7065

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 14 additions & 5 deletions util/jenkins/check_table_size/check_table_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def check_table_growth(rds_list, username, password, threshold, rds_threshold):
table_list = []
for db in rds_list:
print("Checking table sizes for {}".format(db["Endpoint"]))
format_string_header = "{:<50} {:<30} {:<70}"
print(format_string_header.format("RDS Name","Database Name", "Table Name", "Size"))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing space after comma

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like that was copied from the code below for displaying the tables over the threshold, which would ideally also be fixed. Later, we should either add a linter here or move this code somewhere that already has linting set up.

rds_host_endpoint = db["Endpoint"]
rds_port = db["Port"]
connection = pymysql.connect(host=rds_host_endpoint,
Expand All @@ -102,12 +104,15 @@ def check_table_growth(rds_list, username, password, threshold, rds_threshold):
threshold_limit = threshold
for tables in rds_result:
temp_dict = {}
if tables[2] is not None and tables[2] > float(threshold_limit):
if tables[2] is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we remove the and bit?

Copy link
Contributor

Choose a reason for hiding this comment

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

That condition got moved further down, so we can display the size of tables that don't exceed the threshold.

temp_dict["rds"] = db["name"]
temp_dict["db"] = tables[0]
temp_dict["table"] = tables[1]
temp_dict["size"] = tables[2]
table_list.append(temp_dict)
format_string = "{:<50} {:<30} {:<70} {:>20,}"
print(format_string.format(temp_dict["rds"], temp_dict["db"], temp_dict["table"], temp_dict["size"]) + " MB")
if tables[2] > float(threshold_limit):
table_list.append(temp_dict)
return table_list
except Exception as ex:
print(ex)
Expand Down Expand Up @@ -139,10 +144,14 @@ def controller(username, password, threshold, rdsthreshold, rdsignore):
filtered_rds_list = list([x for x in rds_list if x['name'] not in rdsignore])
table_list = check_table_growth(filtered_rds_list, username, password, threshold, rds_threshold)
if len(table_list) > 0:
format_string = "{:<40}{:<20}{:<50}{}"
print(format_string.format("RDS Name","Database Name", "Table Name", "Size"))
print("#############################")
print("# Tables over the threshold #")
print("#############################")
format_string_header = "{:<50} {:<30} {:<70}"
print(format_string_header.format("RDS Name","Database Name", "Table Name", "Size"))
format_string = "{:<50} {:<30} {:<70} {:>20,}"
for items in table_list:
print(format_string.format(items["rds"], items["db"], items["table"], str(items["size"]) + " MB"))
print(format_string.format(items["rds"], items["db"], items["table"], items["size"]) + " MB")
exit(1)
exit(0)

Expand Down