Search in sources :

Example 11 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method testRecordIntervalMultipleTagValues.

@Test
public void testRecordIntervalMultipleTagValues() {
    // The interval is 10 seconds, i.e. values should expire after 10 seconds.
    View view = View.create(VIEW_NAME, VIEW_DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), Interval.create(TEN_SECONDS));
    // Start at 10s
    clock.setTime(Timestamp.create(10, 0));
    viewManager.registerView(view);
    // record for TagValue1 at 11s
    clock.setTime(Timestamp.fromMillis(11 * MILLIS_PER_SECOND));
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 10.0).record(tagger.emptyBuilder().put(KEY, VALUE).build());
    // record for TagValue2 at 15s
    clock.setTime(Timestamp.fromMillis(15 * MILLIS_PER_SECOND));
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 30.0).record(tagger.emptyBuilder().put(KEY, VALUE_2).build());
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 50.0).record(tagger.emptyBuilder().put(KEY, VALUE_2).build());
    // get ViewData at 19s, no stats should have expired.
    clock.setTime(Timestamp.fromMillis(19 * MILLIS_PER_SECOND));
    ViewData viewData1 = viewManager.getView(VIEW_NAME);
    StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 10.0), Arrays.asList(VALUE_2), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 30.0, 50.0)), EPSILON);
    // record for TagValue2 again at 20s
    clock.setTime(Timestamp.fromMillis(20 * MILLIS_PER_SECOND));
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 40.0).record(tagger.emptyBuilder().put(KEY, VALUE_2).build());
    // get ViewData at 25s, stats for TagValue1 should have expired.
    clock.setTime(Timestamp.fromMillis(25 * MILLIS_PER_SECOND));
    ViewData viewData2 = viewManager.getView(VIEW_NAME);
    StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE_2), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 30.0, 50.0, 40.0)), EPSILON);
    // get ViewData at 30s, the first two values for TagValue2 should have expired.
    clock.setTime(Timestamp.fromMillis(30 * MILLIS_PER_SECOND));
    ViewData viewData3 = viewManager.getView(VIEW_NAME);
    StatsTestUtil.assertAggregationMapEquals(viewData3.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE_2), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 40.0)), EPSILON);
    // get ViewData at 40s, all stats should have expired.
    clock.setTime(Timestamp.fromMillis(40 * MILLIS_PER_SECOND));
    ViewData viewData4 = viewManager.getView(VIEW_NAME);
    assertThat(viewData4.getAggregationMap()).isEmpty();
}
Also used : StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 12 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method testGetCumulativeViewDataWithEmptyBucketBoundaries.

@Test
public void testGetCumulativeViewDataWithEmptyBucketBoundaries() {
    Aggregation noHistogram = Distribution.create(BucketBoundaries.create(Collections.<Double>emptyList()));
    View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, noHistogram, Arrays.asList(KEY));
    clock.setTime(Timestamp.create(1, 0));
    viewManager.registerView(view);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(KEY, VALUE).build());
    clock.setTime(Timestamp.create(3, 0));
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertThat(viewData.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 0), Timestamp.create(3, 0)));
    StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(noHistogram, MEASURE_DOUBLE, 1.1)), EPSILON);
}
Also used : Aggregation(io.opencensus.stats.Aggregation) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) MeasureDouble(io.opencensus.stats.Measure.MeasureDouble) SumDataDouble(io.opencensus.stats.AggregationData.SumDataDouble) LastValueDataDouble(io.opencensus.stats.AggregationData.LastValueDataDouble) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 13 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method testRecordCumulative.

private void testRecordCumulative(Measure measure, Aggregation aggregation, double... values) {
    View view = createCumulativeView(VIEW_NAME, measure, aggregation, Arrays.asList(KEY));
    clock.setTime(Timestamp.create(1, 2));
    viewManager.registerView(view);
    TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
    for (double val : values) {
        putToMeasureMap(statsRecorder.newMeasureMap(), measure, val).record(tags);
    }
    clock.setTime(Timestamp.create(3, 4));
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertThat(viewData.getView()).isEqualTo(view);
    assertThat(viewData.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 2), Timestamp.create(3, 4)));
    StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(aggregation, measure, values)), EPSILON);
}
Also used : TagContext(io.opencensus.tags.TagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View)

