Skip to content

Commit

Permalink
Fixes from review.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuereth committed Jul 9, 2021
1 parent e21ea5e commit a1a0fb0
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private static void addHistogramSamples(
}
}

@Nullable
private static Exemplar lastExemplarOrNull(Collection<Exemplar> exemplars) {
Exemplar result = null;
for (Exemplar e : exemplars) {
Expand All @@ -229,6 +230,7 @@ private static Exemplar lastExemplarOrNull(Collection<Exemplar> exemplars) {
return result;
}

@Nullable
private static Exemplar filterExemplars(Collection<Exemplar> exemplars, double min, double max) {
Exemplar result = null;
for (Exemplar e : exemplars) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +52,7 @@ public static DoubleHistogramPointData create(
double sum,
List<Double> boundaries,
List<Long> counts,
Collection<Exemplar> exemplars) {
List<Exemplar> exemplars) {
if (counts.size() != boundaries.size() + 1) {
throw new IllegalArgumentException(
"invalid counts: size should be "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ public static DoublePointData create(
long epochNanos,
Attributes attributes,
double value,
Collection<Exemplar> exemplars) {
List<Exemplar> exemplars) {
return new AutoValue_DoublePointData(startEpochNanos, epochNanos, attributes, exemplars, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -29,16 +30,18 @@ public interface Exemplar {
/**
* (Optional) Span ID of the exemplar trace.
*
* <p>Span ID may be missing if the measurement is not recorded inside a trace or the trace was
* not sampled.
* <p>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.
*
* <p>Trace ID may be missing if the measurement is not recorded inside a trace or if the trace is
* not sampled.
* <p>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();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ public static LongPointData create(
long epochNanos,
Attributes attributes,
long value,
Collection<Exemplar> exemplars) {
List<Exemplar> exemplars) {
return new AutoValue_LongPointData(startEpochNanos, epochNanos, attributes, exemplars, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -40,5 +40,5 @@ public interface PointData {
*/
Attributes getAttributes();
/** List of exemplars collected from measurements that were used to form the data point. */
Collection<Exemplar> getExemplars();
List<Exemplar> getExemplars();
}

0 comments on commit a1a0fb0

Please sign in to comment.