JayajP commented on code in PR #30084:
URL: https://github.com/apache/beam/pull/30084#discussion_r1463917941


##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/MetricsToPerStepNamespaceMetricsConverter.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.runners.dataflow.worker;
+
+import com.google.api.services.dataflow.model.Base2Exponent;
+import com.google.api.services.dataflow.model.BucketOptions;
+import com.google.api.services.dataflow.model.DataflowHistogramValue;
+import com.google.api.services.dataflow.model.Linear;
+import com.google.api.services.dataflow.model.MetricValue;
+import com.google.api.services.dataflow.model.OutlierStats;
+import com.google.api.services.dataflow.model.PerStepNamespaceMetrics;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.io.gcp.bigquery.BigQuerySinkMetrics;
+import org.apache.beam.sdk.metrics.MetricName;
+import org.apache.beam.sdk.util.HistogramData;
+
+/**
+ * Converts metric updates to {@link PerStepNamespaceMetrics} protos. 
Currently we only support
+ * converting metrics from {@link BigQuerySinkMetrics} with this converter.
+ */
+public class MetricsToPerStepNamespaceMetricsConverter {
+  /**
+   * @param metricName The {@link MetricName} that represents this counter.
+   * @param value The counter value.
+   * @return If the conversion succeeds, {@code MetricValue} that represents 
this counter. Otherwise
+   *     returns null.
+   */
+  private static @Nullable MetricValue convertCounterToMetricValue(

Review Comment:
   Done, didn't know this type existed.



##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/MetricsToPerStepNamespaceMetricsConverter.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.runners.dataflow.worker;
+
+import com.google.api.services.dataflow.model.Base2Exponent;
+import com.google.api.services.dataflow.model.BucketOptions;
+import com.google.api.services.dataflow.model.DataflowHistogramValue;
+import com.google.api.services.dataflow.model.Linear;
+import com.google.api.services.dataflow.model.MetricValue;
+import com.google.api.services.dataflow.model.OutlierStats;
+import com.google.api.services.dataflow.model.PerStepNamespaceMetrics;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.io.gcp.bigquery.BigQuerySinkMetrics;
+import org.apache.beam.sdk.metrics.MetricName;
+import org.apache.beam.sdk.util.HistogramData;
+
+/**
+ * Converts metric updates to {@link PerStepNamespaceMetrics} protos. 
Currently we only support
+ * converting metrics from {@link BigQuerySinkMetrics} with this converter.
+ */
+public class MetricsToPerStepNamespaceMetricsConverter {
+  /**
+   * @param metricName The {@link MetricName} that represents this counter.
+   * @param value The counter value.
+   * @return If the conversion succeeds, {@code MetricValue} that represents 
this counter. Otherwise
+   *     returns null.
+   */
+  private static @Nullable MetricValue convertCounterToMetricValue(
+      MetricName metricName, Long value) {
+    if (value == 0 || 
!metricName.getNamespace().equals(BigQuerySinkMetrics.METRICS_NAMESPACE)) {
+      return null;
+    }
+
+    BigQuerySinkMetrics.ParsedMetricName labeledName =
+        BigQuerySinkMetrics.parseMetricName(metricName.getName());
+    if (labeledName == null || labeledName.getBaseName().isEmpty()) {
+      return null;
+    }
+
+    MetricValue val =
+        new MetricValue()
+            .setMetric(labeledName.getBaseName())
+            .setMetricLabels(labeledName.getMetricLabels())
+            .setValueInt64(value);
+    return val;
+  }
+
+  /**
+   * @param metricName The {@link MetricName} that represents this Histogram.
+   * @param value The histogram value. Currently we only support converting 
histograms that use
+   *     {@code linear} or {@code exponential} buckets.
+   * @return If this conversion succeeds, a {@code MetricValue} that 
represents this histogram.
+   *     Otherwise returns null.
+   */
+  private static @Nullable MetricValue convertHistogramToMetricValue(

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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to