htran1 commented on a change in pull request #2804: GOBBLIN-955: Expose a 
method to get average record size in KafkaExtra…
URL: https://github.com/apache/incubator-gobblin/pull/2804#discussion_r344804136
 
 

 ##########
 File path: 
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/KafkaExtractorStatsTracker.java
 ##########
 @@ -295,6 +299,30 @@ public void emitTrackingEvents(MetricContext context, 
MultiLongWatermark lowWate
     }
   }
 
+  /**
+   *
+   * @param partitionIdx the index of Kafka partition
+   * @return the average record size of records for a given {@link 
KafkaPartition}
+   */
+  public long getAvgRecordSize(int partitionIdx) {
+    ExtractorStats stats = 
this.statsMap.getOrDefault(this.partitions.get(partitionIdx), null);
+    if (stats != null) {
+      if (stats.getAvgRecordSize() != 0) {
+        //Average record size already computed.
+        return stats.getAvgRecordSize();
+      } else {
+        //Compute average record size
+        if (stats.getProcessedRecordCount() != 0) {
+          return stats.getPartitionTotalSize() / 
stats.getProcessedRecordCount();
+        } else {
 
 Review comment:
   How about removing this else and the outermost else and replacing with a 
return 0 at the end?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to