diff options
| author | Yang Song <songy23@users.noreply.github.com> | 2018-04-27 14:47:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-27 14:47:12 -0700 |
| commit | dec25072b4b7671a8ff35f0a121b41eddff5f66f (patch) | |
| tree | f395d21ddce7c2889c987cd46c0bbdcdc469b089 /exporters | |
| parent | 4e62aac18595243b9ed4c98137c24e7413c1dc48 (diff) | |
| download | platform_external_opencensus-java-dec25072b4b7671a8ff35f0a121b41eddff5f66f.tar.gz platform_external_opencensus-java-dec25072b4b7671a8ff35f0a121b41eddff5f66f.tar.bz2 platform_external_opencensus-java-dec25072b4b7671a8ff35f0a121b41eddff5f66f.zip | |
Add Aggregation.LastValue and AggregationData.LastValueData to support Gauge (#1055)
* Add LastValue and LastValueData
* Support LastValue and LastValueData in impl
* Use Utils instead of Precondition
* Add LastValue and remove Mean from match() method.
* Support LastValue and LastValueData in exporters and zpages.
* Update MutableLastValue, add comments on why Mean is still supported.
Diffstat (limited to 'exporters')
6 files changed, 207 insertions, 50 deletions
diff --git a/exporters/stats/prometheus/src/main/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtils.java b/exporters/stats/prometheus/src/main/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtils.java index 14920d7b..e745b594 100644 --- a/exporters/stats/prometheus/src/main/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtils.java +++ b/exporters/stats/prometheus/src/main/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtils.java @@ -28,6 +28,8 @@ import io.opencensus.stats.Aggregation.Sum; import io.opencensus.stats.AggregationData; import io.opencensus.stats.AggregationData.CountData; import io.opencensus.stats.AggregationData.DistributionData; +import io.opencensus.stats.AggregationData.LastValueDataDouble; +import io.opencensus.stats.AggregationData.LastValueDataLong; import io.opencensus.stats.AggregationData.SumDataDouble; import io.opencensus.stats.AggregationData.SumDataLong; import io.opencensus.stats.View; @@ -56,17 +58,19 @@ import org.checkerframework.checker.nullness.qual.Nullable; * * <p>{@link Aggregation} will be converted to a corresponding Prometheus {@link Type}. {@link Sum} * will be {@link Type#UNTYPED}, {@link Count} will be {@link Type#COUNTER}, {@link - * Aggregation.Mean} will be {@link Type#SUMMARY} and {@link Distribution} will be {@link - * Type#HISTOGRAM}. Please note we cannot set bucket boundaries for custom {@link Type#HISTOGRAM}. + * Aggregation.Mean} will be {@link Type#SUMMARY}, {@link Aggregation.LastValue} will be {@link + * Type#GAUGE} and {@link Distribution} will be {@link Type#HISTOGRAM}. Please note we cannot set + * bucket boundaries for custom {@link Type#HISTOGRAM}. * * <p>Each OpenCensus {@link ViewData} will be converted to a Prometheus {@link * MetricFamilySamples}, and each {@code Row} of the {@link ViewData} will be converted to * Prometheus {@link Sample}s. * - * <p>{@link SumDataDouble}, {@link SumDataLong} and {@link CountData} will be converted to a single - * {@link Sample}. {@link AggregationData.MeanData} will be converted to two {@link Sample}s sum and - * count. {@link DistributionData} will be converted to a list of {@link Sample}s that have the sum, - * count and histogram buckets. + * <p>{@link SumDataDouble}, {@link SumDataLong}, {@link LastValueDataDouble}, {@link + * LastValueDataLong} and {@link CountData} will be converted to a single {@link Sample}. {@link + * AggregationData.MeanData} will be converted to two {@link Sample}s sum and count. {@link + * DistributionData} will be converted to a list of {@link Sample}s that have the sum, count and + * histogram buckets. * * <p>{@link TagKey} and {@link TagValue} will be converted to Prometheus {@code LabelName} and * {@code LabelValue}. {@code Null} {@link TagValue} will be converted to an empty string. @@ -116,9 +120,17 @@ final class PrometheusExportUtils { return aggregation.match( Functions.returnConstant(Type.UNTYPED), // SUM Functions.returnConstant(Type.COUNTER), // COUNT - Functions.returnConstant(Type.SUMMARY), // MEAN Functions.returnConstant(Type.HISTOGRAM), // DISTRIBUTION - Functions.returnConstant(Type.UNTYPED)); + Functions.returnConstant(Type.GAUGE), // LAST VALUE + new Function<Aggregation, Type>() { + @Override + public Type apply(Aggregation arg) { + if (arg instanceof Aggregation.Mean) { + return Type.SUMMARY; + } + return Type.UNTYPED; + } + }); } @VisibleForTesting @@ -162,21 +174,6 @@ final class PrometheusExportUtils { return null; } }, - new Function<AggregationData.MeanData, Void>() { - @Override - public Void apply(AggregationData.MeanData arg) { - samples.add( - new MetricFamilySamples.Sample( - name + SAMPLE_SUFFIX_COUNT, labelNames, labelValues, arg.getCount())); - samples.add( - new MetricFamilySamples.Sample( - name + SAMPLE_SUFFIX_SUM, - labelNames, - labelValues, - arg.getCount() * arg.getMean())); - return null; - } - }, new Function<DistributionData, Void>() { @Override public Void apply(DistributionData arg) { @@ -197,7 +194,42 @@ final class PrometheusExportUtils { return null; } }, - Functions.</*@Nullable*/ Void>throwAssertionError()); + new Function<LastValueDataDouble, Void>() { + @Override + public Void apply(LastValueDataDouble arg) { + samples.add(new Sample(name, labelNames, labelValues, arg.getLastValue())); + return null; + } + }, + new Function<LastValueDataLong, Void>() { + @Override + public Void apply(LastValueDataLong arg) { + samples.add(new Sample(name, labelNames, labelValues, arg.getLastValue())); + return null; + } + }, + new Function<AggregationData, Void>() { + @Override + public Void apply(AggregationData arg) { + // TODO(songya): remove this once Mean aggregation is completely removed. Before that + // we need to continue supporting Mean, since it could still be used by users and some + // deprecated RPC views. + if (arg instanceof AggregationData.MeanData) { + AggregationData.MeanData meanData = (AggregationData.MeanData) arg; + samples.add( + new MetricFamilySamples.Sample( + name + SAMPLE_SUFFIX_COUNT, labelNames, labelValues, meanData.getCount())); + samples.add( + new MetricFamilySamples.Sample( + name + SAMPLE_SUFFIX_SUM, + labelNames, + labelValues, + meanData.getCount() * meanData.getMean())); + return null; + } + throw new IllegalArgumentException("Unknown Aggregation."); + } + }); return samples; } diff --git a/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtilsTest.java b/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtilsTest.java index 9629328d..507fd3b6 100644 --- a/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtilsTest.java +++ b/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtilsTest.java @@ -28,10 +28,13 @@ import io.opencensus.common.Duration; import io.opencensus.common.Timestamp; import io.opencensus.stats.Aggregation.Count; import io.opencensus.stats.Aggregation.Distribution; +import io.opencensus.stats.Aggregation.LastValue; import io.opencensus.stats.Aggregation.Mean; import io.opencensus.stats.Aggregation.Sum; import io.opencensus.stats.AggregationData.CountData; import io.opencensus.stats.AggregationData.DistributionData; +import io.opencensus.stats.AggregationData.LastValueDataDouble; +import io.opencensus.stats.AggregationData.LastValueDataLong; import io.opencensus.stats.AggregationData.MeanData; import io.opencensus.stats.AggregationData.SumDataDouble; import io.opencensus.stats.AggregationData.SumDataLong; @@ -71,6 +74,7 @@ public class PrometheusExportUtilsTest { private static final BucketBoundaries BUCKET_BOUNDARIES = BucketBoundaries.create(Arrays.asList(-5.0, 0.0, 5.0)); private static final Distribution DISTRIBUTION = Distribution.create(BUCKET_BOUNDARIES); + private static final LastValue LAST_VALUE = LastValue.create(); private static final View.Name VIEW_NAME_1 = View.Name.create("view1"); private static final View.Name VIEW_NAME_2 = View.Name.create("view2"); private static final View.Name VIEW_NAME_3 = View.Name.create("view-3"); @@ -90,6 +94,8 @@ public class PrometheusExportUtilsTest { private static final MeanData MEAN_DATA = MeanData.create(3.4, 22); private static final DistributionData DISTRIBUTION_DATA = DistributionData.create(4.4, 5, -3.2, 15.7, 135.22, Arrays.asList(0L, 2L, 2L, 1L)); + private static final LastValueDataDouble LAST_VALUE_DATA_DOUBLE = LastValueDataDouble.create(7.9); + private static final LastValueDataLong LAST_VALUE_DATA_LONG = LastValueDataLong.create(66666666); private static final View VIEW1 = View.create( VIEW_NAME_1, DESCRIPTION, MEASURE_DOUBLE, COUNT, Arrays.asList(K1, K2), CUMULATIVE); @@ -121,6 +127,7 @@ public class PrometheusExportUtilsTest { assertThat(PrometheusExportUtils.getType(DISTRIBUTION, CUMULATIVE)).isEqualTo(Type.HISTOGRAM); assertThat(PrometheusExportUtils.getType(SUM, CUMULATIVE)).isEqualTo(Type.UNTYPED); assertThat(PrometheusExportUtils.getType(MEAN, CUMULATIVE)).isEqualTo(Type.SUMMARY); + assertThat(PrometheusExportUtils.getType(LAST_VALUE, CUMULATIVE)).isEqualTo(Type.GAUGE); } @Test @@ -190,6 +197,16 @@ public class PrometheusExportUtilsTest { new Sample(SAMPLE_NAME + "_count", Arrays.asList("k1"), Arrays.asList("v1"), 5), new Sample(SAMPLE_NAME + "_sum", Arrays.asList("k1"), Arrays.asList("v1"), 22.0)) .inOrder(); + assertThat( + PrometheusExportUtils.getSamples( + SAMPLE_NAME, Arrays.asList(K1, K2), Arrays.asList(V1, V2), LAST_VALUE_DATA_DOUBLE)) + .containsExactly( + new Sample(SAMPLE_NAME, Arrays.asList("k1", "k2"), Arrays.asList("v1", "v2"), 7.9)); + assertThat( + PrometheusExportUtils.getSamples( + SAMPLE_NAME, Arrays.asList(K3), Arrays.asList(V3), LAST_VALUE_DATA_LONG)) + .containsExactly( + new Sample(SAMPLE_NAME, Arrays.asList("k_3"), Arrays.asList("v-3"), 66666666)); } @Test diff --git a/exporters/stats/signalfx/src/main/java/io/opencensus/exporter/stats/signalfx/SignalFxSessionAdaptor.java b/exporters/stats/signalfx/src/main/java/io/opencensus/exporter/stats/signalfx/SignalFxSessionAdaptor.java index fb0db8a7..2eb75c4c 100644 --- a/exporters/stats/signalfx/src/main/java/io/opencensus/exporter/stats/signalfx/SignalFxSessionAdaptor.java +++ b/exporters/stats/signalfx/src/main/java/io/opencensus/exporter/stats/signalfx/SignalFxSessionAdaptor.java @@ -24,11 +24,12 @@ import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.Datum; import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.Dimension; import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.MetricType; import io.opencensus.common.Function; -import io.opencensus.common.Functions; import io.opencensus.stats.Aggregation; import io.opencensus.stats.AggregationData; import io.opencensus.stats.AggregationData.CountData; import io.opencensus.stats.AggregationData.DistributionData; +import io.opencensus.stats.AggregationData.LastValueDataDouble; +import io.opencensus.stats.AggregationData.LastValueDataLong; import io.opencensus.stats.AggregationData.SumDataDouble; import io.opencensus.stats.AggregationData.SumDataLong; import io.opencensus.stats.View; @@ -88,7 +89,7 @@ final class SignalFxSessionAdaptor { @javax.annotation.Nullable static MetricType getMetricTypeForAggregation( Aggregation aggregation, View.AggregationWindow window) { - if (aggregation instanceof Aggregation.Mean) { + if (aggregation instanceof Aggregation.Mean || aggregation instanceof Aggregation.LastValue) { return MetricType.GAUGE; } else if (aggregation instanceof Aggregation.Count || aggregation instanceof Aggregation.Sum) { if (window instanceof View.AggregationWindow.Cumulative) { @@ -148,13 +149,6 @@ final class SignalFxSessionAdaptor { return null; } }, - new Function<AggregationData.MeanData, Void>() { - @Override - public Void apply(AggregationData.MeanData arg) { - builder.setDoubleValue(arg.getMean()); - return null; - } - }, new Function<DistributionData, Void>() { @Override public Void apply(DistributionData arg) { @@ -162,7 +156,33 @@ final class SignalFxSessionAdaptor { throw new IllegalArgumentException("Distribution aggregations are not supported"); } }, - Functions.</*@Nullable*/ Void>throwIllegalArgumentException()); + new Function<LastValueDataDouble, Void>() { + @Override + public Void apply(LastValueDataDouble arg) { + builder.setDoubleValue(arg.getLastValue()); + return null; + } + }, + new Function<LastValueDataLong, Void>() { + @Override + public Void apply(LastValueDataLong arg) { + builder.setIntValue(arg.getLastValue()); + return null; + } + }, + new Function<AggregationData, Void>() { + @Override + public Void apply(AggregationData arg) { + // TODO(songya): remove this once Mean aggregation is completely removed. Before that + // we need to continue supporting Mean, since it could still be used by users and some + // deprecated RPC views. + if (arg instanceof AggregationData.MeanData) { + builder.setDoubleValue(((AggregationData.MeanData) arg).getMean()); + return null; + } + throw new IllegalArgumentException("Unknown Aggregation."); + } + }); return builder.build(); } } diff --git a/exporters/stats/signalfx/src/test/java/io/opencensus/exporter/stats/signalfx/SignalFxSessionAdaptorTest.java b/exporters/stats/signalfx/src/test/java/io/opencensus/exporter/stats/signalfx/SignalFxSessionAdaptorTest.java index 3ce2e869..34f4dfa7 100644 --- a/exporters/stats/signalfx/src/test/java/io/opencensus/exporter/stats/signalfx/SignalFxSessionAdaptorTest.java +++ b/exporters/stats/signalfx/src/test/java/io/opencensus/exporter/stats/signalfx/SignalFxSessionAdaptorTest.java @@ -34,6 +34,8 @@ import io.opencensus.stats.Aggregation; import io.opencensus.stats.AggregationData; import io.opencensus.stats.AggregationData.CountData; import io.opencensus.stats.AggregationData.DistributionData; +import io.opencensus.stats.AggregationData.LastValueDataDouble; +import io.opencensus.stats.AggregationData.LastValueDataLong; import io.opencensus.stats.AggregationData.MeanData; import io.opencensus.stats.AggregationData.SumDataDouble; import io.opencensus.stats.AggregationData.SumDataLong; @@ -108,6 +110,14 @@ public class SignalFxSessionAdaptorTest { SignalFxSessionAdaptor.getMetricTypeForAggregation( Aggregation.Distribution.create(BucketBoundaries.create(ImmutableList.of(3.15d))), AggregationWindow.Cumulative.create())); + assertEquals( + MetricType.GAUGE, + SignalFxSessionAdaptor.getMetricTypeForAggregation( + Aggregation.LastValue.create(), AggregationWindow.Cumulative.create())); + assertEquals( + MetricType.GAUGE, + SignalFxSessionAdaptor.getMetricTypeForAggregation( + Aggregation.LastValue.create(), AggregationWindow.Interval.create(ONE_SECOND))); } @Test @@ -206,6 +216,26 @@ public class SignalFxSessionAdaptorTest { } @Test + public void createDatumFromLastValueDouble() { + LastValueDataDouble data = LastValueDataDouble.create(12.2); + Datum datum = SignalFxSessionAdaptor.createDatum(data); + assertTrue(datum.hasDoubleValue()); + assertFalse(datum.hasIntValue()); + assertFalse(datum.hasStrValue()); + assertEquals(12.2, datum.getDoubleValue(), 0d); + } + + @Test + public void createDatumFromLastValueLong() { + LastValueDataLong data = LastValueDataLong.create(100000); + Datum datum = SignalFxSessionAdaptor.createDatum(data); + assertFalse(datum.hasDoubleValue()); + assertTrue(datum.hasIntValue()); + assertFalse(datum.hasStrValue()); + assertEquals(100000, datum.getIntValue()); + } + + @Test public void adaptViewIntoDatapoints() { Map<List<TagValue>, AggregationData> map = ImmutableMap.<List<TagValue>, AggregationData>of( diff --git a/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java b/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java index 8dc5f76c..642d39bc 100644 --- a/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java +++ b/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java @@ -44,9 +44,12 @@ import io.opencensus.contrib.monitoredresource.util.MonitoredResource.GcpGkeCont import io.opencensus.contrib.monitoredresource.util.MonitoredResourceUtils; import io.opencensus.contrib.monitoredresource.util.ResourceType; import io.opencensus.stats.Aggregation; +import io.opencensus.stats.Aggregation.LastValue; import io.opencensus.stats.AggregationData; import io.opencensus.stats.AggregationData.CountData; import io.opencensus.stats.AggregationData.DistributionData; +import io.opencensus.stats.AggregationData.LastValueDataDouble; +import io.opencensus.stats.AggregationData.LastValueDataLong; import io.opencensus.stats.AggregationData.SumDataDouble; import io.opencensus.stats.AggregationData.SumDataLong; import io.opencensus.stats.BucketBoundaries; @@ -131,7 +134,7 @@ final class StackdriverExportUtils { .setValueType(ValueType.STRING) .build()); builder.setUnit(createUnit(view.getAggregation(), view.getMeasure())); - builder.setMetricKind(createMetricKind(view.getWindow())); + builder.setMetricKind(createMetricKind(view.getWindow(), view.getAggregation())); builder.setValueType(createValueType(view.getAggregation(), view.getMeasure())); return builder.build(); } @@ -153,7 +156,10 @@ final class StackdriverExportUtils { // Construct a MetricKind from an AggregationWindow @VisibleForTesting - static MetricKind createMetricKind(View.AggregationWindow window) { + static MetricKind createMetricKind(View.AggregationWindow window, Aggregation aggregation) { + if (aggregation instanceof LastValue) { + return MetricKind.GAUGE; + } return window.match( Functions.returnConstant(MetricKind.CUMULATIVE), // Cumulative // TODO(songya): We don't support exporting Interval stats to StackDriver in this version. @@ -167,8 +173,8 @@ final class StackdriverExportUtils { return aggregation.match( Functions.returnConstant(measure.getUnit()), Functions.returnConstant("1"), // Count - Functions.returnConstant(measure.getUnit()), // Mean Functions.returnConstant(measure.getUnit()), // Distribution + Functions.returnConstant(measure.getUnit()), // LastValue Functions.returnConstant(measure.getUnit())); } @@ -183,9 +189,24 @@ final class StackdriverExportUtils { Functions.returnConstant(MetricDescriptor.ValueType.INT64), // Sum Long Functions.returnConstant(MetricDescriptor.ValueType.UNRECOGNIZED))), Functions.returnConstant(MetricDescriptor.ValueType.INT64), // Count - Functions.returnConstant(MetricDescriptor.ValueType.DOUBLE), // Mean Functions.returnConstant(MetricDescriptor.ValueType.DISTRIBUTION), // Distribution - Functions.returnConstant(MetricDescriptor.ValueType.UNRECOGNIZED)); + Functions.returnConstant( + measure.match( + Functions.returnConstant(MetricDescriptor.ValueType.DOUBLE), // LastValue Double + Functions.returnConstant(MetricDescriptor.ValueType.INT64), // LastValue Long + Functions.returnConstant(MetricDescriptor.ValueType.UNRECOGNIZED))), + new Function<Aggregation, MetricDescriptor.ValueType>() { + @Override + public MetricDescriptor.ValueType apply(Aggregation arg) { + // TODO(songya): remove this once Mean aggregation is completely removed. Before that + // we need to continue supporting Mean, since it could still be used by users and some + // deprecated RPC views. + if (arg instanceof Aggregation.Mean) { + return MetricDescriptor.ValueType.DOUBLE; + } + return MetricDescriptor.ValueType.UNRECOGNIZED; + } + }); } // Convert ViewData to a list of TimeSeries, so that ViewData can be uploaded to Stackdriver. @@ -203,7 +224,7 @@ final class StackdriverExportUtils { // Shared fields for all TimeSeries generated from the same ViewData TimeSeries.Builder shared = TimeSeries.newBuilder(); - shared.setMetricKind(createMetricKind(view.getWindow())); + shared.setMetricKind(createMetricKind(view.getWindow(), view.getAggregation())); shared.setResource(monitoredResource); shared.setValueType(createValueType(view.getAggregation(), view.getMeasure())); @@ -301,13 +322,6 @@ final class StackdriverExportUtils { return null; } }, - new Function<AggregationData.MeanData, Void>() { - @Override - public Void apply(AggregationData.MeanData arg) { - builder.setDoubleValue(arg.getMean()); - return null; - } - }, new Function<DistributionData, Void>() { @Override public Void apply(DistributionData arg) { @@ -320,7 +334,33 @@ final class StackdriverExportUtils { return null; } }, - Functions.</*@Nullable*/ Void>throwIllegalArgumentException()); + new Function<LastValueDataDouble, Void>() { + @Override + public Void apply(LastValueDataDouble arg) { + builder.setDoubleValue(arg.getLastValue()); + return null; + } + }, + new Function<LastValueDataLong, Void>() { + @Override + public Void apply(LastValueDataLong arg) { + builder.setInt64Value(arg.getLastValue()); + return null; + } + }, + new Function<AggregationData, Void>() { + @Override + public Void apply(AggregationData arg) { + // TODO(songya): remove this once Mean aggregation is completely removed. Before that + // we need to continue supporting Mean, since it could still be used by users and some + // deprecated RPC views. + if (arg instanceof AggregationData.MeanData) { + builder.setDoubleValue(((AggregationData.MeanData) arg).getMean()); + return null; + } + throw new IllegalArgumentException("Unknown Aggregation"); + } + }); return builder.build(); } diff --git a/exporters/stats/stackdriver/src/test/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtilsTest.java b/exporters/stats/stackdriver/src/test/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtilsTest.java index a78a96ea..7b808c79 100644 --- a/exporters/stats/stackdriver/src/test/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtilsTest.java +++ b/exporters/stats/stackdriver/src/test/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtilsTest.java @@ -35,10 +35,13 @@ import io.opencensus.common.Duration; import io.opencensus.common.Timestamp; import io.opencensus.stats.Aggregation.Count; import io.opencensus.stats.Aggregation.Distribution; +import io.opencensus.stats.Aggregation.LastValue; import io.opencensus.stats.Aggregation.Mean; import io.opencensus.stats.Aggregation.Sum; import io.opencensus.stats.AggregationData.CountData; import io.opencensus.stats.AggregationData.DistributionData; +import io.opencensus.stats.AggregationData.LastValueDataDouble; +import io.opencensus.stats.AggregationData.LastValueDataLong; import io.opencensus.stats.AggregationData.MeanData; import io.opencensus.stats.AggregationData.SumDataDouble; import io.opencensus.stats.AggregationData.SumDataLong; @@ -92,6 +95,7 @@ public class StackdriverExportUtilsTest { private static final Count COUNT = Count.create(); private static final Mean MEAN = Mean.create(); private static final Distribution DISTRIBUTION = Distribution.create(BUCKET_BOUNDARIES); + private static final LastValue LAST_VALUE = LastValue.create(); private static final String PROJECT_ID = "id"; private static final MonitoredResource DEFAULT_RESOURCE = MonitoredResource.newBuilder().setType("global").build(); @@ -116,10 +120,14 @@ public class StackdriverExportUtilsTest { @Test public void createMetricKind() { - assertThat(StackdriverExportUtils.createMetricKind(CUMULATIVE)) + assertThat(StackdriverExportUtils.createMetricKind(CUMULATIVE, SUM)) .isEqualTo(MetricKind.CUMULATIVE); - assertThat(StackdriverExportUtils.createMetricKind(INTERVAL)) + assertThat(StackdriverExportUtils.createMetricKind(INTERVAL, COUNT)) .isEqualTo(MetricKind.UNRECOGNIZED); + assertThat(StackdriverExportUtils.createMetricKind(CUMULATIVE, LAST_VALUE)) + .isEqualTo(MetricKind.GAUGE); + assertThat(StackdriverExportUtils.createMetricKind(INTERVAL, LAST_VALUE)) + .isEqualTo(MetricKind.GAUGE); } @Test @@ -140,6 +148,10 @@ public class StackdriverExportUtilsTest { .isEqualTo(MetricDescriptor.ValueType.DISTRIBUTION); assertThat(StackdriverExportUtils.createValueType(DISTRIBUTION, MEASURE_LONG)) .isEqualTo(MetricDescriptor.ValueType.DISTRIBUTION); + assertThat(StackdriverExportUtils.createValueType(LAST_VALUE, MEASURE_DOUBLE)) + .isEqualTo(MetricDescriptor.ValueType.DOUBLE); + assertThat(StackdriverExportUtils.createValueType(LAST_VALUE, MEASURE_LONG)) + .isEqualTo(MetricDescriptor.ValueType.INT64); } @Test @@ -149,6 +161,8 @@ public class StackdriverExportUtilsTest { assertThat(StackdriverExportUtils.createUnit(MEAN, MEASURE_DOUBLE)).isEqualTo(MEASURE_UNIT); assertThat(StackdriverExportUtils.createUnit(DISTRIBUTION, MEASURE_DOUBLE)) .isEqualTo(MEASURE_UNIT); + assertThat(StackdriverExportUtils.createUnit(LAST_VALUE, MEASURE_DOUBLE)) + .isEqualTo(MEASURE_UNIT); } @Test @@ -288,6 +302,10 @@ public class StackdriverExportUtilsTest { .setDistributionValue( StackdriverExportUtils.createDistribution(distributionData, BUCKET_BOUNDARIES)) .build()); + assertThat(StackdriverExportUtils.createTypedValue(LAST_VALUE, LastValueDataDouble.create(9.9))) + .isEqualTo(TypedValue.newBuilder().setDoubleValue(9.9).build()); + assertThat(StackdriverExportUtils.createTypedValue(LAST_VALUE, LastValueDataLong.create(90000))) + .isEqualTo(TypedValue.newBuilder().setInt64Value(90000).build()); } @Test |
