rdblue commented on a change in pull request #4050:
URL: https://github.com/apache/iceberg/pull/4050#discussion_r806028824



##########
File path: aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java
##########
@@ -104,8 +112,23 @@ private S3Client client() {
   @Override
   public void initialize(Map<String, String> properties) {
     this.awsProperties = new AwsProperties(properties);
-    this.awsClientFactory = AwsClientFactories.from(properties);
-    this.s3 = awsClientFactory::s3;
+
+    // Do not override s3 client if it was provided
+    if (s3 == null) {
+      this.s3 = AwsClientFactories.from(properties)::s3;
+    }
+
+    // Report Hadoop metrics if Hadoop is available
+    try {
+      Class<? extends MetricsContext> clazz = 
DynClasses.builder().impl(DEFAULT_METRICS_IMPL).buildChecked();
+
+      this.metrics = clazz.getDeclaredConstructor().newInstance();
+      metrics.initialize(ImmutableMap.of("fileio.scheme", "s3"));
+    } catch (ClassNotFoundException e) {

Review comment:
       I'd recommend using `DynConstructors` rather than `DynClasses` because 
`DynConstructors` will catch and handle `NoClassDefFoundError` as well as 
`ClassNotFoundException` and will always throw `ClassNotFoundException`. That 
handles cases where dependencies of the class aren't found, like when Hadoop is 
missing.
   
   Otherwise, this may leak the `NoClassDefFoundError` and fail when Hadoop is 
missing.
   
   I'd also update the error message here to `Unable to load metrics class`. 
And since this is a warning, consider suppressing the exception because we 
expect it. Exception traces that are expected tend to confuse people looking at 
logs.




-- 
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]

Reply via email to