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/03/28 23:18:15 UTC

[PR] Cache Histograms in BigQuerySinkMetrics [beam]

JayajP opened a new pull request, #30796:
URL: https://github.com/apache/beam/pull/30796

   Cache HistogramMetrics in BigQuerySinkMetrics so that these metrics are only created once per worker.
   Using [Initialization On Demand Holder Pattern](https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom)
   ------------------------
   
   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)
   ------------------------------------------------------------------------------------------------
   [![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)
   [![Go tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](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] Move logic to build a Labeled Metric Name to a util file. [beam]

Posted by "JayajP (via GitHub)" <gi...@apache.org>.
JayajP commented on PR #30796:
URL: https://github.com/apache/beam/pull/30796#issuecomment-2052638999

   Java IO precommit failing due to #30941 


-- 
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] Optimize histograms and metric names in BigQuerySinkMetrics [beam]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #30796:
URL: https://github.com/apache/beam/pull/30796#issuecomment-2043422958

   ## [Codecov](https://app.codecov.io/gh/apache/beam/pull/30796?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `87.50000%` with `2 lines` in your changes are missing coverage. Please review.
   > Project coverage is 70.86%. Comparing base [(`e894d8c`)](https://app.codecov.io/gh/apache/beam/commit/e894d8ca7fe10ed4771ce9d999b48361c25220ec?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`ebf509e`)](https://app.codecov.io/gh/apache/beam/pull/30796?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 104 commits behind head on master.
   
   > :exclamation: Current head ebf509e differs from pull request most recent head e3f3012. Consider uploading reports for the commit e3f3012 to get more accurate results
   
   | [Files](https://app.codecov.io/gh/apache/beam/pull/30796?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [.../beam/sdk/io/gcp/bigquery/BigQuerySinkMetrics.java](https://app.codecov.io/gh/apache/beam/pull/30796?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fbigquery%2FBigQuerySinkMetrics.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL2JpZ3F1ZXJ5L0JpZ1F1ZXJ5U2lua01ldHJpY3MuamF2YQ==) | 86.66% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/beam/pull/30796?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #30796      +/-   ##
   ============================================
   - Coverage     71.47%   70.86%   -0.61%     
   - Complexity        0     2990    +2990     
   ============================================
     Files           710     1062     +352     
     Lines        104815   132697   +27882     
     Branches          0     3230    +3230     
   ============================================
   + Hits          74915    94034   +19119     
   - Misses        28268    35570    +7302     
   - Partials       1632     3093    +1461     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/beam/pull/30796/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [java](https://app.codecov.io/gh/apache/beam/pull/30796/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `68.57% <87.50%> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/beam/pull/30796?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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] Cache Histograms in BigQuerySinkMetrics [beam]

Posted by "JayajP (via GitHub)" <gi...@apache.org>.
JayajP commented on PR #30796:
URL: https://github.com/apache/beam/pull/30796#issuecomment-2027571536

   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] Move logic to build a Labeled Metric Name to a util file. [beam]

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn merged PR #30796:
URL: https://github.com/apache/beam/pull/30796


-- 
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] Cache Histograms in BigQuerySinkMetrics [beam]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #30796:
URL: https://github.com/apache/beam/pull/30796#issuecomment-2026362370

   ## [Codecov](https://app.codecov.io/gh/apache/beam/pull/30796?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `87.50000%` with `2 lines` in your changes are missing coverage. Please review.
   > Project coverage is 70.86%. Comparing base [(`e894d8c`)](https://app.codecov.io/gh/apache/beam/commit/e894d8ca7fe10ed4771ce9d999b48361c25220ec?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`ebf509e`)](https://app.codecov.io/gh/apache/beam/pull/30796?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 8 commits behind head on master.
   
   | [Files](https://app.codecov.io/gh/apache/beam/pull/30796?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [.../beam/sdk/io/gcp/bigquery/BigQuerySinkMetrics.java](https://app.codecov.io/gh/apache/beam/pull/30796?src=pr&el=tree&filepath=sdks%2Fjava%2Fio%2Fgoogle-cloud-platform%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fbeam%2Fsdk%2Fio%2Fgcp%2Fbigquery%2FBigQuerySinkMetrics.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2Rrcy9qYXZhL2lvL2dvb2dsZS1jbG91ZC1wbGF0Zm9ybS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvYmVhbS9zZGsvaW8vZ2NwL2JpZ3F1ZXJ5L0JpZ1F1ZXJ5U2lua01ldHJpY3MuamF2YQ==) | 86.66% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/beam/pull/30796?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #30796      +/-   ##
   ============================================
   - Coverage     71.47%   70.86%   -0.61%     
   - Complexity        0     2990    +2990     
   ============================================
     Files           710     1062     +352     
     Lines        104815   132697   +27882     
     Branches          0     3230    +3230     
   ============================================
   + Hits          74915    94034   +19119     
   - Misses        28268    35570    +7302     
   - Partials       1632     3093    +1461     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/beam/pull/30796/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [java](https://app.codecov.io/gh/apache/beam/pull/30796/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `68.57% <87.50%> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/beam/pull/30796?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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] Cache Histograms in BigQuerySinkMetrics [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #30796:
URL: https://github.com/apache/beam/pull/30796#issuecomment-2027573382

   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] Move logic to build a Labeled Metric Name to a util file. [beam]

Posted by "m-trieu (via GitHub)" <gi...@apache.org>.
m-trieu commented on code in PR #30796:
URL: https://github.com/apache/beam/pull/30796#discussion_r1560068175


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/LabeledMetricNameUtils.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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 com.google.auto.value.AutoValue;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Splitter;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+
+/** Util class for building/parsing labeled {@link MetricName}. */
+public class LabeledMetricNameUtils {
+  // Delimiters. Avoid using delimeters that can be used in metric labels.
+  // E.g. Since we support BigQuery TableIds as labels we avoid using delimiters that can be used in
+  // TableIds.
+  // ref: https://cloud.google.com/bigquery/docs/tables#table_naming
+  private static final char LABEL_DELIMITER = ';';
+  private static final char METRIC_KV_DELIMITER = ':';
+  private static final char METRIC_NAME_DELIMITER = '*';
+
+  /**
+   * Builder class for a labeled {@code MetricName}. Returned {@link MetricName#getName} will be
+   * formatted as:
+   *
+   * <p>'{baseName}-{metricLabelKey1}:{metricLabelVal1};...{metricLabelKeyN}:{metricLabelValN};'
+   */
+  public static class MetricNameBuilder {
+    private final StringBuilder labeledNameBuilder;
+
+    private MetricNameBuilder(String baseName) {
+      this.labeledNameBuilder = new StringBuilder(baseName + METRIC_NAME_DELIMITER);
+    }
+
+    public static MetricNameBuilder baseNameBuilder(String baseName) {
+      return new MetricNameBuilder(baseName);
+    }
+
+    /**
+     * Add a metric label KV pair to the metric name. Calling {@code addLabel} multiple times with
+     * the same {@code key} will lead to unexpected results when parsing metric names.
+     */
+    public void addLabel(String key, String value) {
+      this.labeledNameBuilder
+          .append(key)
+          .append(METRIC_KV_DELIMITER)
+          .append(value)
+          .append(LABEL_DELIMITER);
+    }
+
+    public MetricName build(String metricNamespace) {
+      return MetricName.named(metricNamespace, labeledNameBuilder.toString());
+    }
+  }
+
+  @AutoValue
+  public abstract static class ParsedMetricName {
+    public abstract String getBaseName();
+
+    public abstract Map<String, String> getMetricLabels();
+
+    public static ParsedMetricName create(String baseName, Map<String, String> metricLabels) {
+      return new AutoValue_LabeledMetricNameUtils_ParsedMetricName(baseName, metricLabels);
+    }
+
+    public static ParsedMetricName create(String baseName) {
+      ImmutableMap<String, String> emptyMap = ImmutableMap.of();
+      return new AutoValue_LabeledMetricNameUtils_ParsedMetricName(baseName, emptyMap);
+    }
+  }
+
+  /**
+   * Parse a 'metric name' String that was created with 'MetricNameBuilder'. The input string should
+   * be formatted as.
+   *
+   * <p>'{baseName}*{metricLabelKey1}:{metricLabelVal1};...{metricLabelKeyN}:{metricLabelValN};'
+   *
+   * @param metricName
+   * @return Returns a ParsedMetricName object if the input string is properly formatted. If the
+   *     input string is empty or malformed, returns an empty value.
+   */
+  public static Optional<ParsedMetricName> parseMetricName(String metricName) {
+    if (metricName.isEmpty()) {
+      return Optional.empty();
+    }
+
+    List<String> metricNameSplit =
+        Splitter.on(METRIC_NAME_DELIMITER).limit(2).splitToList(metricName);
+
+    if (metricNameSplit.size() == 0) {
+      return Optional.empty();
+    }
+
+    if (metricNameSplit.size() == 1) {
+      return Optional.of(ParsedMetricName.create(metricNameSplit.get(0)));
+    }
+
+    Splitter.MapSplitter splitter =
+        Splitter.on(LABEL_DELIMITER).omitEmptyStrings().withKeyValueSeparator(METRIC_KV_DELIMITER);
+    try {
+      Map<String, String> labels = splitter.split(metricNameSplit.get(1));
+      return Optional.of(ParsedMetricName.create(metricNameSplit.get(0), labels));
+    } catch (IllegalArgumentException e) {

Review Comment:
   or maybe just move the return statement below into here to show that we only do the latter when an an exception is thrown



-- 
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] Move logic to build a Labeled Metric Name to a util file. [beam]

Posted by "m-trieu (via GitHub)" <gi...@apache.org>.
m-trieu commented on code in PR #30796:
URL: https://github.com/apache/beam/pull/30796#discussion_r1560067189


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/LabeledMetricNameUtils.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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 com.google.auto.value.AutoValue;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Splitter;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+
+/** Util class for building/parsing labeled {@link MetricName}. */
+public class LabeledMetricNameUtils {
+  // Delimiters. Avoid using delimeters that can be used in metric labels.
+  // E.g. Since we support BigQuery TableIds as labels we avoid using delimiters that can be used in
+  // TableIds.
+  // ref: https://cloud.google.com/bigquery/docs/tables#table_naming
+  private static final char LABEL_DELIMITER = ';';
+  private static final char METRIC_KV_DELIMITER = ':';
+  private static final char METRIC_NAME_DELIMITER = '*';
+
+  /**
+   * Builder class for a labeled {@code MetricName}. Returned {@link MetricName#getName} will be
+   * formatted as:
+   *
+   * <p>'{baseName}-{metricLabelKey1}:{metricLabelVal1};...{metricLabelKeyN}:{metricLabelValN};'
+   */
+  public static class MetricNameBuilder {
+    private final StringBuilder labeledNameBuilder;
+
+    private MetricNameBuilder(String baseName) {
+      this.labeledNameBuilder = new StringBuilder(baseName + METRIC_NAME_DELIMITER);
+    }
+
+    public static MetricNameBuilder baseNameBuilder(String baseName) {
+      return new MetricNameBuilder(baseName);
+    }
+
+    /**
+     * Add a metric label KV pair to the metric name. Calling {@code addLabel} multiple times with
+     * the same {@code key} will lead to unexpected results when parsing metric names.
+     */
+    public void addLabel(String key, String value) {
+      this.labeledNameBuilder
+          .append(key)
+          .append(METRIC_KV_DELIMITER)
+          .append(value)
+          .append(LABEL_DELIMITER);
+    }
+
+    public MetricName build(String metricNamespace) {
+      return MetricName.named(metricNamespace, labeledNameBuilder.toString());
+    }
+  }
+
+  @AutoValue
+  public abstract static class ParsedMetricName {
+    public abstract String getBaseName();
+
+    public abstract Map<String, String> getMetricLabels();
+
+    public static ParsedMetricName create(String baseName, Map<String, String> metricLabels) {
+      return new AutoValue_LabeledMetricNameUtils_ParsedMetricName(baseName, metricLabels);
+    }
+
+    public static ParsedMetricName create(String baseName) {
+      ImmutableMap<String, String> emptyMap = ImmutableMap.of();
+      return new AutoValue_LabeledMetricNameUtils_ParsedMetricName(baseName, emptyMap);
+    }
+  }
+
+  /**
+   * Parse a 'metric name' String that was created with 'MetricNameBuilder'. The input string should
+   * be formatted as.
+   *
+   * <p>'{baseName}*{metricLabelKey1}:{metricLabelVal1};...{metricLabelKeyN}:{metricLabelValN};'
+   *
+   * @param metricName
+   * @return Returns a ParsedMetricName object if the input string is properly formatted. If the
+   *     input string is empty or malformed, returns an empty value.
+   */
+  public static Optional<ParsedMetricName> parseMetricName(String metricName) {
+    if (metricName.isEmpty()) {
+      return Optional.empty();
+    }
+
+    List<String> metricNameSplit =
+        Splitter.on(METRIC_NAME_DELIMITER).limit(2).splitToList(metricName);
+
+    if (metricNameSplit.size() == 0) {
+      return Optional.empty();
+    }
+
+    if (metricNameSplit.size() == 1) {
+      return Optional.of(ParsedMetricName.create(metricNameSplit.get(0)));
+    }
+
+    Splitter.MapSplitter splitter =
+        Splitter.on(LABEL_DELIMITER).omitEmptyStrings().withKeyValueSeparator(METRIC_KV_DELIMITER);
+    try {
+      Map<String, String> labels = splitter.split(metricNameSplit.get(1));
+      return Optional.of(ParsedMetricName.create(metricNameSplit.get(0), labels));
+    } catch (IllegalArgumentException e) {

Review Comment:
   should we log something here?



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