Search in sources :

Example 6 with View

use of io.opencensus.stats.View 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 7 with View

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

the class StatsRecorderImplTest method record_WithAttachments_DistributionNoHistogram.

@Test
public void record_WithAttachments_DistributionNoHistogram() {
    testClock.setTime(START_TIME);
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, DISTRIBUTION_NO_HISTOGRAM, Arrays.asList(KEY));
    viewManager.registerView(view);
    recordWithAttachments();
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertThat(viewData).isNotNull();
    DistributionData distributionData = (DistributionData) viewData.getAggregationMap().get(Collections.singletonList(VALUE));
    // Recording exemplar has no effect if there's no histogram.
    assertThat(distributionData.getExemplars()).isEmpty();
}
Also used : DistributionData(io.opencensus.stats.AggregationData.DistributionData) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 8 with View

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

the class StatsRecorderImplTest method record_WithAttachments_Count.

@Test
public void record_WithAttachments_Count() {
    testClock.setTime(START_TIME);
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Count.create(), Arrays.asList(KEY));
    viewManager.registerView(view);
    recordWithAttachments();
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertThat(viewData).isNotNull();
    CountData countData = (CountData) viewData.getAggregationMap().get(Collections.singletonList(VALUE));
    // Recording exemplar does not affect views with an aggregation other than distribution.
    assertThat(countData.getCount()).isEqualTo(2L);
}
Also used : StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) CountData(io.opencensus.stats.AggregationData.CountData) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 9 with View

use of io.opencensus.stats.View 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 10 with View

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

the class StatsRecorderImplTest method record_WithAttachments_Distribution.

@Test
public void record_WithAttachments_Distribution() {
    testClock.setTime(START_TIME);
    View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
    viewManager.registerView(view);
    recordWithAttachments();
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertThat(viewData).isNotNull();
    DistributionData distributionData = (DistributionData) viewData.getAggregationMap().get(Collections.singletonList(VALUE));
    List<Exemplar> expected = Arrays.asList(Exemplar.create(1.0, Timestamp.create(2, 0), Collections.singletonMap("k2", ATTACHMENT_VALUE_2)), Exemplar.create(12.0, Timestamp.create(3, 0), Collections.singletonMap("k1", ATTACHMENT_VALUE_3)));
    assertThat(distributionData.getExemplars()).containsExactlyElementsIn(expected).inOrder();
}
Also used : Exemplar(io.opencensus.metrics.data.Exemplar) DistributionData(io.opencensus.stats.AggregationData.DistributionData) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

Aggregations

View (io.opencensus.stats.View)45 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