Example 14 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class MutableViewDataTest method testTimeRewindsOnCountViewNoThrow.

@Test
public void testTimeRewindsOnCountViewNoThrow() {
    // First we set up some buckets THEN we rewind time for giggles.
    View tester = View.create(View.Name.create("view"), "Description", MeasureDouble.create("name", "desc", "us"), Count.create(), Collections.singletonList(TagKey.create("KEY")));
    Timestamp start = Timestamp.create(10000000, 0);
    Timestamp validPointTime = Timestamp.create(10000010, 0);
    CurrentState.State state = CurrentState.State.ENABLED;
    MutableViewData viewData = MutableViewData.create(tester, start);
    // Create a data points to get thrown away.
    viewData.record(TagMapImpl.EMPTY, 1.0, validPointTime, Collections.<String, AttachmentValue>emptyMap());
    // Rewind time and look for explosions.
    Timestamp thePast = Timestamp.create(0, 0);
    ViewData result = viewData.toViewData(thePast, state);
    assertThat(result.getAggregationMap()).isEmpty();
}
Also used : ViewData(io.opencensus.stats.ViewData) CurrentState(io.opencensus.implcore.internal.CurrentState) View(io.opencensus.stats.View) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 15 with ViewData

use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.

the class MutableViewDataTest method testTimeRewindsOnDistributionViewNoThrow.

@Test
public void testTimeRewindsOnDistributionViewNoThrow() {
    // First we set up some buckets THEN we rewind time for giggles.
    Aggregation latencyDistribution = Distribution.create(BucketBoundaries.create(Arrays.asList(0.0, 25.0, 100.0, 200.0, 400.0, 800.0, 10000.0)));
    View tester = View.create(View.Name.create("view"), "Description", MeasureDouble.create("name", "desc", "us"), latencyDistribution, Collections.singletonList(TagKey.create("KEY")));
    Timestamp start = Timestamp.create(10000000, 0);
    Timestamp validPointTime = Timestamp.create(10000010, 0);
    CurrentState.State state = CurrentState.State.ENABLED;
    MutableViewData viewData = MutableViewData.create(tester, start);
    // Create a data points to get thrown away.
    viewData.record(TagMapImpl.EMPTY, 1.0, validPointTime, Collections.<String, AttachmentValue>emptyMap());
    // Rewind time and look for explosions.
    Timestamp thePast = Timestamp.create(0, 0);
    ViewData result = viewData.toViewData(thePast, state);
    assertThat(result.getAggregationMap()).isEmpty();
}
Also used : Aggregation(io.opencensus.stats.Aggregation) ViewData(io.opencensus.stats.ViewData) CurrentState(io.opencensus.implcore.internal.CurrentState) View(io.opencensus.stats.View) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Aggregations

ViewData (io.opencensus.stats.ViewData)27 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)21 Test (org.junit.Test)20 View (io.opencensus.stats.View)18 TagContext (io.opencensus.tags.TagContext)5 SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)4 Timestamp (io.opencensus.common.Timestamp)3 MeasureMap (io.opencensus.stats.MeasureMap)3 CurrentState (io.opencensus.implcore.internal.CurrentState)2 Aggregation (io.opencensus.stats.Aggregation)2 DistributionData (io.opencensus.stats.AggregationData.DistributionData)2 TagValue (io.opencensus.tags.TagValue)2 ImmutableList (com.google.common.collect.ImmutableList)1 Context (io.grpc.Context)1 Scope (io.opencensus.common.Scope)1 Exemplar (io.opencensus.metrics.data.Exemplar)1 AggregationData (io.opencensus.stats.AggregationData)1 CountData (io.opencensus.stats.AggregationData.CountData)1 LastValueDataDouble (io.opencensus.stats.AggregationData.LastValueDataDouble)1 SumDataDouble (io.opencensus.stats.AggregationData.SumDataDouble)1