This repository has been archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 966
feat: Output table sizes while calculating #7065
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we remove the and bit? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.