Search in sources :

Example 41 with View

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

the class ViewManagerImplTest method settingStateToDisabledWillClearStats_Interval.

@Test
public void settingStateToDisabledWillClearStats_Interval() {
    View intervalView = View.create(VIEW_NAME_2, VIEW_DESCRIPTION, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY), Interval.create(Duration.create(60, 0)));
    settingStateToDisabledWillClearStats(intervalView);
}
Also used : View(io.opencensus.stats.View) Test(org.junit.Test)

Example 42 with View

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

the class ViewManagerImplTest method testRecordInterval.

private final void testRecordInterval(Measure measure, Aggregation aggregation, double[] initialValues, /* There are 5 initial values recorded before we call getView(). */
double value6, double value7, AggregationData expectedValues1, AggregationData expectedValues2, AggregationData expectedValues3) {
    // The interval is 10 seconds, i.e. values should expire after 10 seconds.
    // Each bucket has a duration of 2.5 seconds.
    View view = View.create(VIEW_NAME, VIEW_DESCRIPTION, measure, aggregation, Arrays.asList(KEY), Interval.create(TEN_SECONDS));
    // start at 30s
    long startTimeMillis = 30 * MILLIS_PER_SECOND;
    clock.setTime(Timestamp.fromMillis(startTimeMillis));
    viewManager.registerView(view);
    TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
    for (int i = 1; i <= 5; i++) {
        /*
       * Add each value in sequence, at 31s, 32s, 33s, etc.
       * 1st and 2nd values should fall into the first bucket [30.0, 32.5),
       * 3rd and 4th values should fall into the second bucket [32.5, 35.0),
       * 5th value should fall into the third bucket [35.0, 37.5).
       */
        clock.setTime(Timestamp.fromMillis(startTimeMillis + i * MILLIS_PER_SECOND));
        putToMeasureMap(statsRecorder.newMeasureMap(), measure, initialValues[i - 1]).record(tags);
    }
    clock.setTime(Timestamp.fromMillis(startTimeMillis + 8 * MILLIS_PER_SECOND));
    // 38s, no values should have expired
    StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(aggregation, measure, initialValues)), EPSILON);
    clock.setTime(Timestamp.fromMillis(startTimeMillis + 11 * MILLIS_PER_SECOND));
    // 41s, 40% of the values in the first bucket should have expired (1 / 2.5 = 0.4).
    StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), expectedValues1), EPSILON);
    clock.setTime(Timestamp.fromMillis(startTimeMillis + 12 * MILLIS_PER_SECOND));
    // 42s, add a new value value1, should fall into bucket [40.0, 42.5)
    putToMeasureMap(statsRecorder.newMeasureMap(), measure, value6).record(tags);
    clock.setTime(Timestamp.fromMillis(startTimeMillis + 17 * MILLIS_PER_SECOND));
    // 47s, values in the first and second bucket should have expired, and 80% of values in the
    // third bucket should have expired. The new value should persist.
    StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), expectedValues2), EPSILON);
    clock.setTime(Timestamp.fromMillis(60 * MILLIS_PER_SECOND));
    // 60s, all previous values should have expired, add another value value2
    putToMeasureMap(statsRecorder.newMeasureMap(), measure, value7).record(tags);
    StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), expectedValues3), EPSILON);
    clock.setTime(Timestamp.fromMillis(100 * MILLIS_PER_SECOND));
    // 100s, all values should have expired
    assertThat(viewManager.getView(VIEW_NAME).getAggregationMap()).isEmpty();
}
Also used : TagContext(io.opencensus.tags.TagContext) View(io.opencensus.stats.View)

Example 43 with View

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

the class ViewManagerImplTest method registerRecordAndGetView_StatsDisabled.

@Test
@SuppressWarnings("deprecation")
public void registerRecordAndGetView_StatsDisabled() {
    statsComponent.setState(StatsCollectionState.DISABLED);
    View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY));
    viewManager.registerView(view);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(KEY, VALUE).build());
    assertThat(viewManager.getView(VIEW_NAME)).isEqualTo(createEmptyViewData(view));
}
Also used : View(io.opencensus.stats.View) Test(org.junit.Test)

Example 44 with View

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

the class ViewManagerImplTest method preventRegisteringDifferentViewWithSameName.

@Test
public void preventRegisteringDifferentViewWithSameName() {
    View view1 = View.create(VIEW_NAME, "View description.", MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
    View view2 = View.create(VIEW_NAME, "This is a different description.", MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
    testFailedToRegisterView(view1, view2, "A different view with the same name is already registered");
}
Also used : View(io.opencensus.stats.View) Test(org.junit.Test)

Aggregations

View (io.opencensus.stats.View)44 Test (org.junit.Test)31 ViewData (io.opencensus.stats.ViewData)18 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)15 SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)6 Aggregation (io.opencensus.stats.Aggregation)5 TagContext (io.opencensus.tags.TagContext)5 Timestamp (io.opencensus.common.Timestamp)3 AggregationData (io.opencensus.stats.AggregationData)3 Measure (io.opencensus.stats.Measure)3 MeasureMap (io.opencensus.stats.MeasureMap)3 TagKey (io.opencensus.tags.TagKey)3 TagValue (io.opencensus.tags.TagValue)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CurrentState (io.opencensus.implcore.internal.CurrentState)2 DistributionData (io.opencensus.stats.AggregationData.DistributionData)2 MeasureDouble (io.opencensus.stats.Measure.MeasureDouble)2 ViewManager (io.opencensus.stats.ViewManager)2 ImmutableList (com.google.common.collect.ImmutableList)1