You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/09/23 16:48:50 UTC

[GitHub] [beam] ajamato commented on a change in pull request #12852: [BEAM-10890] Log error counts to debug BigQuery streaming insert requ…

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:
users@infra.apache.org