diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricKey.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricKey.java index e7dcebd14833..05f1d736d8a5 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricKey.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricKey.java @@ -18,6 +18,7 @@ package org.apache.beam.sdk.metrics; import com.google.auto.value.AutoValue; +import com.google.auto.value.extension.memoized.Memoized; import java.io.Serializable; import org.apache.beam.sdk.annotations.Experimental; import org.apache.beam.sdk.annotations.Experimental.Kind; @@ -35,7 +36,8 @@ public abstract class MetricKey implements Serializable { public abstract MetricName metricName(); @Override - public final String toString() { + @Memoized + public String toString() { return stepName() + ":" + metricName(); } diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricName.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricName.java index 329e44a5d714..258aa4827c50 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricName.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricName.java @@ -20,6 +20,7 @@ import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument; import com.google.auto.value.AutoValue; +import com.google.auto.value.extension.memoized.Memoized; import java.io.Serializable; import org.apache.beam.sdk.annotations.Experimental; import org.apache.beam.sdk.annotations.Experimental.Kind; @@ -42,6 +43,7 @@ public abstract class MetricName implements Serializable { public abstract String getName(); @Override + @Memoized public String toString() { return getNamespace() + ":" + getName(); }