rdblue commented on code in PR #7014:
URL: https://github.com/apache/iceberg/pull/7014#discussion_r1126775799


##########
core/src/main/java/org/apache/iceberg/CatalogUtil.java:
##########
@@ -407,36 +408,38 @@ public static void configureHadoopConf(Object 
maybeConfigurable, Object conf) {
    *
    * <p>The implementation must have a no-arg constructor.
    *
-   * @param impl full class name of a custom {@link MetricsReporter} 
implementation
+   * @param properties catalog properties which contains class name of a 
custom {@link
+   *     MetricsReporter} implementation
    * @return An initialized {@link MetricsReporter}.
-   * @throws IllegalArgumentException if class path not found or right 
constructor not found or the
-   *     loaded class cannot be cast to the given interface type
    */
-  public static MetricsReporter loadMetricsReporter(String impl) {
+  public static MetricsReporter loadMetricsReporter(Map<String, String> 
properties) {
+    String impl = properties.get(CatalogProperties.METRICS_REPORTER_IMPL);
+    if (impl == null || impl.isEmpty()) {
+      return LoggingMetricsReporter.instance();
+    }
     LOG.info("Loading custom MetricsReporter implementation: {}", impl);
     DynConstructors.Ctor<MetricsReporter> ctor;
+    MetricsReporter reporter = null;
     try {
       ctor =
           DynConstructors.builder(MetricsReporter.class)
               .loader(CatalogUtil.class.getClassLoader())
               .impl(impl)
               .buildChecked();
+      reporter = ctor.newInstance();
     } catch (NoSuchMethodException e) {
-      throw new IllegalArgumentException(
-          String.format("Cannot initialize MetricsReporter, missing no-arg 
constructor: %s", impl),
+      LOG.warn(
+          "Cannot initialize MetricsReporter, missing no-arg constructor: {}, 
fall back to default LoggingMetricsReporter",
+          impl,
           e);
-    }
-
-    MetricsReporter reporter;
-    try {
-      reporter = ctor.newInstance();
     } catch (ClassCastException e) {
-      throw new IllegalArgumentException(
-          String.format(
-              "Cannot initialize MetricsReporter, %s does not implement 
MetricsReporter.", impl),
+      LOG.warn(
+          "Cannot initialize MetricsReporter, {} does not implement 
MetricsReporter, fall back to default LoggingMetricsReporter",
+          impl,
           e);
     }
-
+    reporter = reporter == null ? LoggingMetricsReporter.instance() : reporter;
+    reporter.initialize(properties);

Review Comment:
   There should be an empty line after this to separate it from the return 
statement.



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