aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorBogdan Drutu <bdrutu@google.com>2018-11-02 22:46:18 +0100
committerYang Song <songy23@users.noreply.github.com>2018-11-02 14:46:18 -0700
commitffd217631bde90866e98ceb5cd98209f72332642 (patch)
tree2e22d684f0f6e3911a4bbcfa408b7fcbdd8b4328 /api
parentdbcc97b4a383b4f4a730d57467230e4d18ec5771 (diff)
downloadplatform_external_opencensus-java-ffd217631bde90866e98ceb5cd98209f72332642.tar.gz
platform_external_opencensus-java-ffd217631bde90866e98ceb5cd98209f72332642.tar.bz2
platform_external_opencensus-java-ffd217631bde90866e98ceb5cd98209f72332642.zip
Remove min/max from Distribution. (#1542)
* Remove min/max from Distribution. * Add changelog entry.
Diffstat (limited to 'api')
-rw-r--r--api/src/main/java/io/opencensus/stats/AggregationData.java77
-rw-r--r--api/src/test/java/io/opencensus/stats/AggregationDataTest.java44
-rw-r--r--api/src/test/java/io/opencensus/stats/ViewDataTest.java4
3 files changed, 77 insertions, 48 deletions
diff --git a/api/src/main/java/io/opencensus/stats/AggregationData.java b/api/src/main/java/io/opencensus/stats/AggregationData.java
index c6e12b67..795c4178 100644
--- a/api/src/main/java/io/opencensus/stats/AggregationData.java
+++ b/api/src/main/java/io/opencensus/stats/AggregationData.java
@@ -275,7 +275,10 @@ public abstract class AggregationData {
* @param exemplars the exemplars associated with histogram buckets.
* @return a {@code DistributionData}.
* @since 0.16
+ * @deprecated since 0.17. Use {@link #create(double, long, double, List, List)}
*/
+ @Deprecated
+ @SuppressWarnings("InconsistentOverloads")
public static DistributionData create(
double mean,
long count,
@@ -284,17 +287,34 @@ public abstract class AggregationData {
double sumOfSquaredDeviations,
List<Long> bucketCounts,
List<Exemplar> exemplars) {
- if (min != Double.POSITIVE_INFINITY || max != Double.NEGATIVE_INFINITY) {
- Utils.checkArgument(min <= max, "max should be greater or equal to min.");
- }
+ return create(mean, count, sumOfSquaredDeviations, bucketCounts, exemplars);
+ }
- Utils.checkNotNull(bucketCounts, "bucketCounts");
- List<Long> bucketCountsCopy = Collections.unmodifiableList(new ArrayList<Long>(bucketCounts));
- for (Long bucket : bucketCountsCopy) {
- Utils.checkNotNull(bucket, "bucket");
+ /**
+ * Creates a {@code DistributionData}.
+ *
+ * @param mean mean value.
+ * @param count count value.
+ * @param sumOfSquaredDeviations sum of squared deviations.
+ * @param bucketCounts histogram bucket counts.
+ * @param exemplars the exemplars associated with histogram buckets.
+ * @return a {@code DistributionData}.
+ * @since 0.17
+ */
+ public static DistributionData create(
+ double mean,
+ long count,
+ double sumOfSquaredDeviations,
+ List<Long> bucketCounts,
+ List<Exemplar> exemplars) {
+ List<Long> bucketCountsCopy =
+ Collections.unmodifiableList(
+ new ArrayList<Long>(Utils.checkNotNull(bucketCounts, "bucketCounts")));
+ for (Long bucketCount : bucketCountsCopy) {
+ Utils.checkNotNull(bucketCount, "bucketCount");
}
- Utils.checkNotNull(exemplars, "exemplar list should not be null.");
+ Utils.checkNotNull(exemplars, "exemplars");
for (Exemplar exemplar : exemplars) {
Utils.checkNotNull(exemplar, "exemplar");
}
@@ -302,8 +322,6 @@ public abstract class AggregationData {
return new AutoValue_AggregationData_DistributionData(
mean,
count,
- min,
- max,
sumOfSquaredDeviations,
bucketCountsCopy,
Collections.<Exemplar>unmodifiableList(new ArrayList<Exemplar>(exemplars)));
@@ -320,7 +338,10 @@ public abstract class AggregationData {
* @param bucketCounts histogram bucket counts.
* @return a {@code DistributionData}.
* @since 0.8
+ * @deprecated since 0.17. Use {@link #create(double, long, double, List)}.
*/
+ @Deprecated
+ @SuppressWarnings("InconsistentOverloads")
public static DistributionData create(
double mean,
long count,
@@ -329,13 +350,23 @@ public abstract class AggregationData {
double sumOfSquaredDeviations,
List<Long> bucketCounts) {
return create(
- mean,
- count,
- min,
- max,
- sumOfSquaredDeviations,
- bucketCounts,
- Collections.<Exemplar>emptyList());
+ mean, count, sumOfSquaredDeviations, bucketCounts, Collections.<Exemplar>emptyList());
+ }
+
+ /**
+ * Creates a {@code DistributionData}.
+ *
+ * @param mean mean value.
+ * @param count count value.
+ * @param sumOfSquaredDeviations sum of squared deviations.
+ * @param bucketCounts histogram bucket counts.
+ * @return a {@code DistributionData}.
+ * @since 0.17
+ */
+ public static DistributionData create(
+ double mean, long count, double sumOfSquaredDeviations, List<Long> bucketCounts) {
+ return create(
+ mean, count, sumOfSquaredDeviations, bucketCounts, Collections.<Exemplar>emptyList());
}
/**
@@ -359,16 +390,24 @@ public abstract class AggregationData {
*
* @return the minimum of the population values.
* @since 0.8
+ * @deprecated since 0.17. Returns {@code 0}.
*/
- public abstract double getMin();
+ @Deprecated
+ public double getMin() {
+ return 0;
+ }
/**
* Returns the maximum of the population values.
*
* @return the maximum of the population values.
* @since 0.8
+ * @deprecated since 0.17. Returns {@code 0}.
*/
- public abstract double getMax();
+ @Deprecated
+ public double getMax() {
+ return 0;
+ }
/**
* Returns the aggregated sum of squared deviations.
diff --git a/api/src/test/java/io/opencensus/stats/AggregationDataTest.java b/api/src/test/java/io/opencensus/stats/AggregationDataTest.java
index a6d6d1de..38675398 100644
--- a/api/src/test/java/io/opencensus/stats/AggregationDataTest.java
+++ b/api/src/test/java/io/opencensus/stats/AggregationDataTest.java
@@ -55,11 +55,9 @@ public class AggregationDataTest {
@Test
public void testCreateDistributionData() {
DistributionData distributionData =
- DistributionData.create(7.7, 10, 1.1, 9.9, 32.2, Arrays.asList(4L, 1L, 5L));
+ DistributionData.create(7.7, 10, 32.2, Arrays.asList(4L, 1L, 5L));
assertThat(distributionData.getMean()).isWithin(TOLERANCE).of(7.7);
assertThat(distributionData.getCount()).isEqualTo(10);
- assertThat(distributionData.getMin()).isWithin(TOLERANCE).of(1.1);
- assertThat(distributionData.getMax()).isWithin(TOLERANCE).of(9.9);
assertThat(distributionData.getSumOfSquaredDeviations()).isWithin(TOLERANCE).of(32.2);
assertThat(distributionData.getBucketCounts()).containsExactly(4L, 1L, 5L).inOrder();
}
@@ -70,14 +68,14 @@ public class AggregationDataTest {
Exemplar exemplar2 = Exemplar.create(1, TIMESTAMP_1, ATTACHMENTS);
DistributionData distributionData =
DistributionData.create(
- 7.7, 10, 1.1, 9.9, 32.2, Arrays.asList(4L, 1L), Arrays.asList(exemplar1, exemplar2));
+ 7.7, 10, 32.2, Arrays.asList(4L, 1L), Arrays.asList(exemplar1, exemplar2));
assertThat(distributionData.getExemplars()).containsExactly(exemplar1, exemplar2).inOrder();
}
@Test
public void testExemplar() {
Exemplar exemplar = Exemplar.create(15.0, TIMESTAMP_1, ATTACHMENTS);
- assertThat(exemplar.getValue()).isEqualTo(15.0);
+ assertThat(exemplar.getValue()).isWithin(TOLERANCE).of(15.0);
assertThat(exemplar.getTimestamp()).isEqualTo(TIMESTAMP_1);
assertThat(exemplar.getAttachments()).isEqualTo(ATTACHMENTS);
}
@@ -109,21 +107,21 @@ public class AggregationDataTest {
public void preventNullBucketCountList() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("bucketCounts");
- DistributionData.create(1, 1, 1, 1, 0, null);
+ DistributionData.create(1, 1, 0, null);
}
@Test
public void preventNullBucket() {
thrown.expect(NullPointerException.class);
- thrown.expectMessage("bucket");
- DistributionData.create(1, 1, 1, 1, 0, Arrays.asList(0L, 1L, null));
+ thrown.expectMessage("bucketCount");
+ DistributionData.create(1, 1, 0, Arrays.asList(0L, 1L, null));
}
@Test
public void preventNullExemplarList() {
thrown.expect(NullPointerException.class);
- thrown.expectMessage("exemplar list should not be null.");
- DistributionData.create(1, 1, 1, 1, 0, Arrays.asList(0L, 1L, 1L), null);
+ thrown.expectMessage("exemplars");
+ DistributionData.create(1, 1, 0, Arrays.asList(0L, 1L, 1L), null);
}
@Test
@@ -131,14 +129,7 @@ public class AggregationDataTest {
thrown.expect(NullPointerException.class);
thrown.expectMessage("exemplar");
DistributionData.create(
- 1, 1, 1, 1, 0, Arrays.asList(0L, 1L, 1L), Collections.<Exemplar>singletonList(null));
- }
-
- @Test
- public void preventMinIsGreaterThanMax() {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("max should be greater or equal to min.");
- DistributionData.create(1, 1, 10, 1, 0, Arrays.asList(0L, 1L, 0L));
+ 1, 1, 0, Arrays.asList(0L, 1L, 1L), Collections.<Exemplar>singletonList(null));
}
@Test
@@ -150,14 +141,13 @@ public class AggregationDataTest {
.addEqualityGroup(CountData.create(40), CountData.create(40))
.addEqualityGroup(CountData.create(80), CountData.create(80))
.addEqualityGroup(
- DistributionData.create(10, 10, 1, 1, 0, Arrays.asList(0L, 10L, 0L)),
- DistributionData.create(10, 10, 1, 1, 0, Arrays.asList(0L, 10L, 0L)))
- .addEqualityGroup(DistributionData.create(10, 10, 1, 1, 0, Arrays.asList(0L, 10L, 100L)))
- .addEqualityGroup(DistributionData.create(110, 10, 1, 1, 0, Arrays.asList(0L, 10L, 0L)))
- .addEqualityGroup(DistributionData.create(10, 110, 1, 1, 0, Arrays.asList(0L, 10L, 0L)))
- .addEqualityGroup(DistributionData.create(10, 10, -1, 1, 0, Arrays.asList(0L, 10L, 0L)))
- .addEqualityGroup(DistributionData.create(10, 10, 1, 5, 0, Arrays.asList(0L, 10L, 0L)))
- .addEqualityGroup(DistributionData.create(10, 10, 1, 1, 55.5, Arrays.asList(0L, 10L, 0L)))
+ DistributionData.create(10, 10, 0, Arrays.asList(0L, 10L, 0L)),
+ DistributionData.create(10, 10, 0, Arrays.asList(0L, 10L, 0L)))
+ .addEqualityGroup(DistributionData.create(10, 10, 0, Arrays.asList(0L, 10L, 100L)))
+ .addEqualityGroup(DistributionData.create(110, 10, 0, Arrays.asList(0L, 10L, 0L)))
+ .addEqualityGroup(DistributionData.create(10, 110, 0, Arrays.asList(0L, 10L, 0L)))
+ .addEqualityGroup(DistributionData.create(10, 10, 10, Arrays.asList(0L, 10L, 0L)))
+ .addEqualityGroup(DistributionData.create(10, 10, 0, Arrays.asList(0L, 110L, 0L)))
.addEqualityGroup(MeanData.create(5.0, 1), MeanData.create(5.0, 1))
.addEqualityGroup(MeanData.create(-5.0, 1), MeanData.create(-5.0, 1))
.addEqualityGroup(LastValueDataDouble.create(20.0), LastValueDataDouble.create(20.0))
@@ -172,7 +162,7 @@ public class AggregationDataTest {
SumDataDouble.create(10.0),
SumDataLong.create(100000000),
CountData.create(40),
- DistributionData.create(1, 1, 1, 1, 0, Arrays.asList(0L, 10L, 0L)),
+ DistributionData.create(1, 1, 0, Arrays.asList(0L, 10L, 0L)),
LastValueDataDouble.create(20.0),
LastValueDataLong.create(200000000L));
diff --git a/api/src/test/java/io/opencensus/stats/ViewDataTest.java b/api/src/test/java/io/opencensus/stats/ViewDataTest.java
index 0120ffea..ccd12a69 100644
--- a/api/src/test/java/io/opencensus/stats/ViewDataTest.java
+++ b/api/src/test/java/io/opencensus/stats/ViewDataTest.java
@@ -285,9 +285,9 @@ public final class ViewDataTest {
private static final ImmutableMap<List<TagValue>, DistributionData> ENTRIES =
ImmutableMap.of(
Arrays.asList(V1, V2),
- DistributionData.create(1, 1, 1, 1, 0, Arrays.asList(0L, 1L, 0L)),
+ DistributionData.create(1, 1, 0, Arrays.asList(0L, 1L, 0L)),
Arrays.asList(V10, V20),
- DistributionData.create(-5, 6, -20, 5, 100.1, Arrays.asList(5L, 0L, 1L)));
+ DistributionData.create(-5, 6, 100.1, Arrays.asList(5L, 0L, 1L)));
// name
private static final View.Name NAME = View.Name.create("test-view");