szehon-ho commented on a change in pull request #3001:
URL: https://github.com/apache/iceberg/pull/3001#discussion_r694413759



##########
File path: flink/src/main/java/org/apache/iceberg/flink/sink/CommitStats.java
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.flink.sink;
+
+import java.util.Arrays;
+import java.util.NavigableMap;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.iceberg.io.WriteResult;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+
+class CommitStats {
+
+  private final AtomicLong dataFilesCount = new AtomicLong();
+  private final AtomicLong dataFilesRecordCount = new AtomicLong();
+  private final AtomicLong dataFilesByteCount = new AtomicLong();
+  private final AtomicLong deleteFilesCount = new AtomicLong();
+  private final AtomicLong deleteFilesRecordCount = new AtomicLong();
+  private final AtomicLong deleteFilesByteCount = new AtomicLong();
+
+  CommitStats(NavigableMap<Long, WriteResult> pendingResults) {
+    pendingResults.values().forEach(writeResult -> {
+      dataFilesCount.addAndGet(writeResult.dataFiles().length);
+      Arrays.stream(writeResult.dataFiles()).forEach(dataFile -> {
+        dataFilesRecordCount.addAndGet(dataFile.recordCount());
+        dataFilesByteCount.addAndGet(dataFile.fileSizeInBytes());
+      });
+      deleteFilesCount.addAndGet(writeResult.deleteFiles().length);
+      Arrays.stream(writeResult.deleteFiles()).forEach(deleteFile -> {
+        deleteFilesRecordCount.addAndGet(deleteFile.recordCount());
+        deleteFilesByteCount.addAndGet(deleteFile.fileSizeInBytes());
+      });
+    });
+  }
+
+  long dataFilesCount() {
+    return dataFilesCount.get();
+  }
+
+  long dataFilesRecordCount() {
+    return dataFilesRecordCount.get();
+  }
+
+  long dataFilesByteCount() {
+    return dataFilesByteCount.get();
+  }
+
+  long deleteFilesCount() {
+    return deleteFilesCount.get();
+  }
+
+  long deleteFilesRecordCount() {
+    return deleteFilesRecordCount.get();
+  }
+
+  long deleteFilesByteCount() {
+    return deleteFilesByteCount.get();
+  }
+
+  @Override
+  public String toString() {
+    return MoreObjects.toStringHelper(this)
+        .add("dataFilesCount", dataFilesCount.get())
+        .add("dataFilesRecordCount", dataFilesRecordCount.get())
+        .add("dataFilesByteCount", dataFilesByteCount.get())
+        .add("deleteFilesCount", deleteFilesCount.get())
+        .add("deleteFilesRecordCount", deleteFilesRecordCount.get())
+        .add("deleteFilesByteCount", deleteFilesByteCount)

Review comment:
       Missed a get?

##########
File path: flink/src/main/java/org/apache/iceberg/flink/sink/FlinkSink.java
##########
@@ -249,6 +251,19 @@ public Builder uidPrefix(String newPrefix) {
       return this;
     }
 
+    /**
+     * Set the {@link SlidingWindowReservoir} size (number of measurements 
stored)
+     * for the two histogram metrics of data files and delete file size 
distribution.
+     *
+     * @param newReservoirSize
+     * default is 128, which  only add a small memory overhead of 1 KB (128 x 
8B) per histogram. For large
+     * use cases with a lot of files, a larger reservoir size can produce more 
accurate histogram distribution.
+     */
+    public Builder fileSizeHistogramReservoirSize(int newReservoirSize) {
+      this.fileSizeHistogramReservoirSize = newReservoirSize;

Review comment:
       Should we add Precondition here?  Looks like codahale doesnt really 
check this value and directly uses it as the size of the array.  Or can we turn 
off the histogram if it's set to 0 or negative?

##########
File path: flink/src/main/java/org/apache/iceberg/flink/sink/FlinkSink.java
##########
@@ -249,6 +251,19 @@ public Builder uidPrefix(String newPrefix) {
       return this;
     }
 
+    /**
+     * Set the {@link SlidingWindowReservoir} size (number of measurements 
stored)
+     * for the two histogram metrics of data files and delete file size 
distribution.
+     *
+     * @param newReservoirSize
+     * default is 128, which  only add a small memory overhead of 1 KB (128 x 
8B) per histogram. For large

Review comment:
       Small nit: Can you make it a complete sentence, and fix the extra space?

##########
File path: 
flink/src/main/java/org/apache/iceberg/flink/sink/IcebergFilesCommitterMetrics.java
##########
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.flink.sink;
+
+import com.codahale.metrics.SlidingWindowReservoir;
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.flink.dropwizard.metrics.DropwizardHistogramWrapper;
+import org.apache.flink.metrics.Histogram;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.iceberg.io.WriteResult;
+
+class IcebergFilesCommitterMetrics {
+
+  private final AtomicLong lastCheckpointDurationMs;
+  private final AtomicLong lastCommitDurationMs;
+  private final AtomicLong committedDataFilesCount;
+  private final AtomicLong committedDataFilesRecordCount;
+  private final AtomicLong committedDataFilesByteCount;
+  private final AtomicLong committedDeleteFilesCount;
+  private final AtomicLong committedDeleteFilesRecordCount;
+  private final AtomicLong committedDeleteFilesByteCount;
+
+  private final Histogram dataFilesSizeHistogram;
+  private final Histogram deleteFilesSizeHistogram;
+
+  IcebergFilesCommitterMetrics(MetricGroup metrics, String fullTableName,
+                               int slidingWindowReservoirSize) {
+    MetricGroup committerMetrics = metrics.addGroup("IcebergFilesCommitter", 
fullTableName);
+
+    this.lastCheckpointDurationMs = new AtomicLong();

Review comment:
       Nit: for these variables, initialize when declaring them?

##########
File path: 
flink/src/main/java/org/apache/iceberg/flink/sink/IcebergStreamWriterMetrics.java
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.flink.sink;
+
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.flink.metrics.Counter;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.iceberg.io.WriteResult;
+
+class IcebergStreamWriterMetrics {
+
+  private final Counter processedRecords;
+  private final AtomicLong flushedDataFiles;
+  private final AtomicLong flushedDeleteFiles;
+  private final AtomicLong flushedReferencedDataFiles;
+  private final AtomicLong lastFlushDurationMs;
+
+  IcebergStreamWriterMetrics(MetricGroup metrics, String fullTableName) {
+    MetricGroup writerMetrics = metrics.addGroup("IcebergStreamWriter", 
fullTableName);
+
+    processedRecords = writerMetrics.counter("processedRecords");
+    flushedDataFiles = new AtomicLong();

Review comment:
       Can we instantiate these when we declare them?




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