Skip to content

CRAB-21879: Add a tag_instances command to Nagbot#1

Open
dakkanner wants to merge 2 commits intomasterfrom
feature/dk/add-stop-and-terminate-dates-CRAB-21879
Open

CRAB-21879: Add a tag_instances command to Nagbot#1
dakkanner wants to merge 2 commits intomasterfrom
feature/dk/add-stop-and-terminate-dates-CRAB-21879

Conversation

@dakkanner
Copy link

This adds a new tag_instances command to Nagbot. It's intended to run shortly before notify in the mornings.

If Stop after tag is not present, it will be set to three days in the future. If Terminate after is not set to a valid date, it will be set to two weeks in the future. A slack message will be sent if any instances get new tags added.


I hope to extend this new command in the future to parse the instance Name, look for any known names within Seeq, and automatically add a Contact email. E.G. an instance named "Dak's manual testing" would be able to automatically add my email address as the contact.

@dakkanner dakkanner requested a review from dkharlan October 16, 2020 23:06
Copy link

@dkharlan dkharlan left a comment

Choose a reason for hiding this comment

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

Aside from a couple piddling formatting / style comments, I think this looks good! I ran the unit tests and everything passed.

I can break out some time to exploratory test later today or tomorrow, once I make a bit more headway on my STAR week stuff -- how have you been testing this with EC2? I assume the easiest way to do so in isolation would be to spin up a couple free-tier instances on my personal account (?)

app/nagbot.py Outdated
if not instance.stop_after:
sqaws.set_tag(instance.region_name, instance.instance_id, 'Stop after',
AUTO_STOP_AFTER_DAY_YYYY_MM_DD)
if (not instance.terminate_after

Choose a reason for hiding this comment

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

This would be a bit more readable if we pulled out a helper method e.g. _terminate_after_date_present(instance) or something; could also be used by is_taggable()

Choose a reason for hiding this comment

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

Actually, it could be a method on Instance

Copy link
Author

Choose a reason for hiding this comment

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

I moved is_stop_after_tag_missing and is_terminate_after_tag_missing to Instance. I chose not to pass the whitelist logic into Instance or move other functions like is_stoppable, which would require moving or passing the DateTime constants for now. I would like to do so in the future, but maybe in more of a 0.0.1 pass.

@dakkanner dakkanner force-pushed the feature/dk/add-stop-and-terminate-dates-CRAB-21879 branch from f76c363 to fa488f8 Compare October 31, 2020 02:35
@dakkanner
Copy link
Author

Aside from a couple piddling formatting / style comments, I think this looks good! I ran the unit tests and everything passed.

I can break out some time to exploratory test later today or tomorrow, once I make a bit more headway on my STAR week stuff -- how have you been testing this with EC2? I assume the easiest way to do so in isolation would be to spin up a couple free-tier instances on my personal account (?)

That's a great question. Once the code looked good, I was planning on doing something similar to your suggestions - either giving the bot free reign on my personal account with $0 instances or adding custom filter logic before deploying so it could only potentially impact a select few instances. Since this is set up as a whole new top-level arg to be run in its own Cron schedule, it's very easy to test and deploy it independently.

(I have no idea how to reply to top-level comments in Github. Hopefully this is how.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants