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/12/05 01:23:23 UTC

[GitHub] [beam] ihji opened a new pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

ihji opened a new pull request #13491:
URL: https://github.com/apache/beam/pull/13491


   …y logging
   
   **Please** add a meaningful description for your change here
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
    - [ ] Format the pull request title like `[BEAM-XXX] Fixes bug in ApproximateQuantiles`, where you replace `BEAM-XXX` with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/#make-reviewers-job-easier).
   
   Post-Commit Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   
   Lang | SDK | Dataflow | Flink | Samza | Spark | Twister2
   --- | --- | --- | --- | --- | --- | ---
   Go | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Go/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Go/lastCompletedBuild/) | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Go_VR_Flink/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Go_VR_Flink/lastCompletedBuild/) | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Go_VR_Spark/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Go_VR_Spark/lastCompletedBuild/) | ---
   Java | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_VR_Dataflow_V2/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_VR_Dataflow_V2/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow_Java11/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow_Java11/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink/lastCompletedBuild/badge/icon)](https://ci-beam
 .apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink_Java11/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink_Java11/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Flink_Batch/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Flink_Batch/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Flink_Streaming/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Flink_Streaming/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Samza/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Samza/lastCompletedBuild/) | [![Build Status](https://ci-beam.a
 pache.org/job/beam_PostCommit_Java_ValidatesRunner_Spark/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Spark/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Spark_Batch/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Spark_Batch/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_SparkStructuredStreaming/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_SparkStructuredStreaming/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Twister2/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Twister2/lastCompletedBuild/)
   Python | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python36/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python36/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python37/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python37/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python38/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python38/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Py_VR_Dataflow/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Py_VR_Dataflow/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Py_VR_Dataflow_V2/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Py_VR_Dataflow_V2/lastCompletedBuild/)<br>[![Build Status](https://ci-beam
 .apache.org/job/beam_PostCommit_Py_ValCont/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Py_ValCont/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Python_PVR_Flink_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Python_PVR_Flink_Cron/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python_VR_Flink/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python_VR_Flink/lastCompletedBuild/) | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python_VR_Spark/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python_VR_Spark/lastCompletedBuild/) | ---
   XLang | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Direct/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Direct/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Dataflow/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Dataflow/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Flink/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Flink/lastCompletedBuild/) | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Spark/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Spark/lastCompletedBuild/) | ---
   
   Pre-Commit Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   
   --- |Java | Python | Go | Website | Whitespace | Typescript
   --- | --- | --- | --- | --- | --- | ---
   Non-portable | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Java_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Java_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Python_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Python_Cron/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_PythonLint_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_PythonLint_Cron/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_PythonDocker_Cron/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_PythonDocker_Cron/lastCompletedBuild/) <br>[![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_PythonDocs_Cron/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_PythonDocs_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/be
 am_PreCommit_Go_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Go_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Website_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Website_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Whitespace_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Whitespace_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Typescript_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Typescript_Cron/lastCompletedBuild/)
   Portable | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Portable_Python_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Portable_Python_Cron/lastCompletedBuild/) | --- | --- | --- | ---
   
   See [.test-infra/jenkins/README](https://github.com/apache/beam/blob/master/.test-infra/jenkins/README.md) for trigger phrase, status and link of all Jenkins jobs.
   
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
   


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



[GitHub] [beam] ihji commented on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-740122079


   R: @ajamato
   
   Uses Metrics for logging latencies instead of parameters. Reverted BigQueryService API signature changes for histogram and counter.


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



[GitHub] [beam] ihji commented on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-761521561


   Run Java PreCommit


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



[GitHub] [beam] ajamato commented on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ajamato commented on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-758331523


   @pabloem Would you take a look as well, as a committer. Or lmk if you have someone else in mind on the java side.


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



[GitHub] [beam] ihji commented on a change in pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on a change in pull request #13491:
URL: https://github.com/apache/beam/pull/13491#discussion_r557692931



##########
File path: runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerImpl.java
##########
@@ -383,4 +409,70 @@ public boolean equals(@Nullable Object object) {
   public int hashCode() {
     return Objects.hash(stepName, counters, distributions, gauges);
   }
+
+  private boolean equalsMetricName(MetricName metricName, String namespace, String name) {
+    return (namespace == null || namespace.equals(metricName.getNamespace()))

Review comment:
       Yeah, `equals` prefix is misleading. It's more like matching and when the field will be ignored when the parameter is null. I renamed the method.




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



[GitHub] [beam] ihji commented on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-755012399


   @ajamato Friendly ping


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



[GitHub] [beam] ajamato commented on a change in pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ajamato commented on a change in pull request #13491:
URL: https://github.com/apache/beam/pull/13491#discussion_r555442985



##########
File path: sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/LatencyRecordingHttpRequestInitializer.java
##########
@@ -23,14 +23,26 @@
 import com.google.api.client.http.HttpResponse;
 import com.google.api.client.http.HttpResponseInterceptor;
 import java.io.IOException;
-import org.apache.beam.sdk.util.Histogram;
+import org.apache.beam.sdk.metrics.Histogram;
+import org.apache.beam.sdk.metrics.Metrics;
+import org.apache.beam.sdk.util.HistogramData;
 
 /** HttpRequestInitializer for recording request to response latency of Http-based API calls. */
 public class LatencyRecordingHttpRequestInitializer implements HttpRequestInitializer {
+  public static final String HISTOGRAM_NAME = "latency_ms";

Review comment:
       Would you please use a specific name for the metric where it is instantiated
   
   See the URN defined here:
   API_REQUEST_LATENCIES
   urn = beam:metric:io:api_request_latencies:v1
   https://s.apache.org/beam-gcp-debuggability
   
   For Labels:
   for SERVICE_NAME use "BigQuery", METHOD_NAME you can use "BigQueryBatchWrite" and "BigQueryBatchRead". Which is just referring to API calls which read or write elements in batches.
   
   Additional Labels (Populate these if they are available, if not leave it for follow up work for me):
   BIGQUERY_PROJECT_ID
   BIGQUERY_DATASET
   BIGQUERY_TABLE
   BIGQUERY_VIEW
   BIGQUERY_QUERY_NAME- user provided query name
   RESOURCE - combination of the above (See my python PR linked below for reference)
   
   https://github.com/apache/beam/pull/13217/files#diff-5427a5d3887eb695cefde082c58575a2372972996b547d55961abeb4f7bc3debR576
   

##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/DelegatingCounter.java
##########
@@ -38,7 +44,10 @@ public void inc() {
   /** Increment the counter by the given amount. */
   @Override
   public void inc(long n) {
-    MetricsContainer container = MetricsEnvironment.getCurrentContainer();
+    MetricsContainer container =
+        processWideContainer

Review comment:
       this.processWideContainer

##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/Metrics.java
##########
@@ -96,6 +97,21 @@ public static Gauge gauge(Class<?> namespace, String name) {
     return new DelegatingGauge(MetricName.named(namespace, name));
   }
 
+  public static class Internal {
+    public static Counter counter(String namespace, String name, boolean processWideContainer) {
+      return new DelegatingCounter(MetricName.named(namespace, name), processWideContainer);
+    }
+
+    public static Histogram histogram(
+        String namespace,

Review comment:
       namespace and name parameters are specific to user metric (Which is a metric that populates a specific MonitoringInfo URN with a name and namspace parameter).
   
   Have this just take a MetricName instead which allows for non user metrics
   I.e. like the ElementCount metric
   which is uniquely identifiers by a URN and labels.
   
   https://github.com/apache/beam/pull/7272/files#diff-3834ef03b753005ee8251870a88fe3505732e9a7ad34da600f78e33ab9f37139R45
   
   You can make it under the LabeledMetrics class, which is meant to be an internal implementation for SDK harness implementations. Not part of the public API (Much like the internal.Metrics in python you've added).
   
   




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



[GitHub] [beam] ihji merged pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji merged pull request #13491:
URL: https://github.com/apache/beam/pull/13491


   


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



[GitHub] [beam] ihji commented on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-761529153


   Run Java PreCommit


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



[GitHub] [beam] ihji commented on a change in pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on a change in pull request #13491:
URL: https://github.com/apache/beam/pull/13491#discussion_r556847572



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/Metrics.java
##########
@@ -96,6 +97,21 @@ public static Gauge gauge(Class<?> namespace, String name) {
     return new DelegatingGauge(MetricName.named(namespace, name));
   }
 
+  public static class Internal {
+    public static Counter counter(String namespace, String name, boolean processWideContainer) {
+      return new DelegatingCounter(MetricName.named(namespace, name), processWideContainer);
+    }
+
+    public static Histogram histogram(
+        String namespace,

Review comment:
       Done. Moved into `LabeledMetrics`.




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



[GitHub] [beam] ihji commented on a change in pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on a change in pull request #13491:
URL: https://github.com/apache/beam/pull/13491#discussion_r556846796



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/DelegatingCounter.java
##########
@@ -38,7 +44,10 @@ public void inc() {
   /** Increment the counter by the given amount. */
   @Override
   public void inc(long n) {
-    MetricsContainer container = MetricsEnvironment.getCurrentContainer();
+    MetricsContainer container =
+        processWideContainer

Review comment:
       Done.




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



[GitHub] [beam] ajamato commented on a change in pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ajamato commented on a change in pull request #13491:
URL: https://github.com/apache/beam/pull/13491#discussion_r555446487



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricsLogger.java
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.beam.sdk.metrics;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.annotations.Experimental.Kind;
+import org.slf4j.Logger;
+
+@Experimental(Kind.METRICS)
+public interface MetricsLogger extends Serializable {
+  Lock REPORTING_LOCK = new ReentrantLock();
+  AtomicLong LAST_REPORTED_MILLIS = new AtomicLong(System.currentTimeMillis());
+
+  default void tryLoggingMetrics(
+      String header, String namespace, long minimumLoggingFrequencyMillis, boolean resetMetrics) {
+    if (REPORTING_LOCK.tryLock()) {

Review comment:
       Is it possible to use this style for logging, if it exists? If not ignore this suggestion.
   
   
           try (Autolock alock = new Autolock(lock)) {
               // Whatever you need to do while you own the lock
           } //unlocks here
           
           See:
   
   https://stackoverflow.com/questions/151917/autolock-in-java-how-to




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



[GitHub] [beam] ajamato commented on a change in pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ajamato commented on a change in pull request #13491:
URL: https://github.com/apache/beam/pull/13491#discussion_r557579670



##########
File path: runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsContainerImpl.java
##########
@@ -383,4 +409,70 @@ public boolean equals(@Nullable Object object) {
   public int hashCode() {
     return Objects.hash(stepName, counters, distributions, gauges);
   }
+
+  private boolean equalsMetricName(MetricName metricName, String namespace, String name) {
+    return (namespace == null || namespace.equals(metricName.getNamespace()))

Review comment:
       This equality looks werid, why would it be considered equal if the param is null?
   
   Can you add a clairifying comment




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



[GitHub] [beam] ihji commented on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-761521536


   Run Java_Examples_Dataflow PreCommit


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



[GitHub] [beam] ihji removed a comment on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji removed a comment on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-761521536


   Run Java_Examples_Dataflow PreCommit


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



[GitHub] [beam] ihji commented on a change in pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on a change in pull request #13491:
URL: https://github.com/apache/beam/pull/13491#discussion_r556848262



##########
File path: sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/LatencyRecordingHttpRequestInitializer.java
##########
@@ -23,14 +23,26 @@
 import com.google.api.client.http.HttpResponse;
 import com.google.api.client.http.HttpResponseInterceptor;
 import java.io.IOException;
-import org.apache.beam.sdk.util.Histogram;
+import org.apache.beam.sdk.metrics.Histogram;
+import org.apache.beam.sdk.metrics.Metrics;
+import org.apache.beam.sdk.util.HistogramData;
 
 /** HttpRequestInitializer for recording request to response latency of Http-based API calls. */
 public class LatencyRecordingHttpRequestInitializer implements HttpRequestInitializer {
+  public static final String HISTOGRAM_NAME = "latency_ms";

Review comment:
       Done.




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



[GitHub] [beam] ihji commented on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-759796964


   Run Java PreCommit


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



[GitHub] [beam] ihji commented on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-744789739


   @ajamato PTAL


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



[GitHub] [beam] ihji removed a comment on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji removed a comment on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-761529153


   Run Java PreCommit


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



[GitHub] [beam] ihji commented on a change in pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji commented on a change in pull request #13491:
URL: https://github.com/apache/beam/pull/13491#discussion_r556865969



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricsLogger.java
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.beam.sdk.metrics;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.annotations.Experimental.Kind;
+import org.slf4j.Logger;
+
+@Experimental(Kind.METRICS)
+public interface MetricsLogger extends Serializable {
+  Lock REPORTING_LOCK = new ReentrantLock();
+  AtomicLong LAST_REPORTED_MILLIS = new AtomicLong(System.currentTimeMillis());
+
+  default void tryLoggingMetrics(
+      String header, String namespace, long minimumLoggingFrequencyMillis, boolean resetMetrics) {
+    if (REPORTING_LOCK.tryLock()) {

Review comment:
       `Lock` is not auto closeable by default and IMHO `tryLock` doesn't fit well with try-with-resources style (it hides the semantics of `tryLock`).




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



[GitHub] [beam] ihji removed a comment on pull request #13491: [BEAM-11032] Use metric for Java BigQuery streaming insert API latenc…

Posted by GitBox <gi...@apache.org>.
ihji removed a comment on pull request #13491:
URL: https://github.com/apache/beam/pull/13491#issuecomment-761521561


   Run Java PreCommit


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