Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#185529919] Reworked instance tags in ruby script #3404

Merged
merged 1 commit into from
Oct 3, 2023
Merged
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
17 changes: 12 additions & 5 deletions scripts/upgrade_instance_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def process_instance(rds_client, instance, target_class, dry_run)
end

if compatible
MyLogger.instance.log_info("Updating instance #{instance.db_instance_identifier} from #{instance.db_instance_class} to #{target_class} db_instance_class during maintenance window...")
MyLogger.instance.log_warn("Updating instance #{instance.db_instance_identifier} from #{instance.db_instance_class} to #{target_class} db_instance_class during maintenance window...")

state = manage_instance_state(rds_client, instance)

Expand All @@ -159,7 +159,7 @@ def process_instance(rds_client, instance, target_class, dry_run)
modify_instance(rds_client, instance, target_class, instance.engine_version, dry_run)
end
else
MyLogger.instance.log_info("Target instance class #{target_class} is not compatible with the current engine version.")
MyLogger.instance.log_warn("Target instance class #{target_class} is not compatible with the current engine version.")
MyLogger.instance.log_info("... trying to find a suitable engine upgrade.")

engine_version_options = get_available_engine_version_options(rds_client, instance, target_class)
Expand Down Expand Up @@ -190,7 +190,7 @@ def process_instance(rds_client, instance, target_class, dry_run)
end
end

def main(deploy_env, dry_run)
def main(env, dry_run)
instance_class_mapping = {
"db.t2." => "db.t3.",
"db.m4." => "db.m5.",
Expand All @@ -202,10 +202,17 @@ def main(deploy_env, dry_run)

instances.each do |instance|
instance.tag_list.each do |tag|
if tag[:key] == "deploy_env" && tag[:value] == deploy_env
if (tag[:key] == "deploy_env" || tag[:key] == "Broker Name") && tag[:value] == env
risicle marked this conversation as resolved.
Show resolved Hide resolved
# Is the instance class of interest?
if instance_class_mapping.key? instance.db_instance_class[0..5]
# skip postgres 10 dbs
if instance.engine == "postgres" && instance.engine_version.start_with?("10.")
MyLogger.instance.log_warn("instance #{instance.db_instance_identifier} is postgres 10 and will not be processed.")
next
end
Copy link
Member

Choose a reason for hiding this comment

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

We.. have pg10 databases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it also surprised Andy

target_class = instance.db_instance_class.sub(instance.db_instance_class[0..5], instance_class_mapping.fetch(instance.db_instance_class[0..5]))
MyLogger.instance.log_warn("Updating instance #{instance.db_instance_identifier} with class: #{target_class} and engine version: #{instance.engine_version}.")

process_instance(rds_client, instance, target_class, dry_run)
else
MyLogger.instance.log_info("Instance #{instance.db_instance_identifier} doesn't have a db instance class that needs replacing.")
Expand All @@ -214,7 +221,7 @@ def main(deploy_env, dry_run)
end
end
rescue Aws::RDS::Errors::ServiceError => e
MyLogger.instance.log_fatal("Caught #{e.class}, exiting")
MyLogger.instance.log_fatal("Caught exception: #{e.class}, message: #{e.message} ... exiting")
end

ARGV << "-h" if ARGV.empty?
Expand Down