steveloughran commented on code in PR #8417:
URL: https://github.com/apache/hadoop/pull/8417#discussion_r4684660157
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/AWSClientConfig.java:
##########
@@ -429,32 +460,44 @@ private static void initSigner(Configuration conf,
private static void initRequestHeaders(Configuration conf,
ClientOverrideConfiguration.Builder clientConfig, String
awsServiceIdentifier) {
String configKey = null;
+ String configKeyPrefix = null;
switch (awsServiceIdentifier) {
case AWS_SERVICE_IDENTIFIER_S3:
configKey = CUSTOM_HEADERS_S3;
+ configKeyPrefix = CUSTOM_REQUEST_HEADERS_S3_PREFIX;
break;
case AWS_SERVICE_IDENTIFIER_STS:
configKey = CUSTOM_HEADERS_STS;
+ configKeyPrefix = CUSTOM_REQUEST_HEADERS_STS_PREFIX;
break;
default:
// No known service.
}
if (configKey != null) {
- Map<String, String> awsClientCustomHeadersMap =
- S3AUtils.getTrimmedStringCollectionSplitByEquals(conf,
configKey);
- awsClientCustomHeadersMap.forEach((header, valueString) -> {
- List<String> headerValues = Arrays.stream(valueString.split(";"))
- .map(String::trim)
- .filter(v -> !v.isEmpty())
- .collect(Collectors.toList());
- if (!headerValues.isEmpty()) {
- clientConfig.putHeader(header, headerValues);
- } else {
- LOG.warn("Ignoring header '{}' for {} client because no values were
provided",
- header, awsServiceIdentifier);
- }
- });
+ // headers for all requests are provided via clientConfig.putHeader
+ applyHeaders(conf, configKey, clientConfig::putHeader,
+ (header) -> LOG.warn("Ignoring header '{}' for {} client because
no values were provided",
+ header, awsServiceIdentifier));
LOG.debug("headers for {} client = {}", awsServiceIdentifier,
clientConfig.headers());
+
+ // per-request headers are provided via AddRequestHeaderInterceptor
+ String keyPrefix = configKeyPrefix;
+ Map<String, Map<String, List<String>>> requestHeaders = new HashMap<>();
+ Map<String, String> requestHeaderConfs =
conf.getPropsWithPrefix(keyPrefix);
+ requestHeaderConfs.keySet().forEach((request) ->
+ applyHeaders(conf, keyPrefix + request,
+ (header, headerValues) ->
+ requestHeaders.computeIfAbsent(request, c -> new
HashMap<>()).put(header, headerValues),
+ (header) -> LOG.warn("Ignoring {} request header '{}'
for {} client because " +
Review Comment:
again, risk of noise
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/AddRequestHeaderInterceptor.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.hadoop.fs.s3a.impl;
+
+import software.amazon.awssdk.awscore.AwsRequest;
+import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
+import software.amazon.awssdk.core.SdkRequest;
+import software.amazon.awssdk.core.interceptor.Context;
+import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
+import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
+
+import java.util.HashMap;
Review Comment:
nit, put the first block in the imports
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/AWSClientConfig.java:
##########
@@ -429,32 +460,44 @@ private static void initSigner(Configuration conf,
private static void initRequestHeaders(Configuration conf,
ClientOverrideConfiguration.Builder clientConfig, String
awsServiceIdentifier) {
String configKey = null;
+ String configKeyPrefix = null;
switch (awsServiceIdentifier) {
case AWS_SERVICE_IDENTIFIER_S3:
configKey = CUSTOM_HEADERS_S3;
+ configKeyPrefix = CUSTOM_REQUEST_HEADERS_S3_PREFIX;
break;
case AWS_SERVICE_IDENTIFIER_STS:
configKey = CUSTOM_HEADERS_STS;
+ configKeyPrefix = CUSTOM_REQUEST_HEADERS_STS_PREFIX;
break;
default:
// No known service.
}
if (configKey != null) {
- Map<String, String> awsClientCustomHeadersMap =
- S3AUtils.getTrimmedStringCollectionSplitByEquals(conf,
configKey);
- awsClientCustomHeadersMap.forEach((header, valueString) -> {
- List<String> headerValues = Arrays.stream(valueString.split(";"))
- .map(String::trim)
- .filter(v -> !v.isEmpty())
- .collect(Collectors.toList());
- if (!headerValues.isEmpty()) {
- clientConfig.putHeader(header, headerValues);
- } else {
- LOG.warn("Ignoring header '{}' for {} client because no values were
provided",
- header, awsServiceIdentifier);
- }
- });
+ // headers for all requests are provided via clientConfig.putHeader
+ applyHeaders(conf, configKey, clientConfig::putHeader,
Review Comment:
this will get noisy fast in production. we have LogExactlyOnce to log once
then STFU to keep log files under control
##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/impl/TestAwsClientConfig.java:
##########
@@ -30,6 +32,15 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.AbstractHadoopTestBase;
import org.apache.hadoop.util.Lists;
+import software.amazon.awssdk.core.SdkRequest;
Review Comment:
nit: put in the block above the org.apache one
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]