-
Notifications
You must be signed in to change notification settings - Fork 10
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
AutoScalingGroups support #57
Comments
Hi @ackward Thanks for the feature request. I personally have no worked with ASG before, but I'll take a look at this for you. Your design thoughts around the implementation make total sense to me as well. I'll dig through the API and see how much effort this would take. Hopefully I won't have to make any UI changes. |
Looked into this. My thoughts so far: I see an API call for retrieving ASG, but unlike the EC2 Instance call it does not allow me to filter (by tags). This seems a bit inefficient to me, especially when there is a ton of ASGs that are not tag compatible with aws-power-toggle (not too big of a deal though). Also I will have to write some paging logic, since the max ASGs it can return is 100 (which I don't know if that's a small number or not?). Once I get these ASGs that I filtered out manually via tags, I can add a new object to the cache to keep track of them. If the ASG had a desired count greater than 0 then I can also cache that. When a user decides to power toggle down an environment, I can make an API call with the ASG name and set the desired count to 0 (while still keeping the original non-0 value if it existed). I must then loop through all instances and also issue a shutdown since I am currently not associating instances with an ASG (even though aws is). I could spend some time on this and actually create the association myself in the cache, this would all me to avoid issuing shutdown calls to instances that belong to an ASG that I already zeroed the desire count to. @ackward please confirm if this logic makes any sense :) https://godoc.org/github.com/aws/aws-sdk-go-v2/service/autoscaling#Client.DescribeAutoScalingGroups
https://godoc.org/github.com/aws/aws-sdk-go-v2/service/autoscaling#Client.SetDesiredCapacity
So it's certainly doable, but it would take significant time for me to properly implement since I have to experiment with ASGs as well as write the code. I will provide further updates when I make any progress (but no promises). Obviously help would be greatly appreciated if anyone else is interested in this feature. |
Thanks for the detailed implementation plan @ackward, that really helped in shedding more light on how to handle this. That extra tag I can see one problem though. Let's say an ASG has been shutdown (so desired state is set to 0). Then we restart aws-power-toggle. Unfortunately, we only discover environments based on instances (current design anyways), so if we don't poll for ASGs we can't interact with it again since no instance will have a tag |
Yes, that's correct. My plan is to run the tool as an ECS fargate (using env variables to overwrite the yaml config file), everything declared inside a CFT, the IAM role and the table will also be provisioned in just a CF Stack. |
Yea I don't think adding a state requirement is worth it just for this feature. I'm pretty happy keeping it stateless. I can work on adding this feature as experimental (can be enabled by config flag). It will poll the ASGs and present them as a single instance with combined cpu/memory stats. I will look into this when I get some time, I will also need to experiment a bit with ASGs ;) |
Thanks for your time, if you are interested in the CFT for ECS Fargate I can upload it somewhere. session = boto3.Session(profile_name='%s' % profile)
auto = session.client('autoscaling',region_name='eu-west-1')
page_iterator = auto.get_paginator('describe_auto_scaling_groups').paginate(PaginationConfig={'PageSize': 100} )
for page in page_iterator:
for asg in page["AutoScalingGroups"]:
if any(d["Key"] == 'power-toggle-enabled' and d["Value"] == 'true' for d in asg["Tags"]): print (asg["AutoScalingGroupName"]) The tag "power-toggle-enabled" must be declared in the ASG, not only in the LaunchTemplate or LaunchConfiguration. |
FYI, before you spend a lot of time on this. I've managed to get it working. It needs quite a bit of cleaning/documentation and don't expect great quality code (first time coding in go, the last time I did something in C-like was 20 years ago) |
Hey @ackward, I would love to review your code and both welcome and appreciate your contributions. Please feel free to push a fork at your earliest convenience. |
Toogle by env is still not supported, I need to look at it. |
Thanks @ackward |
Hi @ackward I looked over your branch and added some stuff, (I couldn't commit it to your fork). Your code was great BTW. Please try building it and seeing if it works to your liking: https://github.com/gbolo/aws-power-toggle/tree/asg_support |
* ASG Support * CloudFormation Example * fix env functionality * fix ever-increasing cache table when ASG support is turned off * fix broken test case * update docs to describe ASG functionality Co-authored-by: n0251612 <g.gainza@libertyseguros.es> Co-authored-by: ackward <ackward@gmail.com>
@ackward I merged this into the |
Hi!,
First of all, thanks and congrats for this superb tool :)
I don't know if it's too much work but I miss the lack of ASG (AutoScalingGroup) support, most of my EC2 instances are part of an ASG, as they follow the same design model for nonprod and prod. We have scheduled actions that stops them at the evening and starts them at the morning but it's inneficient as most of them could be left stopped or even better, not start them and let the developers (or app owners) start them from a web frontend.
aws-power-toogle could stop the ASG just setting the DesiredCount to 0 and for starting the instances, setting the DesiredCount to 1 (or to the original desired size if it was cached). Managed by the same tags that for EC2.
The text was updated successfully, but these errors were encountered: