You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "JayajP (via GitHub)" <gi...@apache.org> on 2024/01/23 18:44:07 UTC
[PR] Add converter class to convert metrics to PerStepNamespaceMetrics [beam]
JayajP opened a new pull request, #30084:
URL: https://github.com/apache/beam/pull/30084
Add a MetricsToPerStepNamespaceMetricsConverter class that converts metric updates to PerStepNamespaceMetrics objects.
We will periodically extract BigQuerySink metric updates, convert them into the PerStepNamespaceMetrics format, and send them to the Dataflow backend on the WorkerMessages api.
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] 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://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+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 or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add converter class to convert metrics to PerStepNamespaceMetrics [beam]
Posted by "JayajP (via GitHub)" <gi...@apache.org>.
JayajP commented on PR #30084:
URL: https://github.com/apache/beam/pull/30084#issuecomment-1906734842
R: @m-trieu
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add converter class to convert metrics to PerStepNamespaceMetrics [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #30084:
URL: https://github.com/apache/beam/pull/30084#issuecomment-1906737877
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add converter class to convert metrics to PerStepNamespaceMetrics [beam]
Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn merged PR #30084:
URL: https://github.com/apache/beam/pull/30084
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add converter class to convert metrics to PerStepNamespaceMetrics [beam]
Posted by "m-trieu (via GitHub)" <gi...@apache.org>.
m-trieu commented on code in PR #30084:
URL: https://github.com/apache/beam/pull/30084#discussion_r1463858571
##########
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:
same as above, it is preferred to return `Optional<MetricValue>` instead of `null`
go/java-practices/optional.md
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add converter class to convert metrics to PerStepNamespaceMetrics [beam]
Posted by "m-trieu (via GitHub)" <gi...@apache.org>.
m-trieu commented on code in PR #30084:
URL: https://github.com/apache/beam/pull/30084#discussion_r1463857107
##########
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:
Can this return `Optional<MetricValue>`?
and can return `Optional.empty()` or `Optional.of(val)`
and also nit: instead of `return val;`
can just be
```
return new MetricValue()
.setMetric(labeledName.getBaseName())
.setMetricLabels(labeledName.getMetricLabels())
.setValueInt64(value);
```
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add converter class to convert metrics to PerStepNamespaceMetrics [beam]
Posted by "JayajP (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org