ajamato commented on a change in pull request #12852:
URL: https://github.com/apache/beam/pull/12852#discussion_r493738743



##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/StreamingWriteFn.java
##########
@@ -150,24 +143,42 @@ public void finishBundle(FinishBundleContext context) 
throws Exception {
     for (ValueInSingleWindow<ErrorT> row : failedInserts) {
       context.output(failedOutputTag, row.getValue(), row.getTimestamp(), 
row.getWindow());
     }
-
-    long currentTimeMillis = System.currentTimeMillis();
-    if (histogram.getTotalCount() > 0
-        && (currentTimeMillis - lastReportedSystemClockMillis)
-            > options.getLatencyLoggingFrequency() * 1000L) {
-      logPercentiles();
-      histogram.clear();
-      lastReportedSystemClockMillis = currentTimeMillis;
-    }
+    reportStreamingApiLogging(options);
   }
 
-  private void logPercentiles() {
-    LOG.info(
-        "Total number of streaming insert requests: {}, P99: {}ms, P90: {}ms, 
P50: {}ms",
-        histogram.getTotalCount(),
-        DoubleMath.roundToInt(histogram.p99(), RoundingMode.HALF_UP),
-        DoubleMath.roundToInt(histogram.p90(), RoundingMode.HALF_UP),
-        DoubleMath.roundToInt(histogram.p50(), RoundingMode.HALF_UP));
+  private void reportStreamingApiLogging(BigQueryOptions options) {
+    if (reportingLock.tryLock()) {
+      try {
+        long currentTimeMillis = System.currentTimeMillis();
+        if (currentTimeMillis - lastReportedSystemClockMillis
+            > options.getBqStreamingApiLoggingFrequencySec() * 1000L) {

Review comment:
       Is there a pattern here in java for this. I.e. * MILLIS_PER_SEC. Or 
converting to duration objects and comparing those?

##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/StreamingWriteFn.java
##########
@@ -150,24 +143,42 @@ public void finishBundle(FinishBundleContext context) 
throws Exception {
     for (ValueInSingleWindow<ErrorT> row : failedInserts) {
       context.output(failedOutputTag, row.getValue(), row.getTimestamp(), 
row.getWindow());
     }
-
-    long currentTimeMillis = System.currentTimeMillis();
-    if (histogram.getTotalCount() > 0
-        && (currentTimeMillis - lastReportedSystemClockMillis)
-            > options.getLatencyLoggingFrequency() * 1000L) {
-      logPercentiles();
-      histogram.clear();
-      lastReportedSystemClockMillis = currentTimeMillis;
-    }
+    reportStreamingApiLogging(options);
   }
 
-  private void logPercentiles() {
-    LOG.info(
-        "Total number of streaming insert requests: {}, P99: {}ms, P90: {}ms, 
P50: {}ms",
-        histogram.getTotalCount(),
-        DoubleMath.roundToInt(histogram.p99(), RoundingMode.HALF_UP),
-        DoubleMath.roundToInt(histogram.p90(), RoundingMode.HALF_UP),
-        DoubleMath.roundToInt(histogram.p50(), RoundingMode.HALF_UP));
+  private void reportStreamingApiLogging(BigQueryOptions options) {
+    if (reportingLock.tryLock()) {
+      try {
+        long currentTimeMillis = System.currentTimeMillis();
+        if (currentTimeMillis - lastReportedSystemClockMillis
+            > options.getBqStreamingApiLoggingFrequencySec() * 1000L) {
+          StringBuilder logMessage = new StringBuilder();
+          logMessage.append(
+              String.format(
+                  "[Streaming Insert API Statistics since %s]\n",

Review comment:
       Please make this message mention BigQuery




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


Reply via email to