Skip to content

Commit 288fd09

Browse files
committed
HADOOP-19455. S3A: SDK client to log metrics at TRACE
Switch is in client; commented out in test log properties; covered in troubleshooting doc Change-Id: If70447d8eb3d3d0e03db5c169cd1aabf844931bd
1 parent b55801f commit 288fd09

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/DefaultS3ClientFactory.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.slf4j.Logger;
3030
import org.slf4j.LoggerFactory;
3131

32+
import org.slf4j.event.Level;
3233
import software.amazon.awssdk.awscore.util.AwsHostNameUtils;
3334
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
3435
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
@@ -38,6 +39,7 @@
3839
import software.amazon.awssdk.http.auth.spi.scheme.AuthScheme;
3940
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
4041
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
42+
import software.amazon.awssdk.metrics.LoggingMetricPublisher;
4143
import software.amazon.awssdk.regions.Region;
4244
import software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin;
4345
import software.amazon.awssdk.services.s3.S3AsyncClient;
@@ -211,12 +213,20 @@ private <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, ClientT> Build
211213
final ClientOverrideConfiguration.Builder override =
212214
createClientOverrideConfiguration(parameters, conf);
213215

214-
S3BaseClientBuilder s3BaseClientBuilder = builder
216+
S3BaseClientBuilder<BuilderT, ClientT> s3BaseClientBuilder = builder
215217
.overrideConfiguration(override.build())
216218
.credentialsProvider(parameters.getCredentialSet())
217219
.disableS3ExpressSessionAuth(!parameters.isExpressCreateSession())
218220
.serviceConfiguration(serviceConfiguration);
219221

222+
if (LOG.isTraceEnabled()) {
223+
// if this log is set to debug then we turn on logging of SDK metrics.
224+
// The metrics itself will log at info; it is just that reflection work
225+
// would be needed to change that setting safely for shaded and unshaded aws artifacts.
226+
s3BaseClientBuilder.overrideConfiguration(o ->
227+
o.addMetricPublisher(LoggingMetricPublisher.create()));
228+
}
229+
220230
if (conf.getBoolean(HTTP_SIGNER_ENABLED, HTTP_SIGNER_ENABLED_DEFAULT)) {
221231
// use an http signer through an AuthScheme
222232
final AuthScheme<AwsCredentialsIdentity> signer =

hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/troubleshooting_s3a.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,48 @@ execchain.MainClientExec (MainClientExec.java:execute(284)) - Connection can be
13591359
13601360
```
13611361

1362+
1363+
To log the output of the AWS SDK metrics, set the log
1364+
`org.apache.hadoop.fs.s3a.DefaultS3ClientFactory` to `TRACE`.
1365+
This will then turn on logging of the internal SDK metrics.4
1366+
1367+
These will actually be logged at INFO in the log
1368+
```
1369+
software.amazon.awssdk.metrics.LoggingMetricPublisher
1370+
```
1371+
1372+
```text
1373+
INFO metrics.LoggingMetricPublisher (LoggerAdapter.java:info(165)) - Metrics published:
1374+
MetricCollection(name=ApiCall, metrics=[
1375+
MetricRecord(metric=MarshallingDuration, value=PT0.000092041S),
1376+
MetricRecord(metric=RetryCount, value=0),
1377+
MetricRecord(metric=ApiCallSuccessful, value=true),
1378+
MetricRecord(metric=OperationName, value=DeleteObject),
1379+
MetricRecord(metric=EndpointResolveDuration, value=PT0.000132792S),
1380+
MetricRecord(metric=ApiCallDuration, value=PT0.064890875S),
1381+
MetricRecord(metric=CredentialsFetchDuration, value=PT0.000017458S),
1382+
MetricRecord(metric=ServiceEndpoint, value=https://buckets3.eu-west-2.amazonaws.com),
1383+
MetricRecord(metric=ServiceId, value=S3)], children=[
1384+
MetricCollection(name=ApiCallAttempt, metrics=[
1385+
MetricRecord(metric=TimeToFirstByte, value=PT0.06260225S),
1386+
MetricRecord(metric=SigningDuration, value=PT0.000293083S),
1387+
MetricRecord(metric=ReadThroughput, value=0.0),
1388+
MetricRecord(metric=ServiceCallDuration, value=PT0.06260225S),
1389+
MetricRecord(metric=HttpStatusCode, value=204),
1390+
MetricRecord(metric=BackoffDelayDuration, value=PT0S),
1391+
MetricRecord(metric=TimeToLastByte, value=PT0.064313667S),
1392+
MetricRecord(metric=AwsRequestId, value=RKZD44SE5DW91K1G)], children=[
1393+
MetricCollection(name=HttpClient, metrics=[
1394+
MetricRecord(metric=AvailableConcurrency, value=1),
1395+
MetricRecord(metric=LeasedConcurrency, value=0),
1396+
MetricRecord(metric=ConcurrencyAcquireDuration, value=PT0S),
1397+
MetricRecord(metric=PendingConcurrencyAcquires, value=0),
1398+
MetricRecord(metric=MaxConcurrency, value=512),
1399+
MetricRecord(metric=HttpClientName, value=Apache)], children=[])
1400+
])
1401+
])
1402+
```
1403+
13621404
### <a name="audit-logging"></a> Enable S3 Server-side Logging
13631405

13641406
The [Auditing](auditing) feature of the S3A connector can be used to generate

hadoop-tools/hadoop-aws/src/test/resources/log4j.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ log4j.logger.org.apache.hadoop.fs.s3a.S3AStorageStatistics=INFO
102102
# services it launches itself.
103103
# log4.logger.org.apache.hadoop.service=DEBUG
104104

105+
# log this at trace to trigger enabling the
106+
# log4j.logger.org.apache.hadoop.fs.s3a.DefaultS3ClientFactory=TRACE
107+

0 commit comments

Comments
 (0)