Skip to content

Commit

Permalink
feat(backup/s3): use sensible configuration defaults for client
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaschoenburg committed Oct 4, 2022
1 parent 5459c0a commit 0284d98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backup-stores/s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>auth</artifactId>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.awscore.defaultsmode.DefaultsMode;
import software.amazon.awssdk.core.async.AsyncRequestBody;
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
import software.amazon.awssdk.core.async.SdkPublisher;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.s3.model.NoSuchKeyException;
Expand Down Expand Up @@ -429,6 +432,19 @@ private CompletableFuture<PutObjectResponse> saveNamedFile(

public static S3AsyncClient buildClient(final S3BackupConfig config) {
final var builder = S3AsyncClient.builder();

// Enable auto-tuning of various parameters based on the environment
builder.defaultsMode(DefaultsMode.AUTO);

builder.httpClient(
NettyNioAsyncHttpClient.builder()
// We'd rather wait longer for a connection than have a failed backup. This helps in
// smoothing out spikes when taking a backup.
// Default is 10s: `SdkHttpConfigurationOption.DEFAULT_CONNECTION_ACQUIRE_TIMEOUT`.
.connectionAcquisitionTimeout(Duration.ofSeconds(45))
.build());

builder.overrideConfiguration(cfg -> cfg.retryPolicy(RetryMode.ADAPTIVE));
config.endpoint().ifPresent(endpoint -> builder.endpointOverride(URI.create(endpoint)));
config.region().ifPresent(region -> builder.region(Region.of(region)));
config
Expand Down

0 comments on commit 0284d98

Please sign in to comment.