Search in sources :

Example 1 with SimpleTagContext

use of io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method record_UnregisteredMeasure.

@Test
public void record_UnregisteredMeasure() {
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
    viewManager.registerView(view);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE_NO_VIEW_1, 1.0).put(MEASURE_DOUBLE, 2.0).put(MEASURE_DOUBLE_NO_VIEW_2, 3.0).record(new SimpleTagContext(Tag.create(KEY, VALUE)));
    ViewData viewData = viewManager.getView(VIEW_NAME);
    // There should be one entry.
    StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 2.0)), 1e-6);
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 2 with SimpleTagContext

use of io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method record_MapDeprecatedRpcConstants.

@Test
public void record_MapDeprecatedRpcConstants() {
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(RecordUtils.RPC_METHOD));
    viewManager.registerView(view);
    MeasureMap statsRecord = statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0);
    statsRecord.record(new SimpleTagContext(Tag.create(RecordUtils.GRPC_CLIENT_METHOD, VALUE)));
    ViewData viewData = viewManager.getView(VIEW_NAME);
    // There should be two entries.
    StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0)), 1e-6);
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) MeasureMap(io.opencensus.stats.MeasureMap) Test(org.junit.Test)

Example 3 with SimpleTagContext

use of io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method recordTwice.

@Test
public void recordTwice() {
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
    viewManager.registerView(view);
    MeasureMap statsRecord = statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0);
    statsRecord.record(new SimpleTagContext(Tag.create(KEY, VALUE)));
    statsRecord.record(new SimpleTagContext(Tag.create(KEY, VALUE_2)));
    ViewData viewData = viewManager.getView(VIEW_NAME);
    // There should be two entries.
    StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0), Arrays.asList(VALUE_2), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0)), 1e-6);
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) MeasureMap(io.opencensus.stats.MeasureMap) Test(org.junit.Test)

Example 4 with SimpleTagContext

use of io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method record_StatsReenabled.

@Test
@SuppressWarnings("deprecation")
public void record_StatsReenabled() {
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
    viewManager.registerView(view);
    statsComponent.setState(StatsCollectionState.DISABLED);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record(new SimpleTagContext(Tag.create(KEY, VALUE)));
    assertThat(viewManager.getView(VIEW_NAME)).isEqualTo(createEmptyViewData(view));
    statsComponent.setState(StatsCollectionState.ENABLED);
    assertThat(viewManager.getView(VIEW_NAME).getAggregationMap()).isEmpty();
    assertThat(viewManager.getView(VIEW_NAME).getWindowData()).isNotEqualTo(CumulativeData.create(ZERO_TIMESTAMP, ZERO_TIMESTAMP));
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 4.0).record(new SimpleTagContext(Tag.create(KEY, VALUE)));
    StatsTestUtil.assertAggregationMapEquals(viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 4.0)), 1e-6);
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 5 with SimpleTagContext

use of io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext in project instrumentation-java by census-instrumentation.

the class StatsRecorderImplTest method recordWithAttachments.

private void recordWithAttachments() {
    TagContext context = new SimpleTagContext(Tag.create(KEY, VALUE));
    // The test Distribution has bucket boundaries [-10.0, 0.0, 10.0].
    // 1st second.
    testClock.advanceTime(ONE_SECOND);
    // -1.0 is in the 2nd bucket [-10.0, 0.0).
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, -1.0).putAttachment("k1", ATTACHMENT_VALUE_1).record(context);
    // 2nd second.
    testClock.advanceTime(ONE_SECOND);
    // 1.0 is in the 3rd bucket [0.0, 10.0).
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).putAttachment("k2", ATTACHMENT_VALUE_2).record(context);
    // 3rd second.
    testClock.advanceTime(ONE_SECOND);
    // 12.0 is in the 4th bucket [10.0, +Inf).
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 12.0).putAttachment("k1", ATTACHMENT_VALUE_3).record(context);
    // 4th second.
    testClock.advanceTime(ONE_SECOND);
    // -20.0 is in the 1st bucket [-Inf, -10.0).
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, -20.0).putAttachment("k3", ATTACHMENT_VALUE_1).record(context);
    // 5th second.
    testClock.advanceTime(ONE_SECOND);
    // -5.0 is in the 2nd bucket [-10.0, 0), should overwrite the previous exemplar -1.0.
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, -5.0).putAttachment("k3", ATTACHMENT_VALUE_3).record(context);
    // 6th second.
    testClock.advanceTime(ONE_SECOND);
    // -3.0 is in the 2nd bucket [-10.0, 0), but this value doesn't come with attachments, so it
    // shouldn't overwrite the previous exemplar (-5.0).
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, -3.0).record(context);
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) TagContext(io.opencensus.tags.TagContext) SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)

Aggregations

SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)7 View (io.opencensus.stats.View)6 Test (org.junit.Test)6 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)4 ViewData (io.opencensus.stats.ViewData)4 MeasureMap (io.opencensus.stats.MeasureMap)2 TagContext (io.opencensus.tags.TagContext)2 Context (io.grpc.Context)1