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

aws-backend: add support for running instances on multiple subnets #700

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

timbrown5
Copy link

Update the AWS backend (and instance config) to add the ability to run instance on a set of subnets (and
so availability zone).

The main use-case for this is to allow instance to come up in multiple availability zones. A user would create one (or more) subnets in an availability zone and the list the subnets in the subnet_configs section. This has two main advantages:

  • There is some crude load balancing (subnets are picked at random from the list)
  • If an instance fails to start we can retry in another subnet. This will help in cases where an AZ has been starved of all the instance and instance not longer start.

To support this (without breaking existing configs) I added a new subnet_configs section to the instance config. This is mutually exclusive to the existing subnet_id section.
If subnet_configs is set, then the backend will choose one of the subnets at random and try to bring up the instance there. If this fails. then another subnet will be tried, until one works. If none of the subnets work, an the exception will be re-raised.

@timbrown5 timbrown5 requested a review from a team as a code owner January 16, 2025 13:53
@@ -70,7 +127,7 @@ def test_aws_instance_config(runner: Runner):
assert instance["TagSpecifications"][1]["ResourceType"] == "volume"


@mark.skipif(not os.getenv("AWS_ACCESS_KEY_ID"), reason="AWS credentials not found")
@mark.skipif(not os.getenv("AWS_ACCESS_KEY_ID") and not os.getenv("AWS_PROFILE"), reason="AWS credentials not found")
Copy link
Author

@timbrown5 timbrown5 Jan 16, 2025

Choose a reason for hiding this comment

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

Note: I use aws SSO profiles for auth, so needed to add a check for the AWS_PROFILE env var to be able to run the tests.

Copy link

codecov bot commented Jan 16, 2025

Codecov Report

Attention: Patch coverage is 19.14894% with 38 lines in your changes missing coverage. Please review.

Project coverage is 84.80%. Comparing base (8969d71) to head (3f60dbf).

Files with missing lines Patch % Lines
runner_manager/backend/aws.py 11.62% 38 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #700      +/-   ##
==========================================
- Coverage   86.68%   84.80%   -1.88%     
==========================================
  Files          35       35              
  Lines        1510     1547      +37     
==========================================
+ Hits         1309     1312       +3     
- Misses        201      235      +34     
Flag Coverage Δ
api 62.76% <19.14%> (-1.15%) ⬇️
unit 66.96% <19.14%> (-1.45%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tcarmet
Copy link
Contributor

tcarmet commented Jan 16, 2025

Hey @timbrown5 ! Thank you for the contribution!

Haven't got the time to review it properly yet, but will do soon, in the meantime, don't worry about codecov complaining, we don't execute those tests in the CI, but do check the linting issues reported (should be easily fixed with a trunk fmt if you have trunk installed).

Cheers!

Copy link
Contributor

@tcarmet tcarmet left a comment

Choose a reason for hiding this comment

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

just a small change request, and let's merge it.

Thanks again

order = list(range(len(subnet_configs)))
shuffle(order)
subnet_config = self.instance_config.subnet_configs
print(f"Order: {order}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Use log

Suggested change
print(f"Order: {order}")
log.debug(f"Order: {order}")

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