Search in sources :

Example 1 with ViewData

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

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

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

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

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

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