nastra commented on code in PR #10459:
URL: https://github.com/apache/iceberg/pull/10459#discussion_r1631954848


##########
core/src/main/java/org/apache/iceberg/CatalogUtil.java:
##########
@@ -443,36 +443,42 @@ public static void configureHadoopConf(Object 
maybeConfigurable, Object conf) {
   public static MetricsReporter loadMetricsReporter(Map<String, String> 
properties) {
     String impl = properties.get(CatalogProperties.METRICS_REPORTER_IMPL);
     if (impl == null) {
+      LOG.info(
+          "Custom metrics reporter is set, but the implementation is null. 
Defaulting to LoggingMetricsReporter");
       return LoggingMetricsReporter.instance();
     }
 
     LOG.info("Loading custom MetricsReporter implementation: {}", impl);
-    DynConstructors.Ctor<MetricsReporter> ctor;
+
+    MetricsReporter reporter;
+
     try {
-      ctor =
-          DynConstructors.builder(MetricsReporter.class)
-              .loader(CatalogUtil.class.getClassLoader())
-              .impl(impl)
-              .buildChecked();
+      reporter = createMetricsReporter(impl, 
CatalogUtil.class.getClassLoader());
     } catch (NoSuchMethodException e) {
-      throw new IllegalArgumentException(
-          String.format("Cannot initialize MetricsReporter, missing no-arg 
constructor: %s", impl),
-          e);
+      try {
+        reporter = createMetricsReporter(impl, 
Thread.currentThread().getContextClassLoader());
+      } catch (NoSuchMethodException e2) {
+        throw new IllegalArgumentException(
+            String.format("Cannot initialize MetricsReporter, missing no-arg 
constructor: %s", impl), e2);
+      }
     }
 
-    MetricsReporter reporter;
+    reporter.initialize(properties);
+    return reporter;
+  }
+
+  private static MetricsReporter createMetricsReporter(String impl, 
ClassLoader loader)
+      throws NoSuchMethodException {
+    DynConstructors.Ctor<MetricsReporter> ctor =
+        
DynConstructors.builder(MetricsReporter.class).loader(loader).impl(impl).buildChecked();
     try {
-      reporter = ctor.newInstance();
+      return ctor.newInstance();
     } catch (ClassCastException e) {
       throw new IllegalArgumentException(
           String.format(
-              "Cannot initialize MetricsReporter, %s does not implement 
MetricsReporter.", impl),
+              "Cannot initialize MetricsReporter, '%s' does not implement 
MetricsReporter.", impl),

Review Comment:
   ```suggestion
                 "Cannot initialize MetricsReporter, %s does not implement 
MetricsReporter.", impl),
   ```



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to