praveenc7 commented on code in PR #16379:
URL: https://github.com/apache/pinot/pull/16379#discussion_r2216917445


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java:
##########
@@ -199,7 +199,20 @@ public Response downloadSegment(
             "Segment " + segmentName + " or table " + tableName + " not found 
in " + segmentFile.getAbsolutePath(),
             Response.Status.NOT_FOUND);
       }
-      builder.entity(segmentFile);
+      String rawTableName = TableNameBuilder.extractRawTableName(tableName);
+      long segmentSizeInBytes = segmentFile.length();
+      long accessStartTimeMs = System.currentTimeMillis();
+      ResourceUtils.emitPreSegmentDownloadMetrics(_controllerMetrics, 
rawTableName, segmentSizeInBytes);
+      // Streaming the segment file directly from local disk to the output 
stream to ensure we can capture the metrics
+      builder.entity((StreamingOutput) output -> {
+        try {
+          Files.copy(segmentFile.toPath(), output);
+        } finally {
+          long durationMs = System.currentTimeMillis() - accessStartTimeMs;
+          ResourceUtils.emitPostSegmentDownloadMetrics(_controllerMetrics, 
rawTableName, durationMs,

Review Comment:
   Ahh, Right. Fixed it



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