Skip to content

Commit 54b9410

Browse files
committed
Add specific http configurations for cloudwatch and s3
1 parent 9699d19 commit 54b9410

File tree

13 files changed

+245
-13
lines changed

13 files changed

+245
-13
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "Amazon CloudWatch",
3+
"type": "bugfix",
4+
"description": "Add cloudwatch specific http configurations, specifically reducing `connectionMaxIdleTime`. Related to [#1380](https://github.com/aws/aws-sdk-java-v2/issues/1380)"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "Amazon S3",
3+
"type": "bugfix",
4+
"description": "Add s3 specific http configurations, specifically reducing `connectionMaxIdleTime`. Related to [#1122](https://github.com/aws/aws-sdk-java-v2/issues/1122)"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2010-2019 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.cloudwatch.internal;
17+
18+
import java.time.Duration;
19+
import software.amazon.awssdk.annotations.SdkInternalApi;
20+
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
21+
import software.amazon.awssdk.utils.AttributeMap;
22+
23+
/**
24+
* CloudWatch specific http configurations
25+
*/
26+
@SdkInternalApi
27+
public final class CloudWatchHttpConfigurationOptions {
28+
private static final AttributeMap OPTIONS = AttributeMap
29+
.builder()
30+
.put(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT, Duration.ofSeconds(5))
31+
.build();
32+
33+
private CloudWatchHttpConfigurationOptions() {
34+
}
35+
36+
public static AttributeMap defaultHttpConfig() {
37+
return OPTIONS;
38+
}
39+
}

services/cloudwatch/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"deleteDashboards",
1010
"putDashboard",
1111
"getDashboard"
12-
]
12+
],
13+
"serviceSpecificHttpConfig": "software.amazon.awssdk.services.cloudwatch.internal.CloudWatchHttpConfigurationOptions"
1314
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2010-2019 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.s3.internal;
17+
18+
import java.time.Duration;
19+
import software.amazon.awssdk.annotations.SdkInternalApi;
20+
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
21+
import software.amazon.awssdk.utils.AttributeMap;
22+
23+
/**
24+
* S3 specific http configurations
25+
*/
26+
@SdkInternalApi
27+
public final class S3HttpConfigurationOptions {
28+
private static final AttributeMap OPTIONS = AttributeMap
29+
.builder()
30+
.put(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT, Duration.ofSeconds(5))
31+
.build();
32+
33+
private S3HttpConfigurationOptions() {
34+
}
35+
36+
public static AttributeMap defaultHttpConfig() {
37+
return OPTIONS;
38+
}
39+
}

services/s3/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,6 @@
8585
"createMethodParams": [
8686
"clientConfiguration"
8787
]
88-
}
88+
},
89+
"serviceSpecificHttpConfig": "software.amazon.awssdk.services.s3.internal.S3HttpConfigurationOptions"
8990
}

test/stability-tests/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@
129129
<version>${awsjavasdk.version}</version>
130130
<scope>test</scope>
131131
</dependency>
132+
<dependency>
133+
<groupId>software.amazon.awssdk</groupId>
134+
<artifactId>cloudwatch</artifactId>
135+
<version>${awsjavasdk.version}</version>
136+
<scope>test</scope>
137+
</dependency>
132138
<dependency>
133139
<groupId>org.junit.jupiter</groupId>
134140
<artifactId>junit-jupiter-api</artifactId>

test/stability-tests/src/it/java/software/amazon/awssdk/stability/tests/TestRunner.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@
1616
package software.amazon.awssdk.stability.tests;
1717

1818

