diff --git a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricUrns.java b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricUrns.java new file mode 100644 index 000000000000..6b40603081a1 --- /dev/null +++ b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricUrns.java @@ -0,0 +1,43 @@ +/* + * 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.core.metrics; + +import static org.apache.beam.runners.core.metrics.SimpleMonitoringInfoBuilder.USER_COUNTER_URN_PREFIX; + +import org.apache.beam.sdk.metrics.MetricName; + +/** Utility for parsing a URN to a {@link MetricName}. */ +public class MetricUrns { + /** + * Parse a {@link MetricName} from a {@link + * org.apache.beam.model.fnexecution.v1.BeamFnApi.MonitoringInfoUrns.Enum}. + * + *
Should be consistent with {@code parse_namespace_and_name} in monitoring_infos.py. + */ + public static MetricName parseUrn(String urn) { + if (urn.startsWith(USER_COUNTER_URN_PREFIX)) { + urn = urn.substring(USER_COUNTER_URN_PREFIX.length()); + } + // If it is not a user counter, just use the first part of the URN, i.e. 'beam' + String[] pieces = urn.split(":", 2); + if (pieces.length != 2) { + throw new IllegalArgumentException("Invalid metric URN: " + urn); + } + return MetricName.named(pieces[0], pieces[1]); + } +} diff --git a/runners/flink/src/main/java/org/apache/beam/runners/flink/metrics/FlinkMetricContainer.java b/runners/flink/src/main/java/org/apache/beam/runners/flink/metrics/FlinkMetricContainer.java index c235a51782e6..23d1f8356da3 100644 --- a/runners/flink/src/main/java/org/apache/beam/runners/flink/metrics/FlinkMetricContainer.java +++ b/runners/flink/src/main/java/org/apache/beam/runners/flink/metrics/FlinkMetricContainer.java @@ -17,13 +17,18 @@ */ package org.apache.beam.runners.flink.metrics; +import static org.apache.beam.runners.core.metrics.MetricUrns.parseUrn; import static org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults; -import static org.apache.beam.runners.core.metrics.SimpleMonitoringInfoBuilder.USER_COUNTER_URN_PREFIX; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.beam.model.fnexecution.v1.BeamFnApi; +import org.apache.beam.model.fnexecution.v1.BeamFnApi.CounterData; +import org.apache.beam.model.fnexecution.v1.BeamFnApi.DistributionData; +import org.apache.beam.model.fnexecution.v1.BeamFnApi.ExtremaData; +import org.apache.beam.model.fnexecution.v1.BeamFnApi.IntDistributionData; +import org.apache.beam.model.fnexecution.v1.BeamFnApi.Metric; +import org.apache.beam.model.fnexecution.v1.BeamFnApi.MonitoringInfo; import org.apache.beam.runners.core.metrics.MetricsContainerImpl; import org.apache.beam.runners.core.metrics.MetricsContainerStepMap; import org.apache.beam.sdk.metrics.Distribution; @@ -90,36 +95,20 @@ public MetricsContainer getMetricsContainer(String stepName) { } /** - * Parse a {@link MetricName} from a {@link - * org.apache.beam.model.fnexecution.v1.BeamFnApi.MonitoringInfoUrns.Enum} - * - *
Should be consistent with {@code parse_namespace_and_name} in monitoring_infos.py - * - *
TODO: not flink-specific; where should it live?
+ * Update this container with metrics from the passed {@link MonitoringInfo}s, and send updates
+ * along to Flink's internal metrics framework.
*/
- public static MetricName parseUrn(String urn) {
- if (urn.startsWith(USER_COUNTER_URN_PREFIX)) {
- urn = urn.substring(USER_COUNTER_URN_PREFIX.length());
- }
- // If it is not a user counter, just use the first part of the URN, i.e. 'beam'
- String[] pieces = urn.split(":", 2);
- if (pieces.length != 2) {
- throw new IllegalArgumentException("Invalid metric URN: " + urn);
- }
- return MetricName.named(pieces[0], pieces[1]);
- }
-
- public void updateMetrics(String stepName, List