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

refactor: faster EC2 instance search #535

Merged
merged 8 commits into from
Aug 1, 2021

Conversation

glasswalk3r
Copy link
Contributor

Based on available documentation, this PR introduces some assertions to check if the id parameter has the expected format of a instance id.

If does, than an attempt to find the instance is attempted, just like the original code.

If the id has not a instance id expected format, than an attempt with a tag name is attempted instead, avoiding an API request that would probably fail anyway.

@k1LoW
Copy link
Owner

k1LoW commented Jun 28, 2021

@glasswalk3r Thank you for your commitment!

I like the idea of verifying what can be verified in advance before the API call.

But if this change is introduced, it appears that if there is a change in the format of the resource ID ( for example, prefix change i- to ec-i- ), the search will not work as it did before the change.

I think the test code should run as stably as possible.

@glasswalk3r
Copy link
Contributor Author

Hi @k1LoW ,

You're right, there is a tradeoff.

Unfortunately, there is no way to get to know the format dynamically, only to check if your account has migrated or not to the latest format.

On the other hand, it could take years from now for AWS to change that again (if it will ever happen) and that would probably be a planned modification, with customer being notified well before the change is applied to avoid breaking compatibility.

The instance ID is already at the second generation, no way to predict if it is going to change again or not.

The only way I see to implement compatibility with the old way of Ec2::find_ec2 is to keep it as is and use an environment variable to adopt the newer behavior... or vice-versa.

What do you think?

@k1LoW
Copy link
Owner

k1LoW commented Jul 4, 2021

I think the test code should run as stably as possible.

In other words, we believe that stability is better than expansion for faster performance.

@glasswalk3r
Copy link
Contributor Author

I think the test code should run as stably as possible.

In other words, we believe that stability is better than expansion for faster performance.

Understood @k1LoW !
I made some new changes, adding a fallback in the case a given id that does not look like an EC2 instance ID but does work like one.

It would not only keep things working as expected, but giving us a proper warning that something changed regarding the instance ID format.

@k1LoW
Copy link
Owner

k1LoW commented Aug 1, 2021

@glasswalk3r Thank you !!! Great !

@k1LoW k1LoW merged commit 63338db into k1LoW:master Aug 1, 2021
@glasswalk3r glasswalk3r deleted the feature/fast_ec2_finder branch August 1, 2021 21:57
@k1LoW
Copy link
Owner

k1LoW commented Aug 9, 2021

Released as v1.24.4.

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