-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
AWS: Enable RetryMode for AWS KMS client #11420
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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 java.util.Map; | ||
import org.apache.iceberg.util.PropertyUtil; | ||
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 { | ||
|
||
/** This property is used to configure {@link RetryMode} for AWS KMS client */ | ||
public static final String KMS_RETRY_MODE = "kms.retry.mode"; | ||
|
||
public static final String KMS_RETRY_MODE_DEFAULT = "LEGACY"; | ||
|
||
private RetryMode kmsRetryMode; | ||
|
||
public KmsClientProperties() { | ||
this.kmsRetryMode = RetryMode.valueOf(KMS_RETRY_MODE_DEFAULT); | ||
} | ||
|
||
public KmsClientProperties(Map<String, String> properties) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I would add the link to AWS configBuilder configuration, especially about retry mode (to know the accepted values for retry mode). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jbonofre Thank you for your review! I linked to both |
||
this.kmsRetryMode = | ||
RetryMode.valueOf( | ||
PropertyUtil.propertyAsString(properties, KMS_RETRY_MODE, KMS_RETRY_MODE_DEFAULT)); | ||
} | ||
|
||
public RetryMode kmsRetryMode() { | ||
return kmsRetryMode; | ||
} | ||
|
||
public void setKmsRetryMode(RetryMode kmsRetryMode) { | ||
this.kmsRetryMode = kmsRetryMode; | ||
} | ||
|
||
public <T extends KmsClientBuilder> void applyRetryConfigurations(T builder) { | ||
ClientOverrideConfiguration.Builder configBuilder = | ||
null != builder.overrideConfiguration() | ||
? builder.overrideConfiguration().toBuilder() | ||
: ClientOverrideConfiguration.builder(); | ||
|
||
builder.overrideConfiguration(configBuilder.retryStrategy(kmsRetryMode).build()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 java.util.Map; | ||
import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
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() { | ||
Map<String, String> properties = Maps.newHashMap(); | ||
properties.put(KmsClientProperties.KMS_RETRY_MODE, "ADAPTIVE_V2"); | ||
KmsClientProperties kmsClientProperties = new KmsClientProperties(properties); | ||
|
||
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); | ||
} | ||
} |
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.
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.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.
@amogh-jahagirdar Thank you for your feedback.
Making
applyRetryConfigurations
as part ofAwsClientProperties
makes sense to me.