Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Map;
import java.util.UUID;
import org.apache.iceberg.aws.kms.KmsClientProperties;
import org.apache.iceberg.aws.s3.S3FileIOProperties;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
Expand All @@ -38,6 +39,7 @@ public class AssumeRoleAwsClientFactory implements AwsClientFactory {
private HttpClientProperties httpClientProperties;
private S3FileIOProperties s3FileIOProperties;
private String roleSessionName;
private KmsClientProperties kmsClientProperties;

@Override
public S3Client s3() {
Expand All @@ -64,6 +66,7 @@ public KmsClient kms() {
return KmsClient.builder()
.applyMutation(this::applyAssumeRoleConfigurations)
.applyMutation(httpClientProperties::applyHttpClientConfigurations)
.applyMutation(kmsClientProperties::applyRetryConfigurations)
.build();
}

Expand All @@ -81,6 +84,7 @@ public void initialize(Map<String, String> properties) {
this.awsProperties = new AwsProperties(properties);
this.s3FileIOProperties = new S3FileIOProperties(properties);
this.httpClientProperties = new HttpClientProperties(properties);
this.kmsClientProperties = new KmsClientProperties();
this.roleSessionName = genSessionName();
Preconditions.checkNotNull(
awsProperties.clientAssumeRoleArn(),
Expand Down Expand Up @@ -126,6 +130,10 @@ protected S3FileIOProperties s3FileIOProperties() {
return s3FileIOProperties;
}

protected KmsClientProperties kmsClientProperties() {
return kmsClientProperties;
}

private StsClient sts() {
return StsClient.builder()
.applyMutation(httpClientProperties::applyHttpClientConfigurations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.net.URI;
import java.util.Map;
import org.apache.iceberg.aws.kms.KmsClientProperties;
import org.apache.iceberg.aws.s3.S3FileIOProperties;
import org.apache.iceberg.common.DynConstructors;
import org.apache.iceberg.relocated.com.google.common.base.Strings;
Expand Down Expand Up @@ -94,12 +95,14 @@ static class DefaultAwsClientFactory implements AwsClientFactory {
private AwsClientProperties awsClientProperties;
private S3FileIOProperties s3FileIOProperties;
private HttpClientProperties httpClientProperties;
private KmsClientProperties kmsClientProperties;

DefaultAwsClientFactory() {
awsProperties = new AwsProperties();
awsClientProperties = new AwsClientProperties();
s3FileIOProperties = new S3FileIOProperties();
httpClientProperties = new HttpClientProperties();
kmsClientProperties = new KmsClientProperties();
}

@Override
Expand Down Expand Up @@ -134,6 +137,7 @@ public KmsClient kms() {
.applyMutation(awsClientProperties::applyClientRegionConfiguration)
.applyMutation(httpClientProperties::applyHttpClientConfigurations)
.applyMutation(awsClientProperties::applyClientCredentialConfigurations)
.applyMutation(kmsClientProperties::applyRetryConfigurations)
.build();
}

Expand All @@ -153,6 +157,7 @@ public void initialize(Map<String, String> properties) {
this.awsClientProperties = new AwsClientProperties(properties);
this.s3FileIOProperties = new S3FileIOProperties(properties);
this.httpClientProperties = new HttpClientProperties(properties);
this.kmsClientProperties = new KmsClientProperties();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.iceberg.aws.kms;

import java.io.Serializable;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.services.kms.KmsClientBuilder;

public class KmsClientProperties implements Serializable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need this class considering there's no separate properties we're introducing for KMS and the fact that it may make sense to also apply ADAPTIVE_V2 for Glue client as well (not needed in this PR, but down the line we could just use that)? Just don't want to avoid public properties classes until they're really necessary

I think an applyRetryConfigurations in the existing AwsClientProperties also would work well since that class is meant for generalizing across the different AWS clients.

@hsiang-c hsiang-c Dec 2, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@amogh-jahagirdar Thank you for your feedback.

Making applyRetryConfigurations as part of AwsClientProperties makes sense to me.

public KmsClientProperties() {}

/**
* Set ADAPTIVE_V2 <a
* href="https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/core/retry/RetryMode.html">RetryMode</a>
* for a KMS client.
*
* <p>For more details, see
* https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/core/client/config/ClientOverrideConfiguration.Builder.html#retryStrategy(software.amazon.awssdk.core.retry.RetryMode)
*/
public <T extends KmsClientBuilder> void applyRetryConfigurations(T builder) {
ClientOverrideConfiguration.Builder configBuilder =
null != builder.overrideConfiguration()
? builder.overrideConfiguration().toBuilder()
: ClientOverrideConfiguration.builder();

builder.overrideConfiguration(configBuilder.retryStrategy(RetryMode.ADAPTIVE_V2).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public KmsClient kms() {
if (isTableRegisteredWithLakeFormation()) {
return KmsClient.builder()
.applyMutation(httpClientProperties()::applyHttpClientConfigurations)
.applyMutation(kmsClientProperties()::applyRetryConfigurations)
.credentialsProvider(
new LakeFormationCredentialsProvider(lakeFormation(), buildTableArn()))
.region(Region.of(region()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.iceberg.aws.kms;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.services.kms.KmsClient;
import software.amazon.awssdk.services.kms.KmsClientBuilder;

public class TestKmsClientProperties {
@Test
public void testApplyRetryConfiguration() {
KmsClientProperties kmsClientProperties = new KmsClientProperties();

KmsClientBuilder builder = KmsClient.builder();
kmsClientProperties.applyRetryConfigurations(builder);

RetryMode retryPolicy = builder.overrideConfiguration().retryMode().get();
assertThat(retryPolicy).as("retry mode was not set").isEqualTo(RetryMode.ADAPTIVE_V2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Could we clean up this error message to be "Retry mode should be ADAPTIVE_V2"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry I missed this one.

}
}