Skip to content

Implement Asynchronous EC2 Metadata Client #3523

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

Merged
merged 26 commits into from
Nov 8, 2022

Conversation

L-Applin
Copy link
Contributor

Implementation of the Asynchronous Ec2 Metadata Client.

Motivation and Context

This is part of the required features before release of the EC2Metadata Service Client

Modifications

Add interface Ec2MetadataAsyncClient and one default implementation.
Slight refactoring of the sync client to keep both client aligned.

Testing

Unit tests added for the implementation.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@L-Applin L-Applin requested a review from a team as a code owner October 27, 2022 14:30
- Create a common builder Ec2MetadataClientBuilder
- Create a common test class BaseEc2MetadataClientTest
- Refactor common initialization logic for both sync and async client in BaseEc2MetadataClient class
- Use netty async client in unit tests
- fix Async error logic
- fix one failing unit test
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 8, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 70 Code Smells

84.2% 84.2% Coverage
1.5% 1.5% Duplication

@L-Applin L-Applin merged commit a5a40da into feature/master/imds Nov 8, 2022
@L-Applin L-Applin deleted the olapplin/imds-async branch November 8, 2022 18:51
private DefaultEc2MetadataAsyncClient(Ec2MetadataAsyncBuilder builder) {
super(builder);
this.httpClient = Validate.getOrDefault(builder.httpClient,
() -> new DefaultSdkAsyncHttpClientBuilder().buildWithDefaults(AttributeMap.empty()));
Copy link
Contributor

Choose a reason for hiding this comment

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

We should create a default attribute map for IMDS, something like the following. I think connection timeout and read timeout are both 1 second.

    private static final AttributeMap IMDS_HTTP_DEFAULTS =
        AttributeMap.builder()
                    .put(SdkHttpConfigurationOption.CONNECTION_TIMEOUT, Duration.ofSeconds(1))
....
                    .build();

connection.setConnectTimeout(1000);
connection.setReadTimeout(1000);
connection.setRequestMethod(method);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3543

httpClient.close();
}
if (isRetryExecutorManaged) {
asyncRetryScheduler.shutdown();
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems an exception thrown from httpClient#close will prevent asyncRetryScheduler from being closed. Should we try catch here?

https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/NettyNioAsyncHttpClient.java#L197

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3543

@@ -36,6 +36,8 @@
@SdkInternalApi
public final class Ec2MetadataEndpointProvider {

public static final Ec2MetadataEndpointProvider DEFAULT_ENDPOINT_PROVIDER = builder().build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make this private and create a static method to return this singleton?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3543

aws-sdk-java-automation added a commit that referenced this pull request Dec 17, 2024
…3b6158226

Pull request: release <- staging/9c9d802f-6722-42b6-ae9d-8cc3b6158226
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.

3 participants