Skip to content

Append User-Agent for Waiters operations #2039

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 1 commit into from
Sep 22, 2020

Conversation

Quanzzzz
Copy link
Contributor

Currently, there is no signs for Waiters in the User-Agent header, and to track the usage of waiters, we should append a specific user agent for waiters in the header.

Description

The codegen module is modified, adding the method appending userAgent for waiters in all the operations related to the waiters.

Testing

The generated dynamodb client is tested with the waiters. There are two WireMock tests verifying if the requests triggered by the waiters include the WAITERS user agent in them.

Screenshots (if appropriate)

Types of changes

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

License

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

@Quanzzzz Quanzzzz force-pushed the waiters-development branch 2 times, most recently from f78f4f4 to 0d520b0 Compare September 16, 2020 21:46
@Quanzzzz Quanzzzz changed the title Append userAgent for Waiters operations Append User-Agent for Waiters operations Sep 16, 2020
@Quanzzzz Quanzzzz requested review from zoewangg and removed request for zoewangg September 16, 2020 22:26
@Quanzzzz Quanzzzz force-pushed the waiters-development branch 2 times, most recently from e6f2589 to 7567d23 Compare September 17, 2020 02:19
@Quanzzzz Quanzzzz requested a review from millems September 17, 2020 02:19
@Quanzzzz Quanzzzz force-pushed the waiters-development branch 3 times, most recently from 64c4737 to 9be7b05 Compare September 18, 2020 16:54
@@ -84,6 +89,15 @@ public void close() {
return new DefaultBuilder();
}

private <T extends QueryRequest> T applyWaitersUserAgent(T request) {
Consumer<AwsRequestOverrideConfiguration.Builder> userAgentApplier = b -> b.addApiName(ApiName.builder()
.version(VersionInfo.SDK_VERSION).name("WAITERS").build());
Copy link
Contributor

Choose a reason for hiding this comment

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

In metric publisher we do

ApiName.builder().name("hll").version("cw-mp").build();

With the mapper we do

ApiName.builder().version("ddb-enh").name("hll").build();

Waiters is kind of a high-level library. Should we do

ApiName.builder().name("hll").version("waiter").build();

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea sure, I can change that. I was imitating the Paginator user agent so it looked like this.

Comment on lines 56 to 77
dynamoDbClient = DynamoDbClient.builder()
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test",
"test")))
.region(Region.US_WEST_2)
.overrideConfiguration(c -> c.addExecutionInterceptor(interceptor))
.build();

dynamoDbAsyncClient = DynamoDbAsyncClient.builder()
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials
.create("test",
"test")))
.region(Region.US_WEST_2)
.overrideConfiguration(c -> c.addExecutionInterceptor(interceptor))
.build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an integration test now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, these are just the clients with the interceptor. The integration tests are not here.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like these are calling the real DynamoDB, though, not the wiremock server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I got what you mean, yea I can add the wireMock server.

@Quanzzzz Quanzzzz force-pushed the waiters-development branch 2 times, most recently from f41b9f2 to 1945470 Compare September 19, 2020 01:15
Comment on lines 79 to 91
@Test
public void syncWaiters_shouldHaveWaitersUserAgent() {
stubFor(any(urlEqualTo("/")).willReturn(aResponse().withStatus(500)));

DynamoDbWaiter waiter = dynamoDbClient.waiter();
assertThatThrownBy(() -> waiter.waitUntilTableExists(DescribeTableRequest.builder().tableName("table").build())).isNotNull();

ArgumentCaptor<Context.BeforeTransmission> context = ArgumentCaptor.forClass(Context.BeforeTransmission.class);
Mockito.verify(interceptor, times(9)).beforeTransmission(context.capture(), Matchers.any());

assertTrue(context.getValue().httpRequest().headers().get("User-Agent").toString().contains("waiter"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How long do these tests take to run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sync one takes around 7s, while the async one only takes 98ms, because the sync one does wait for the response. For the async one, the CompletableFuture is cancelled once the user agent is checked.

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 use mock clients instead? codegen-generated-classes-test seems like a good place for this test. https://github.com/aws/aws-sdk-java-v2/tree/waiters-development/test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/waiters

nit, you can just use wiremock's verify method rather than the interceptor

       verify(postRequestedFor(anyUrl()).withHeader("User-Agent", contains(...));

Copy link
Contributor

Choose a reason for hiding this comment

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

You could also throw an exception from the interceptor if you want to cancel the calls altogether and just validate the request.

Copy link
Contributor Author

@Quanzzzz Quanzzzz Sep 21, 2020

Choose a reason for hiding this comment

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

@zoewangg I just tried testing with the mock clients and Mockito.verify(), and it took around 8 mins to get the response and finish the test, not sure what caused that but it seems the WireMock test is much more efficient.

@Quanzzzz
Copy link
Contributor Author

Test updated with adding an exception in the beforeTransmission() of the interceptor. Current testing time is around 1.5s for sync and 49ms for async.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (1.8.0_252) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
Read more here

@Quanzzzz Quanzzzz merged commit 57a47d5 into aws:waiters-development Sep 22, 2020
aws-sdk-java-automation added a commit that referenced this pull request May 23, 2022
…07ad87ae0

Pull request: release <- staging/b006e8f5-1021-4408-8c65-fe607ad87ae0
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