-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix loss loss of cross region bucket read config for s3 client in the v2 migration #19180
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -21,12 +21,14 @@ | |
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| public class AWSClientConfig | ||
| { | ||
| // Default values matching AWS SDK v2 defaults | ||
| private static final boolean DEFAULT_CHUNKED_ENCODING_DISABLED = false; | ||
| private static final boolean DEFAULT_PATH_STYLE_ACCESS = false; | ||
| private static final boolean DEFAULT_FORCE_GLOBAL_BUCKET_ACCESS_ENABLED = false; | ||
|
|
||
| private static final int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 10_000; | ||
| private static final int DEFAULT_SOCKET_TIMEOUT_MILLIS = 50_000; | ||
| private static final int DEFAULT_MAX_CONNECTIONS = 50; | ||
|
|
@@ -40,8 +42,17 @@ public class AWSClientConfig | |
| @JsonProperty | ||
| private boolean enablePathStyleAccess = DEFAULT_PATH_STYLE_ACCESS; | ||
|
|
||
| /** | ||
| * @deprecated Use {@link #crossRegionAccessEnabled} instead. | ||
| */ | ||
| @Deprecated | ||
| @JsonProperty | ||
| protected boolean forceGlobalBucketAccessEnabled = DEFAULT_FORCE_GLOBAL_BUCKET_ACCESS_ENABLED; | ||
| @Nullable | ||
| protected Boolean forceGlobalBucketAccessEnabled; | ||
|
|
||
| @JsonProperty | ||
| @Nullable | ||
| private Boolean crossRegionAccessEnabled; | ||
|
|
||
| @JsonProperty | ||
| private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT_MILLIS; | ||
|
|
@@ -67,11 +78,39 @@ public boolean isEnablePathStyleAccess() | |
| return enablePathStyleAccess; | ||
| } | ||
|
|
||
| public boolean isForceGlobalBucketAccessEnabled() | ||
| /** | ||
| * @deprecated Use {@link #isCrossRegionAccessEnabled()} instead. | ||
| */ | ||
| @Deprecated | ||
| @Nullable | ||
| public Boolean isForceGlobalBucketAccessEnabled() | ||
| { | ||
| return forceGlobalBucketAccessEnabled; | ||
| } | ||
|
|
||
| @Nullable | ||
| public Boolean getCrossRegionAccessEnabled() | ||
| { | ||
| return crossRegionAccessEnabled; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves cross-region access setting. Precedence: | ||
| * 1. If crossRegionAccessEnabled is explicitly set, use it. | ||
| * 2. If forceGlobalBucketAccessEnabled (deprecated) is explicitly set, use it. | ||
| * 3. Otherwise, default to false. | ||
| */ | ||
| public boolean isCrossRegionAccessEnabled() | ||
| { | ||
| if (crossRegionAccessEnabled != null) { | ||
| return crossRegionAccessEnabled; | ||
| } | ||
| if (forceGlobalBucketAccessEnabled != null) { | ||
| return forceGlobalBucketAccessEnabled; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public int getConnectionTimeoutMillis() | ||
| { | ||
| return connectionTimeout; | ||
|
|
@@ -94,7 +133,7 @@ public String toString() | |
| "protocol='" + protocol + '\'' + | ||
| ", disableChunkedEncoding=" + disableChunkedEncoding + | ||
| ", enablePathStyleAccess=" + enablePathStyleAccess + | ||
| ", forceGlobalBucketAccessEnabled=" + forceGlobalBucketAccessEnabled + | ||
|
Contributor
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. Should include |
||
| ", crossRegionAccessEnabled=" + isCrossRegionAccessEnabled() + | ||
| ", connectionTimeout=" + connectionTimeout + | ||
| ", socketTimeout=" + socketTimeout + | ||
| ", maxConnections=" + maxConnections + | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * 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.druid.common.aws; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class AWSClientConfigTest | ||
| { | ||
| private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
|
||
| @Test | ||
| public void testDefaultCrossRegionAccessEnabled() throws Exception | ||
| { | ||
| AWSClientConfig config = MAPPER.readValue("{}", AWSClientConfig.class); | ||
| Assertions.assertNull(config.isForceGlobalBucketAccessEnabled()); | ||
Check noticeCode scanning / CodeQL Deprecated method or constructor invocation Note test
Invoking
AWSClientConfig.isForceGlobalBucketAccessEnabled Error loading related location Loading |
||
| Assertions.assertFalse(config.isCrossRegionAccessEnabled()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCrossRegionAccessEnabledExplicitlySet() throws Exception | ||
| { | ||
| AWSClientConfig config = MAPPER.readValue("{\"crossRegionAccessEnabled\": true}", AWSClientConfig.class); | ||
| Assertions.assertNull(config.isForceGlobalBucketAccessEnabled()); | ||
Check noticeCode scanning / CodeQL Deprecated method or constructor invocation Note test
Invoking
AWSClientConfig.isForceGlobalBucketAccessEnabled Error loading related location Loading |
||
| Assertions.assertTrue(config.isCrossRegionAccessEnabled()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNewConfigTakesPrecedenceOverDeprecatedWhenBothSet() throws Exception | ||
| { | ||
| AWSClientConfig config = MAPPER.readValue( | ||
| "{\"forceGlobalBucketAccessEnabled\": true, \"crossRegionAccessEnabled\": false}", | ||
| AWSClientConfig.class | ||
| ); | ||
| Assertions.assertFalse(config.isCrossRegionAccessEnabled()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNewConfigTrueWinsOverDeprecatedFalse() throws Exception | ||
| { | ||
| AWSClientConfig config = MAPPER.readValue( | ||
| "{\"forceGlobalBucketAccessEnabled\": false, \"crossRegionAccessEnabled\": true}", | ||
| AWSClientConfig.class | ||
| ); | ||
| Assertions.assertTrue(config.isCrossRegionAccessEnabled()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeprecatedForceGlobalBucketAccessAloneTrue() throws Exception | ||
| { | ||
| AWSClientConfig config = MAPPER.readValue( | ||
| "{\"forceGlobalBucketAccessEnabled\": true}", | ||
| AWSClientConfig.class | ||
| ); | ||
| Assertions.assertTrue(config.isCrossRegionAccessEnabled()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeprecatedNotSetFallsThroughToCrossRegion() throws Exception | ||
| { | ||
| AWSClientConfig config = MAPPER.readValue( | ||
| "{\"crossRegionAccessEnabled\": true}", | ||
| AWSClientConfig.class | ||
| ); | ||
| Assertions.assertNull(config.isForceGlobalBucketAccessEnabled()); | ||
Check noticeCode scanning / CodeQL Deprecated method or constructor invocation Note test
Invoking
AWSClientConfig.isForceGlobalBucketAccessEnabled Error loading related location Loading |
||
| Assertions.assertTrue(config.isCrossRegionAccessEnabled()); | ||
| } | ||
| } | ||
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.
crossRegionAccessEnabled, if set, should take precedence overforceGlobalBucketAccessEnabledbecause the latter is deprecated.