Skip to content

Commit 0e016da

Browse files
committed
Add amz-sdk-request header, removed amz-sdk-retry header.
Most changes are from a rename of MockHttpClient to MockSyncHttpClient so that a common parent interface can be added for generic programming purposes. The new amz-sdk-request header does not include the TTL, because it's not at all easy to calculate with pluggable HTTP clients and the specification lists it as optional. The TTL can be added when service teams ask for it.
1 parent 7c369d9 commit 0e016da

File tree

16 files changed

+496
-302
lines changed

16 files changed

+496
-302
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Added amz-sdk-request and removed amz-sdk-retry header. The new header matches the behavior of the other SDKs."
6+
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/utils/RetryableStageHelper.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
package software.amazon.awssdk.core.internal.http.pipeline.stages.utils;
1717

18-
import static software.amazon.awssdk.core.internal.retry.SdkDefaultRetrySetting.SDK_RETRY_INFO_HEADER;
19-
2018
import java.time.Duration;
2119
import java.util.concurrent.CompletionException;
2220
import software.amazon.awssdk.annotations.SdkInternalApi;
@@ -37,7 +35,6 @@
3735
import software.amazon.awssdk.core.retry.RetryPolicy;
3836
import software.amazon.awssdk.core.retry.RetryPolicyContext;
3937
import software.amazon.awssdk.core.retry.RetryUtils;
40-
import software.amazon.awssdk.core.retry.conditions.TokenBucketRetryCondition;
4138
import software.amazon.awssdk.http.SdkHttpFullRequest;
4239
import software.amazon.awssdk.http.SdkHttpResponse;
4340

