From c06b69c026ea57874776afa4d1c129fac33854c0 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 9 Jul 2021 17:37:04 -0400 Subject: [PATCH] Fixes from review. --- .../exporter/prometheus/MetricAdapter.java | 2 ++ .../exporter/prometheus/MetricAdapterTest.java | 5 ++++- .../testing/assertj/metrics/MetricAssertionsTest.java | 6 +++--- .../sdk/metrics/data/DoubleHistogramPointData.java | 3 +-- .../sdk/metrics/data/DoublePointData.java | 4 ++-- .../io/opentelemetry/sdk/metrics/data/Exemplar.java | 11 +++++++---- .../opentelemetry/sdk/metrics/data/LongPointData.java | 4 ++-- .../io/opentelemetry/sdk/metrics/data/PointData.java | 4 ++-- 8 files changed, 23 insertions(+), 16 deletions(-) diff --git a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/MetricAdapter.java b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/MetricAdapter.java index 620f007fe4a..789e395ba99 100644 --- a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/MetricAdapter.java +++ b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/MetricAdapter.java @@ -221,6 +221,7 @@ private static void addHistogramSamples( } } + @Nullable private static Exemplar lastExemplarOrNull(Collection exemplars) { Exemplar result = null; for (Exemplar e : exemplars) { @@ -229,6 +230,7 @@ private static Exemplar lastExemplarOrNull(Collection exemplars) { return result; } + @Nullable private static Exemplar filterExemplars(Collection exemplars, double min, double max) { Exemplar result = null; for (Exemplar e : exemplars) { diff --git a/exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/MetricAdapterTest.java b/exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/MetricAdapterTest.java index 83d3f444e2f..02bc077b4fa 100644 --- a/exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/MetricAdapterTest.java +++ b/exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/MetricAdapterTest.java @@ -433,7 +433,10 @@ public String fallbackToStringOf(Object object) { return sb.toString(); } } - return object.toString(); + if (object != null) { + return super.fallbackToStringOf(object); + } + return "null"; } /** Convert an exemplar into a human readable string. */ private static String exemplarToString(Exemplar exemplar) { diff --git a/sdk/metrics-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/metrics/MetricAssertionsTest.java b/sdk/metrics-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/metrics/MetricAssertionsTest.java index 90281620b95..ddedc588aa5 100644 --- a/sdk/metrics-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/metrics/MetricAssertionsTest.java +++ b/sdk/metrics-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/metrics/MetricAssertionsTest.java @@ -23,7 +23,6 @@ import io.opentelemetry.sdk.metrics.data.LongSumData; import io.opentelemetry.sdk.metrics.data.MetricData; import io.opentelemetry.sdk.resources.Resource; -import java.util.Arrays; import java.util.Collections; import org.junit.jupiter.api.Test; @@ -100,7 +99,8 @@ public class MetricAssertionsTest { DoublePointData.create(1, 2, Attributes.empty(), 3.0, Collections.emptyList()); private static final DoublePointData DOUBLE_POINT_DATA_WITH_EXEMPLAR = - DoublePointData.create(1, 2, Attributes.empty(), 3.0, Arrays.asList(DOUBLE_EXEMPLAR)); + DoublePointData.create( + 1, 2, Attributes.empty(), 3.0, Collections.singletonList(DOUBLE_EXEMPLAR)); private static final MetricData LONG_GAUGE_METRIC = MetricData.createLongGauge( @@ -146,7 +146,7 @@ public class MetricAssertionsTest { LongPointData.create(1, 2, Attributes.empty(), 3, Collections.emptyList()); private static final LongPointData LONG_POINT_DATA_WITH_EXEMPLAR = - LongPointData.create(1, 2, Attributes.empty(), 3, Arrays.asList(LONG_EXEMPLAR)); + LongPointData.create(1, 2, Attributes.empty(), 3, Collections.singletonList(LONG_EXEMPLAR)); @Test void metric_passing() { diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleHistogramPointData.java index eaa2cfb7d7b..74f9942b80e 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleHistogramPointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleHistogramPointData.java @@ -8,7 +8,6 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Attributes; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.List; import javax.annotation.concurrent.Immutable; @@ -53,7 +52,7 @@ public static DoubleHistogramPointData create( double sum, List boundaries, List counts, - Collection exemplars) { + List exemplars) { if (counts.size() != boundaries.size() + 1) { throw new IllegalArgumentException( "invalid counts: size should be " diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoublePointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoublePointData.java index 2a07e63e303..3812abdd03e 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoublePointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoublePointData.java @@ -7,8 +7,8 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Attributes; -import java.util.Collection; import java.util.Collections; +import java.util.List; import javax.annotation.concurrent.Immutable; /** @@ -50,7 +50,7 @@ public static DoublePointData create( long epochNanos, Attributes attributes, double value, - Collection exemplars) { + List exemplars) { return new AutoValue_DoublePointData(startEpochNanos, epochNanos, attributes, exemplars, value); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/Exemplar.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/Exemplar.java index 4e1348f17dc..97868ce2afa 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/Exemplar.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/Exemplar.java @@ -6,6 +6,7 @@ package io.opentelemetry.sdk.metrics.data; import io.opentelemetry.api.common.Attributes; +import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; /** @@ -29,16 +30,18 @@ public interface Exemplar { /** * (Optional) Span ID of the exemplar trace. * - *

Span ID may be missing if the measurement is not recorded inside a trace or the trace was - * not sampled. + *

Span ID may be {@code null} if the measurement is not recorded inside a trace or the trace + * was not sampled. */ + @Nullable String getSpanId(); /** * (Optional) Trace ID of the exemplar trace. * - *

Trace ID may be missing if the measurement is not recorded inside a trace or if the trace is - * not sampled. + *

Trace ID may be {@code null} if the measurement is not recorded inside a trace or if the + * trace is not sampled. */ + @Nullable String getTraceId(); /** diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/LongPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/LongPointData.java index e20cef7d83d..7cffd34b73d 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/LongPointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/LongPointData.java @@ -7,8 +7,8 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Attributes; -import java.util.Collection; import java.util.Collections; +import java.util.List; import javax.annotation.concurrent.Immutable; /** @@ -61,7 +61,7 @@ public static LongPointData create( long epochNanos, Attributes attributes, long value, - Collection exemplars) { + List exemplars) { return new AutoValue_LongPointData(startEpochNanos, epochNanos, attributes, exemplars, value); } } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/PointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/PointData.java index bb2a18b61d9..40ebe03163d 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/PointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/PointData.java @@ -6,7 +6,7 @@ package io.opentelemetry.sdk.metrics.data; import io.opentelemetry.api.common.Attributes; -import java.util.Collection; +import java.util.List; import javax.annotation.concurrent.Immutable; /** @@ -40,5 +40,5 @@ public interface PointData { */ Attributes getAttributes(); /** List of exemplars collected from measurements that were used to form the data point. */ - Collection getExemplars(); + List getExemplars(); }