mxm commented on code in PR #16155:
URL: https://github.com/apache/iceberg/pull/16155#discussion_r3161802810


##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/IcebergStreamWriterMetrics.java:
##########
@@ -97,4 +107,55 @@ public Counter getFlushedDataFiles() {
   public Counter getFlushedDeleteFiles() {
     return flushedDeleteFiles;
   }
+
+  @Nullable
+  Histogram dataFilesSizeHistogram() {
+    return dataFilesSizeHistogram;
+  }
+
+  @Nullable
+  Histogram deleteFilesSizeHistogram() {
+    return deleteFilesSizeHistogram;
+  }
+
+  static Histogram loadHistogramIfAvailable(
+      MetricGroup group, String name, int reservoirSize, ClassLoader 
classLoader) {
+
+    if (isFlinkDropwizardAvailable(classLoader)) {

Review Comment:
   Yes, we can could in-line the function call:
   
   ```diff
   diff --git 
a/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/IcebergStreamWriterMetrics.java
 
b/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/IcebergStreamWriterMetrics.java
   index 9e59876f04..9969e8dfc7 100644
   --- 
a/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/IcebergStreamWriterMetrics.java
   +++ 
b/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/IcebergStreamWriterMetrics.java
   @@ -118,31 +118,21 @@ public class IcebergStreamWriterMetrics {
        return deleteFilesSizeHistogram;
      }
    
   +  @SuppressWarnings("CatchBlockLogException")
      static Histogram loadHistogramIfAvailable(
          MetricGroup group, String name, int reservoirSize, ClassLoader 
classLoader) {
    
   -    if (isFlinkDropwizardAvailable(classLoader)) {
   -      return HistogramLoader.load(name, group, reservoirSize);
   -    } else {
   +    try {
   +      Class.forName(
   +          "org.apache.flink.dropwizard.metrics.DropwizardHistogramWrapper", 
false, classLoader);
   +    } catch (ClassNotFoundException e) {
          LOG.warn(
              "flink-metrics-dropwizard is not on the classpath. '{}' histogram 
metrics will be disabled. Add org.apache.flink:flink-metrics-dropwizard to 
enable them.",
              name);
          return null;
        }
   -  }
    
   -  /**
   -   * Checks whether the Dropwizard-based histogram wrapper provided through 
Flink's optional
   -   * flink-metrics-dropwizard dependency is available.
   -   */
   -  private static boolean isFlinkDropwizardAvailable(ClassLoader 
classLoader) {
   -    try {
   -      Class.forName(
   -          "org.apache.flink.dropwizard.metrics.DropwizardHistogramWrapper", 
false, classLoader);
   -      return true;
   -    } catch (ClassNotFoundException e) {
   -      return false;
   -    }
   +    return HistogramLoader.load(name, group, reservoirSize);
      }
   ```
   
   
   Do you prefer this? Note, we need the `SuppressWarnings` due to not wanting 
to spam the log with the `ClassNotFoundException`, which is expected here.



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