19+
/**
20+
* The main method will be invoked when you execute the test jar generated from
21+
* "mvn package -P test-jar"
22+
*
23+
* You can add the tests in the main method.
24+
* eg:
25+
* try {
26+
* S3AsyncStabilityTest s3AsyncStabilityTest = new S3AsyncStabilityTest();
27+
* S3AsyncStabilityTest.setup();
28+
* s3AsyncStabilityTest.putObject_getObject();
29+
* } finally {
30+
* S3AsyncStabilityTest.cleanup();
31+
* }
32+
*/
1933
public class TestRunner {
2034

2135
public static void main(String... args) {
22-
// You can add the tests you want to run here.
23-
// eg:
24-
// try {
25-
// S3AsyncStabilityTest s3AsyncStabilityTest = new S3AsyncStabilityTest();
26-
// S3AsyncStabilityTest.setup();
27-
// s3AsyncStabilityTest.putObject_getObject();
28-
// } finally {
29-
// S3AsyncStabilityTest.cleanup();
30-
// }
3136
}
3237
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2010-2019 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.stability.tests.cloudwatch;
17+
18+
19+
import java.time.Duration;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import java.util.concurrent.CompletableFuture;
23+
import java.util.function.IntFunction;
24+
import org.apache.commons.lang3.RandomUtils;
25+
import org.junit.jupiter.api.AfterAll;
26+
import org.junit.jupiter.api.BeforeAll;
27+
import software.amazon.awssdk.services.cloudwatch.model.MetricDatum;
28+
import software.amazon.awssdk.stability.tests.exceptions.StabilityTestsRetryableException;
29+
import software.amazon.awssdk.stability.tests.utils.RetryableTest;
30+
import software.amazon.awssdk.stability.tests.utils.StabilityTestRunner;
31+
32+
public class CloudWatchAsyncStabilityTest extends CloudWatchBaseStabilityTest {
33+
private static String namespace;
34+
35+
@BeforeAll
36+
public static void setup() {
37+
namespace = "CloudWatchAsyncStabilityTest" + System.currentTimeMillis();
38+
}
39+
40+
@AfterAll
41+
public static void tearDown() {
42+
cloudWatchAsyncClient.close();
43+
}
44+
45+
@RetryableTest(maxRetries = 3, retryableException = StabilityTestsRetryableException.class)
46+
public void putMetrics_lowTpsLongInterval() {
47+
List<MetricDatum> metrics = new ArrayList<>();
48+
for (int i = 0; i < 20 ; i++) {
49+
metrics.add(MetricDatum.builder()
50+
.metricName("test")
51+
.values(RandomUtils.nextDouble(1d, 1000d))
52+
.build());
53+
}
54+
55+
IntFunction<CompletableFuture<?>> futureIntFunction = i ->
56+
cloudWatchAsyncClient.putMetricData(b -> b.namespace(namespace)
57+
.metricData(metrics));
58+
59+
runCloudWatchTest("putMetrics_lowTpsLongInterval", futureIntFunction);
60+
}
61+
62+
63+
private void runCloudWatchTest(String testName, IntFunction<CompletableFuture<?>> futureIntFunction) {
64+
StabilityTestRunner.newRunner()
65+
.testName("CloudWatchAsyncStabilityTest." + testName)
66+
.futureFactory(futureIntFunction)
67+
.totalRuns(TOTAL_RUNS)
68+
.requestCountPerRun(CONCURRENCY)
69+
.delaysBetweenEachRun(Duration.ofSeconds(6))
70+
.run();
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2010-2019 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.stability.tests.cloudwatch;
17+
18+
19+
import java.time.Duration;
20+
import software.amazon.awssdk.core.retry.RetryPolicy;
21+
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
22+
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient;
23+
import software.amazon.awssdk.testutils.service.AwsTestBase;
24+
25+
public abstract class CloudWatchBaseStabilityTest extends AwsTestBase {
26+
protected static final int CONCURRENCY = 50;
27+
protected static final int TOTAL_RUNS = 3;
28+
29+
protected static CloudWatchAsyncClient cloudWatchAsyncClient =
30+
CloudWatchAsyncClient.builder()
31+
.httpClientBuilder(NettyNioAsyncHttpClient.builder().maxConcurrency(CONCURRENCY))
32+
.credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
33+
.overrideConfiguration(b -> b
34+
// Retry at test level
35+
.retryPolicy(RetryPolicy.none())
36+
.apiCallTimeout(Duration.ofMinutes(1)))
37+
.build();
38+
39+
40+
}

test/stability-tests/src/it/java/software/amazon/awssdk/stability/tests/s3/S3AsyncStabilityTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ public void largeObject_put_get_usingFile() {
6161
downloadLargeObjectToFile();
6262
}
6363

64+
@RetryableTest(maxRetries = 3, retryableException = StabilityTestsRetryableException.class)
65+
public void getBucketAcl_lowTpsLongInterval() {
66+
IntFunction<CompletableFuture<?>> future = i -> s3NettyClient.getBucketAcl(b -> b.bucket(bucketName));
67+
StabilityTestRunner.newRunner()
68+
.testName("S3AsyncStabilityTest.getBucketAcl_lowTpsLongInterval")
69+
.futureFactory(future)
70+
.requestCountPerRun(10)
71+
.totalRuns(3)
72+
.delaysBetweenEachRun(Duration.ofSeconds(6))
73+
.run();
74+
}
75+
6476
private void downloadLargeObjectToFile() {
6577
File randomTempFile = RandomTempFile.randomUncreatedFile();
6678
StabilityTestRunner.newRunner()

test/stability-tests/src/it/java/software/amazon/awssdk/stability/tests/s3/S3BaseStabilityTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222
import java.util.concurrent.CompletableFuture;
23+
import software.amazon.awssdk.core.retry.RetryPolicy;
2324
import software.amazon.awssdk.core.sync.RequestBody;
2425
import software.amazon.awssdk.http.apache.ApacheHttpClient;
2526
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
@@ -46,7 +47,9 @@ public abstract class S3BaseStabilityTest extends AwsTestBase {
4647
.httpClientBuilder(NettyNioAsyncHttpClient.builder()
4748
.maxConcurrency(CONCURRENCY))
4849
.credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
49-
.overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMinutes(10)))
50+
.overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMinutes(10))
51+
// Retry at test level
52+
.retryPolicy(RetryPolicy.none()))
5053
.build();
5154

5255

test/stability-tests/src/it/java/software/amazon/awssdk/stability/tests/utils/StabilityTestRunner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ private static CompletableFuture<?> handleException(CompletableFuture<?> future,
251251
} else if (isIOException(cause)) {
252252
exceptionCounter.addIoException();
253253
} else if (cause instanceof SdkClientException) {
254-
exceptionCounter.addClientException();
254+
if (isIOException(cause.getCause())) {
255+
exceptionCounter.addIoException();
256+
} else {
257+
exceptionCounter.addClientException();
258+
}
255259
} else {
256260
exceptionCounter.addUnknownException();
257261
}

0 commit comments

Comments
 (0)