-
Notifications
You must be signed in to change notification settings - Fork 914
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
Append User-Agent for Waiters operations #2039
Conversation
f78f4f4
to
0d520b0
Compare
e6f2589
to
7567d23
Compare
64c4737
to
9be7b05
Compare
@@ -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()); |
There was a problem hiding this comment.
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();
?
There was a problem hiding this comment.
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.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
f41b9f2
to
1945470
Compare
@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")); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(...));
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
b3ec6b6
to
cfe4068
Compare
Test updated with adding an exception in the |
Kudos, SonarCloud Quality Gate passed!
|
…07ad87ae0 Pull request: release <- staging/b006e8f5-1021-4408-8c65-fe607ad87ae0
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
License