aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--metrics/src/main/java/io/opencensus/metrics/Distribution.java45
-rw-r--r--metrics/src/test/java/io/opencensus/metrics/DistributionTest.java95
-rw-r--r--metrics/src/test/java/io/opencensus/metrics/PointTest.java6
-rw-r--r--metrics/src/test/java/io/opencensus/metrics/ValueTest.java8
4 files changed, 70 insertions, 84 deletions
diff --git a/metrics/src/main/java/io/opencensus/metrics/Distribution.java b/metrics/src/main/java/io/opencensus/metrics/Distribution.java
index 6c6fc2ac..5334a8d8 100644
--- a/metrics/src/main/java/io/opencensus/metrics/Distribution.java
+++ b/metrics/src/main/java/io/opencensus/metrics/Distribution.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
/**
@@ -49,7 +50,6 @@ public abstract class Distribution {
* @param sumOfSquaredDeviations sum of squared deviations of the population values.
* @param bucketBoundaries bucket boundaries of a histogram.
* @param buckets {@link Bucket}s of a histogram.
- * @param exemplars the exemplars associated with histogram buckets.
* @return a {@code Distribution}.
* @since 0.16
*/
@@ -58,8 +58,7 @@ public abstract class Distribution {
long count,
double sumOfSquaredDeviations,
List<Double> bucketBoundaries,
- List<Bucket> buckets,
- List<Exemplar> exemplars) {
+ List<Bucket> buckets) {
Utils.checkArgument(count >= 0, "count should be non-negative.");
Utils.checkArgument(
sumOfSquaredDeviations >= 0, "sum of squared deviations should be non-negative.");
@@ -68,15 +67,12 @@ public abstract class Distribution {
Utils.checkArgument(
sumOfSquaredDeviations == 0, "sum of squared deviations should be 0 if count is 0.");
}
- Utils.checkNotNull(exemplars, "exemplar list should not be null.");
- Utils.checkListElementNotNull(exemplars, "exemplar should not be null.");
return new AutoValue_Distribution(
mean,
count,
sumOfSquaredDeviations,
copyBucketBounds(bucketBoundaries),
- copyBucketCount(buckets),
- Collections.<Exemplar>unmodifiableList(new ArrayList<Exemplar>(exemplars)));
+ copyBucketCount(buckets));
}
private static List<Double> copyBucketBounds(List<Double> bucketBoundaries) {
@@ -168,14 +164,6 @@ public abstract class Distribution {
public abstract List<Bucket> getBuckets();
/**
- * Returns the {@link Exemplar}s associated with histogram buckets.
- *
- * @return the {@code Exemplar}s associated with histogram buckets.
- * @since 0.16
- */
- public abstract List<Exemplar> getExemplars();
-
- /**
* The histogram bucket of the population values.
*
* @since 0.16
@@ -195,7 +183,21 @@ public abstract class Distribution {
*/
public static Bucket create(long count) {
Utils.checkArgument(count >= 0, "bucket count should be non-negative.");
- return new AutoValue_Distribution_Bucket(count);
+ return new AutoValue_Distribution_Bucket(count, null);
+ }
+
+ /**
+ * Creates a {@link Bucket} with an {@link Exemplar}.
+ *
+ * @param count the number of values in each bucket of the histogram.
+ * @param exemplar the {@code Exemplar} of this {@code Bucket}.
+ * @return a {@code Bucket}.
+ * @since 0.16
+ */
+ public static Bucket create(long count, Exemplar exemplar) {
+ Utils.checkArgument(count >= 0, "bucket count should be non-negative.");
+ Utils.checkNotNull(exemplar, "exemplar");
+ return new AutoValue_Distribution_Bucket(count, exemplar);
}
/**
@@ -205,6 +207,17 @@ public abstract class Distribution {
* @since 0.16
*/
public abstract long getCount();
+
+ /**
+ * Returns the {@link Exemplar} associated with the {@link Bucket}, or {@code null} if there
+ * isn't one.
+ *
+ * @return the {@code Exemplar} associated with the {@code Bucket}, or {@code null} if there
+ * isn't one.
+ * @since 0.16
+ */
+ @Nullable
+ public abstract Exemplar getExemplar();
}
/**
diff --git a/metrics/src/test/java/io/opencensus/metrics/DistributionTest.java b/metrics/src/test/java/io/opencensus/metrics/DistributionTest.java
index f381b814..d511e317 100644
--- a/metrics/src/test/java/io/opencensus/metrics/DistributionTest.java
+++ b/metrics/src/test/java/io/opencensus/metrics/DistributionTest.java
@@ -38,35 +38,47 @@ public class DistributionTest {
@Rule public final ExpectedException thrown = ExpectedException.none();
- private static final List<Bucket> EMPTY_BUCKET_LIST = Collections.<Bucket>emptyList();
- private static final List<Exemplar> EMPTY_EXEMPLAR_LIST = Collections.<Exemplar>emptyList();
- private static final Timestamp TIMESTAMP_1 = Timestamp.create(1, 0);
- private static final Timestamp TIMESTAMP_2 = Timestamp.create(2, 0);
+ private static final Timestamp TIMESTAMP = Timestamp.create(1, 0);
private static final Map<String, String> ATTACHMENTS = Collections.singletonMap("key", "value");
@Test
public void createAndGet_Bucket() {
Bucket bucket = Bucket.create(98);
assertThat(bucket.getCount()).isEqualTo(98);
+ assertThat(bucket.getExemplar()).isNull();
+ }
+
+ @Test
+ public void createAndGet_BucketWithExemplar() {
+ Exemplar exemplar = Exemplar.create(12.2, TIMESTAMP, ATTACHMENTS);
+ Bucket bucket = Bucket.create(7, exemplar);
+ assertThat(bucket.getCount()).isEqualTo(7);
+ assertThat(bucket.getExemplar()).isEqualTo(exemplar);
+ }
+
+ @Test
+ public void createBucket_preventNullExemplar() {
+ thrown.expect(NullPointerException.class);
+ thrown.expectMessage("exemplar");
+ Bucket.create(1, null);
}
@Test
public void createAndGet_Exemplar() {
- Exemplar exemplar = Exemplar.create(-9.9, TIMESTAMP_1, ATTACHMENTS);
+ Exemplar exemplar = Exemplar.create(-9.9, TIMESTAMP, ATTACHMENTS);
assertThat(exemplar.getValue()).isEqualTo(-9.9);
- assertThat(exemplar.getTimestamp()).isEqualTo(TIMESTAMP_1);
+ assertThat(exemplar.getTimestamp()).isEqualTo(TIMESTAMP);
assertThat(exemplar.getAttachments()).isEqualTo(ATTACHMENTS);
}
@Test
public void createAndGet_Distribution() {
- Exemplar exemplar = Exemplar.create(15.0, TIMESTAMP_1, ATTACHMENTS);
+ Exemplar exemplar = Exemplar.create(15.0, TIMESTAMP, ATTACHMENTS);
List<Double> bucketBounds = Arrays.asList(-1.0, 0.0, 1.0);
List<Bucket> buckets =
- Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4));
- Distribution distribution =
- Distribution.create(
- 6.6, 10, 678.54, bucketBounds, buckets, Collections.singletonList(exemplar));
+ Arrays.asList(
+ Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4, exemplar));
+ Distribution distribution = Distribution.create(6.6, 10, 678.54, bucketBounds, buckets);
assertThat(distribution.getMean()).isEqualTo(6.6);
assertThat(distribution.getCount()).isEqualTo(10);
assertThat(distribution.getSumOfSquaredDeviations()).isEqualTo(678.54);
@@ -74,7 +86,6 @@ public class DistributionTest {
.containsExactlyElementsIn(bucketBounds)
.inOrder();
assertThat(distribution.getBuckets()).containsExactlyElementsIn(buckets).inOrder();
- assertThat(distribution.getExemplars()).containsExactly(exemplar);
}
@Test
@@ -88,7 +99,7 @@ public class DistributionTest {
public void createExemplar_PreventNullAttachments() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("attachments");
- Exemplar.create(15, TIMESTAMP_1, null);
+ Exemplar.create(15, TIMESTAMP, null);
}
@Test
@@ -96,7 +107,7 @@ public class DistributionTest {
Map<String, String> attachments = Collections.singletonMap(null, "value");
thrown.expect(NullPointerException.class);
thrown.expectMessage("key of attachment");
- Exemplar.create(15, TIMESTAMP_1, attachments);
+ Exemplar.create(15, TIMESTAMP, attachments);
}
@Test
@@ -104,7 +115,7 @@ public class DistributionTest {
Map<String, String> attachments = Collections.singletonMap("key", null);
thrown.expect(NullPointerException.class);
thrown.expectMessage("value of attachment");
- Exemplar.create(15, TIMESTAMP_1, attachments);
+ Exemplar.create(15, TIMESTAMP, attachments);
}
@Test
@@ -114,7 +125,7 @@ public class DistributionTest {
Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("count should be non-negative.");
- Distribution.create(6.6, -10, 678.54, bucketBounds, buckets, EMPTY_EXEMPLAR_LIST);
+ Distribution.create(6.6, -10, 678.54, bucketBounds, buckets);
}
@Test
@@ -124,7 +135,7 @@ public class DistributionTest {
Arrays.asList(Bucket.create(0), Bucket.create(0), Bucket.create(0), Bucket.create(0));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("sum of squared deviations should be non-negative.");
- Distribution.create(6.6, 0, -678.54, bucketBounds, buckets, EMPTY_EXEMPLAR_LIST);
+ Distribution.create(6.6, 0, -678.54, bucketBounds, buckets);
}
@Test
@@ -134,7 +145,7 @@ public class DistributionTest {
Arrays.asList(Bucket.create(0), Bucket.create(0), Bucket.create(0), Bucket.create(0));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("mean should be 0 if count is 0.");
- Distribution.create(6.6, 0, 0, bucketBounds, buckets, EMPTY_EXEMPLAR_LIST);
+ Distribution.create(6.6, 0, 0, bucketBounds, buckets);
}
@Test
@@ -144,7 +155,7 @@ public class DistributionTest {
Arrays.asList(Bucket.create(0), Bucket.create(0), Bucket.create(0), Bucket.create(0));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("sum of squared deviations should be 0 if count is 0.");
- Distribution.create(0, 0, 678.54, bucketBounds, buckets, EMPTY_EXEMPLAR_LIST);
+ Distribution.create(0, 0, 678.54, bucketBounds, buckets);
}
@Test
@@ -153,7 +164,7 @@ public class DistributionTest {
Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4));
thrown.expect(NullPointerException.class);
thrown.expectMessage("bucketBoundaries list should not be null.");
- Distribution.create(6.6, 10, 678.54, null, buckets, EMPTY_EXEMPLAR_LIST);
+ Distribution.create(6.6, 10, 678.54, null, buckets);
}
@Test
@@ -163,7 +174,7 @@ public class DistributionTest {
Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("bucket boundaries not sorted.");
- Distribution.create(6.6, 10, 678.54, bucketBounds, buckets, EMPTY_EXEMPLAR_LIST);
+ Distribution.create(6.6, 10, 678.54, bucketBounds, buckets);
}
@Test
@@ -171,7 +182,7 @@ public class DistributionTest {
List<Double> bucketBounds = Arrays.asList(-1.0, 0.0, 1.0);
thrown.expect(NullPointerException.class);
thrown.expectMessage("bucket list should not be null.");
- Distribution.create(6.6, 10, 678.54, bucketBounds, null, EMPTY_EXEMPLAR_LIST);
+ Distribution.create(6.6, 10, 678.54, bucketBounds, null);
}
@Test
@@ -181,27 +192,7 @@ public class DistributionTest {
Arrays.asList(Bucket.create(3), Bucket.create(1), null, Bucket.create(4));
thrown.expect(NullPointerException.class);
thrown.expectMessage("bucket should not be null.");
- Distribution.create(6.6, 10, 678.54, bucketBounds, buckets, EMPTY_EXEMPLAR_LIST);
- }
-
- @Test
- public void preventNullExemplarList() {
- thrown.expect(NullPointerException.class);
- thrown.expectMessage("exemplar list should not be null.");
- Distribution.create(1, 1, 1, Collections.<Double>emptyList(), EMPTY_BUCKET_LIST, null);
- }
-
- @Test
- public void preventNullExemplar() {
- thrown.expect(NullPointerException.class);
- thrown.expectMessage("exemplar should not be null.");
- Distribution.create(
- 1,
- 1,
- 1,
- Collections.<Double>emptyList(),
- EMPTY_BUCKET_LIST,
- Collections.<Exemplar>singletonList(null));
+ Distribution.create(6.6, 10, 678.54, bucketBounds, buckets);
}
@Test
@@ -214,25 +205,14 @@ public class DistributionTest {
1,
Arrays.asList(-5.0, 0.0, 5.0),
Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)),
- EMPTY_EXEMPLAR_LIST),
+ Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4))),
Distribution.create(
10,
10,
1,
Arrays.asList(-5.0, 0.0, 5.0),
Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)),
- EMPTY_EXEMPLAR_LIST))
- .addEqualityGroup(
- Distribution.create(
- -7,
- 10,
- 23.456,
- Arrays.asList(-5.0, 0.0, 5.0),
- Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)),
- EMPTY_EXEMPLAR_LIST))
+ Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4))))
.addEqualityGroup(
Distribution.create(
-7,
@@ -240,8 +220,7 @@ public class DistributionTest {
23.456,
Arrays.asList(-5.0, 0.0, 5.0),
Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)),
- Collections.singletonList(Exemplar.create(1.0, TIMESTAMP_2, ATTACHMENTS))))
+ Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4))))
.testEquals();
}
}
diff --git a/metrics/src/test/java/io/opencensus/metrics/PointTest.java b/metrics/src/test/java/io/opencensus/metrics/PointTest.java
index 63b735c1..cb6175c1 100644
--- a/metrics/src/test/java/io/opencensus/metrics/PointTest.java
+++ b/metrics/src/test/java/io/opencensus/metrics/PointTest.java
@@ -21,9 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.common.testing.EqualsTester;
import io.opencensus.common.Timestamp;
import io.opencensus.metrics.Distribution.Bucket;
-import io.opencensus.metrics.Distribution.Exemplar;
import java.util.Arrays;
-import java.util.Collections;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -41,8 +39,8 @@ public class PointTest {
10,
678.54,
Arrays.asList(-1.0, 0.0, 1.0),
- Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)),
- Collections.<Exemplar>emptyList()));
+ Arrays.asList(
+ Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4))));
private static final Timestamp TIMESTAMP_1 = Timestamp.create(1, 2);
private static final Timestamp TIMESTAMP_2 = Timestamp.create(3, 4);
private static final Timestamp TIMESTAMP_3 = Timestamp.create(5, 6);
diff --git a/metrics/src/test/java/io/opencensus/metrics/ValueTest.java b/metrics/src/test/java/io/opencensus/metrics/ValueTest.java
index 85840c8a..63430b28 100644
--- a/metrics/src/test/java/io/opencensus/metrics/ValueTest.java
+++ b/metrics/src/test/java/io/opencensus/metrics/ValueTest.java
@@ -22,13 +22,11 @@ import com.google.common.testing.EqualsTester;
import io.opencensus.common.Function;
import io.opencensus.common.Functions;
import io.opencensus.metrics.Distribution.Bucket;
-import io.opencensus.metrics.Distribution.Exemplar;
import io.opencensus.metrics.Value.ValueDistribution;
import io.opencensus.metrics.Value.ValueDouble;
import io.opencensus.metrics.Value.ValueLong;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,8 +42,7 @@ public class ValueTest {
10,
1,
Arrays.asList(-5.0, 0.0, 5.0),
- Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)),
- Collections.<Exemplar>emptyList());
+ Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)));
@Test
public void createAndGet_ValueDouble() {
@@ -83,8 +80,7 @@ public class ValueTest {
23.456,
Arrays.asList(-5.0, 0.0, 5.0),
Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)),
- Collections.<Exemplar>emptyList())))
+ Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)))))
.testEquals();
}