@@ -47,6 +44,8 @@
4744
*/
4845
@SdkInternalApi
4946
public class RetryableStageHelper {
47+
public static final String SDK_RETRY_INFO_HEADER = "amz-sdk-request";
48+
5049
public static final ExecutionAttribute<Duration> LAST_BACKOFF_DELAY_DURATION =
5150
new ExecutionAttribute<>("LastBackoffDuration");
5251

@@ -140,14 +139,8 @@ public void logBackingOff(Duration backoffDelay) {
140139
* Retrieve the request to send to the service, including any detailed retry information headers.
141140
*/
142141
public SdkHttpFullRequest requestToSend() {
143-
Integer availableRetryCapacity = TokenBucketRetryCondition.getCapacityForExecution(context.executionAttributes())
144-
.map(TokenBucketRetryCondition.Capacity::capacityRemaining)
145-
.orElse(null);
146-
String headerValue = (attemptNumber - 1) + "/" +
147-
context.executionAttributes().getAttribute(LAST_BACKOFF_DELAY_DURATION).toMillis() + "/" +
148-
(availableRetryCapacity != null ? availableRetryCapacity : "");
149142
return request.toBuilder()
150-
.putHeader(SDK_RETRY_INFO_HEADER, headerValue)
143+
.putHeader(SDK_RETRY_INFO_HEADER, "attempt=" + attemptNumber + "; max=" + retryPolicy.numRetries())
151144
.build();
152145
}
153146

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/retry/SdkDefaultRetrySetting.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
@SdkInternalApi
3434
public final class SdkDefaultRetrySetting {
35-
public static final String SDK_RETRY_INFO_HEADER = "amz-sdk-retry";
36-
3735
public static final class Legacy {
3836
private static final int THROTTLE_EXCEPTION_TOKEN_COST = 0;
3937
private static final int DEFAULT_EXCEPTION_TOKEN_COST = 5;

core/sdk-core/src/main/java/software/amazon/awssdk/core/retry/conditions/TokenBucketRetryCondition.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import software.amazon.awssdk.core.retry.RetryMode;
2727
import software.amazon.awssdk.core.retry.RetryPolicy;
2828
import software.amazon.awssdk.core.retry.RetryPolicyContext;
29+
import software.amazon.awssdk.utils.Logger;
2930
import software.amazon.awssdk.utils.ToString;
3031
import software.amazon.awssdk.utils.Validate;
3132

@@ -47,6 +48,8 @@
4748
*/
4849
@SdkPublicApi
4950
public class TokenBucketRetryCondition implements RetryCondition {
51+
private static final Logger log = Logger.loggerFor(TokenBucketRetryCondition.class);
52+
5053
private static final ExecutionAttribute<Capacity> LAST_ACQUIRED_CAPACITY =
5154
new ExecutionAttribute<>("TokenBucketRetryCondition.LAST_ACQUIRED_CAPACITY");
5255

@@ -122,9 +125,17 @@ public boolean shouldRetry(RetryPolicyContext context) {
122125
context.executionAttributes().putAttribute(LAST_ACQUIRED_CAPACITY, c);
123126
context.executionAttributes().putAttribute(RETRY_COUNT_OF_LAST_CAPACITY_ACQUISITION,
124127
context.retriesAttempted());
128+
log.trace(() -> "Successfully acquired token bucket capacity to retry this request. "
129+
+ "Acquired: " + c.capacityAcquired + ". Remaining: " + c.capacityRemaining);
125130
});
126131

127-
return capacity.isPresent();
132+
boolean hasCapacity = capacity.isPresent();
133+
134+
if (!hasCapacity) {
135+
log.debug(() -> "This request will not be retried because the client has experienced too many recent call failures.");
136+
}
137+
138+
return hasCapacity;
128139
}
129140

130141
@Override

core/sdk-core/src/test/java/software/amazon/awssdk/core/http/RetryCountInUserAgentTest.java

Lines changed: 0 additions & 101 deletions
This file was deleted.

services/s3/src/test/java/software/amazon/awssdk/services/s3/S3EndpointResolutionTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@
3434
import software.amazon.awssdk.http.SdkHttpRequest;
3535
import software.amazon.awssdk.profiles.ProfileFile;
3636
import software.amazon.awssdk.regions.Region;
37-
import software.amazon.awssdk.services.s3.S3Client;
38-
import software.amazon.awssdk.services.s3.S3ClientBuilder;
39-
import software.amazon.awssdk.services.s3.S3Configuration;
4037
import software.amazon.awssdk.services.s3.internal.handlers.EndpointAddressInterceptor;
4138
import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
4239
import software.amazon.awssdk.testutils.EnvironmentVariableHelper;
43-
import software.amazon.awssdk.testutils.service.http.MockHttpClient;
40+
import software.amazon.awssdk.testutils.service.http.MockSyncHttpClient;
4441
import software.amazon.awssdk.utils.StringInputStream;
4542

4643
/**
@@ -53,12 +50,12 @@ public class S3EndpointResolutionTest {
5350
private static final String ENDPOINT_WITHOUT_BUCKET = "https://s3.ap-south-1.amazonaws.com";
5451
private static final String ENDPOINT_WITH_BUCKET = String.format("https://%s.s3.ap-south-1.amazonaws.com", BUCKET);
5552

56-
private MockHttpClient mockHttpClient;
53+
private MockSyncHttpClient mockHttpClient;
5754
private Signer mockSigner;
5855

5956
@Before
6057
public void setup() {
61-
mockHttpClient = new MockHttpClient();
58+
mockHttpClient = new MockSyncHttpClient();
6259
mockSigner = (request, executionAttributes) -> request;
6360
}
6461

services/s3/src/test/java/software/amazon/awssdk/services/s3/bucketaddressingsep/VirtualHostAddressingSepTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
import software.amazon.awssdk.regions.Region;
3636
import software.amazon.awssdk.services.s3.S3Client;
3737
import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
38-
import software.amazon.awssdk.testutils.service.http.MockHttpClient;
38+
import software.amazon.awssdk.testutils.service.http.MockSyncHttpClient;
3939

4040
@RunWith(Parameterized.class)
4141
public class VirtualHostAddressingSepTest {
4242
private static final String TEST_FILE_PATH = "VirtualAddressingSepTestCases.json";
43-
private MockHttpClient mockHttpClient;
43+
private MockSyncHttpClient mockHttpClient;
4444
private TestCaseModel testCaseModel;
4545

4646
public VirtualHostAddressingSepTest(TestCaseModel testCaseModel) {
@@ -49,7 +49,7 @@ public VirtualHostAddressingSepTest(TestCaseModel testCaseModel) {
4949

5050
@Before
5151
public void setup() {
52-
mockHttpClient = new MockHttpClient();
52+
mockHttpClient = new MockSyncHttpClient();
5353
}
5454

5555
@Parameterized.Parameters

services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/resource/OutpostAccessPointArnEndpointResolutionTest.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,33 @@
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
2020
import static org.assertj.core.api.Assertions.assertThatThrownBy;
21-
import static software.amazon.awssdk.services.s3.S3MockUtils.mockListBucketsResponse;
2221
import static software.amazon.awssdk.services.s3.S3MockUtils.mockListObjectsResponse;
2322

24-
import java.io.UnsupportedEncodingException;
2523
import java.net.URI;
2624
import org.junit.Before;
2725
import org.junit.Test;
2826
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
2927
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
30-
import software.amazon.awssdk.core.SdkSystemSetting;
31-
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
32-
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
3328
import software.amazon.awssdk.core.signer.Signer;
3429
import software.amazon.awssdk.http.SdkHttpRequest;
35-
import software.amazon.awssdk.profiles.ProfileFile;
3630
import software.amazon.awssdk.regions.Region;
3731
import software.amazon.awssdk.services.s3.S3Client;
3832
import software.amazon.awssdk.services.s3.S3ClientBuilder;
3933
import software.amazon.awssdk.services.s3.S3Configuration;
40-
import software.amazon.awssdk.services.s3.internal.handlers.EndpointAddressInterceptor;
4134
import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
42-
import software.amazon.awssdk.testutils.EnvironmentVariableHelper;
43-
import software.amazon.awssdk.testutils.service.http.MockHttpClient;
44-
import software.amazon.awssdk.utils.StringInputStream;
35+
import software.amazon.awssdk.testutils.service.http.MockSyncHttpClient;
4536

4637
/**
4738
* Functional tests for outpost access point ARN
4839
*/
4940
public class OutpostAccessPointArnEndpointResolutionTest {
5041

51-
private MockHttpClient mockHttpClient;
42+
private MockSyncHttpClient mockHttpClient;
5243
private Signer mockSigner;
5344

5445
@Before
5546
public void setup() {
56-
mockHttpClient = new MockHttpClient();
47+
mockHttpClient = new MockSyncHttpClient();
5748
mockSigner = (request, executionAttributes) -> request;
5849
}
5950

test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/HostPrefixTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@
3030
import software.amazon.awssdk.regions.Region;
3131
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient;
3232
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient;
33-
import software.amazon.awssdk.testutils.service.http.MockAyncHttpClient;
34-
import software.amazon.awssdk.testutils.service.http.MockHttpClient;
33+
import software.amazon.awssdk.testutils.service.http.MockAsyncHttpClient;
34+
import software.amazon.awssdk.testutils.service.http.MockSyncHttpClient;
3535
import software.amazon.awssdk.utils.StringInputStream;
3636
import software.amazon.awssdk.utils.builder.SdkBuilder;
3737

3838
public class HostPrefixTest {
3939

40-
private MockHttpClient mockHttpClient;
40+
private MockSyncHttpClient mockHttpClient;
4141
private ProtocolRestJsonClient client;
42-
private MockAyncHttpClient mockAsyncClient;
42+
private MockAsyncHttpClient mockAsyncClient;
4343

4444
private ProtocolRestJsonAsyncClient asyncClient;
4545

4646
@Before
4747
public void setupClient() {
48-
mockHttpClient = new MockHttpClient();
49-
mockAsyncClient = new MockAyncHttpClient();
48+
mockHttpClient = new MockSyncHttpClient();
49+
mockAsyncClient = new MockAsyncHttpClient();
5050
client = ProtocolRestJsonClient.builder()
5151
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid",
5252
"skid")))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.retry;
17+
18+
import java.net.URI;
19+
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
20+
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
21+
import software.amazon.awssdk.regions.Region;
22+
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient;
23+
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient;
24+
import software.amazon.awssdk.testutils.service.http.MockAsyncHttpClient;
25+
import software.amazon.awssdk.testutils.service.http.MockSyncHttpClient;
26+
27+
public class AsyncRetryHeaderTest extends RetryHeaderTestSuite<MockAsyncHttpClient> {
28+
private final ProtocolRestJsonAsyncClient client;
29+
30+
public AsyncRetryHeaderTest() {
31+
super(new MockAsyncHttpClient());
32+
client = ProtocolRestJsonAsyncClient.builder()
33+
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid")))
34+
.region(Region.US_EAST_1)
35+
.endpointOverride(URI.create("http://localhost"))
36+
.httpClient(mockHttpClient)
37+
.build();
38+
}
39+
40+
@Override
41+
protected void callAllTypesOperation() {
42+
client.allTypes().join();
43+
}
44+
}

0 commit comments

Comments
 (0)