From b979b097462ee3eb77f583523d5c2408101585d9 Mon Sep 17 00:00:00 2001 From: Joseph Mulloy Date: Thu, 16 Nov 2023 13:04:47 -0500 Subject: [PATCH] feat: Output table sizes while calculating Adds table sizes to output while running checks to add transparency to the process. --- .../check_table_size/check_table_size.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/util/jenkins/check_table_size/check_table_size.py b/util/jenkins/check_table_size/check_table_size.py index bf047da354f..4a7fac7617c 100644 --- a/util/jenkins/check_table_size/check_table_size.py +++ b/util/jenkins/check_table_size/check_table_size.py @@ -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")) rds_host_endpoint = db["Endpoint"] rds_port = db["Port"] connection = pymysql.connect(host=rds_host_endpoint, @@ -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: 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) @@ -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)