Search in sources :

Example 1 with DistributionData

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

the class AggregationDataTest method testCreateDistributionDataWithExemplar.

@Test
public void testCreateDistributionDataWithExemplar() {
    Exemplar exemplar1 = Exemplar.create(4, TIMESTAMP_2, ATTACHMENTS);
    Exemplar exemplar2 = Exemplar.create(1, TIMESTAMP_1, ATTACHMENTS);
    DistributionData distributionData = DistributionData.create(7.7, 10, 32.2, Arrays.asList(4L, 1L), Arrays.asList(exemplar1, exemplar2));
    assertThat(distributionData.getExemplars()).containsExactly(exemplar1, exemplar2).inOrder();
}
Also used : Exemplar(io.opencensus.metrics.data.Exemplar) DistributionData(io.opencensus.stats.AggregationData.DistributionData) Test(org.junit.Test)

Example 2 with DistributionData

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

the class AggregationDataTest method testCreateDistributionData.

@Test
public void testCreateDistributionData() {
    DistributionData distributionData = DistributionData.create(7.7, 10, 32.2, Arrays.asList(4L, 1L, 5L));
    assertThat(distributionData.getMean()).isWithin(TOLERANCE).of(7.7);
    assertThat(distributionData.getCount()).isEqualTo(10);
    assertThat(distributionData.getSumOfSquaredDeviations()).isWithin(TOLERANCE).of(32.2);
    assertThat(distributionData.getBucketCounts()).containsExactly(4L, 1L, 5L).inOrder();
}
Also used : DistributionData(io.opencensus.stats.AggregationData.DistributionData) Test(org.junit.Test)

Example 3 with DistributionData

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

use of io.opencensus.stats.AggregationData.DistributionData 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)

Example 5 with DistributionData

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

the class RpczZPageHandler method getStats.

// Gets RPC stats by its view definition, and set it to stats snapshot.
private static void getStats(StatsSnapshot snapshot, AggregationData data, View view, ViewData.AggregationWindowData windowData) {
    if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_VIEW || view == RPC_SERVER_SERVER_LATENCY_VIEW) {
        snapshot.avgLatencyTotal = ((DistributionData) data).getMean();
    } else if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_MINUTE_VIEW || view == RPC_SERVER_SERVER_LATENCY_MINUTE_VIEW) {
        snapshot.avgLatencyLastMinute = ((AggregationData.MeanData) data).getMean();
    } else if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_HOUR_VIEW || view == RPC_SERVER_SERVER_LATENCY_HOUR_VIEW) {
        snapshot.avgLatencyLastHour = ((AggregationData.MeanData) data).getMean();
    } else if (view == RPC_CLIENT_ERROR_COUNT_VIEW || view == RPC_SERVER_ERROR_COUNT_VIEW) {
        snapshot.errorsTotal = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_ERROR_COUNT_MINUTE_VIEW || view == RPC_SERVER_ERROR_COUNT_MINUTE_VIEW) {
        snapshot.errorsLastMinute = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_ERROR_COUNT_HOUR_VIEW || view == RPC_SERVER_ERROR_COUNT_HOUR_VIEW) {
        snapshot.errorsLastHour = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_REQUEST_BYTES_VIEW || view == RPC_SERVER_REQUEST_BYTES_VIEW) {
        DistributionData distributionData = (DistributionData) data;
        snapshot.inputRateTotal = distributionData.getCount() * distributionData.getMean() / BYTES_PER_KB / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } else if (view == RPC_CLIENT_REQUEST_BYTES_MINUTE_VIEW || view == RPC_SERVER_REQUEST_BYTES_MINUTE_VIEW) {
        AggregationData.MeanData meanData = (AggregationData.MeanData) data;
        snapshot.inputRateLastMinute = meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_REQUEST_BYTES_HOUR_VIEW || view == RPC_SERVER_REQUEST_BYTES_HOUR_VIEW) {
        AggregationData.MeanData meanData = (AggregationData.MeanData) data;
        snapshot.inputRateLastHour = meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_VIEW || view == RPC_SERVER_RESPONSE_BYTES_VIEW) {
        DistributionData distributionData = (DistributionData) data;
        snapshot.outputRateTotal = distributionData.getCount() * distributionData.getMean() / BYTES_PER_KB / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_MINUTE_VIEW || view == RPC_SERVER_RESPONSE_BYTES_MINUTE_VIEW) {
        AggregationData.MeanData meanData = (AggregationData.MeanData) data;
        snapshot.outputRateLastMinute = meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_HOUR_VIEW || view == RPC_SERVER_RESPONSE_BYTES_HOUR_VIEW) {
        AggregationData.MeanData meanData = (AggregationData.MeanData) data;
        snapshot.outputRateLastHour = meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_STARTED_COUNT_MINUTE_VIEW || view == RPC_SERVER_STARTED_COUNT_MINUTE_VIEW) {
        snapshot.countLastMinute = ((CountData) data).getCount();
        snapshot.rpcRateLastMinute = snapshot.countLastMinute / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_STARTED_COUNT_HOUR_VIEW || view == RPC_SERVER_STARTED_COUNT_HOUR_VIEW) {
        snapshot.countLastHour = ((CountData) data).getCount();
        snapshot.rpcRateLastHour = snapshot.countLastHour / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_STARTED_COUNT_CUMULATIVE_VIEW || view == RPC_SERVER_STARTED_COUNT_CUMULATIVE_VIEW) {
        snapshot.countTotal = ((CountData) data).getCount();
        snapshot.rpcRateTotal = snapshot.countTotal / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    }
// TODO(songya): compute and store latency percentiles.
}
Also used : DistributionData(io.opencensus.stats.AggregationData.DistributionData) AggregationData(io.opencensus.stats.AggregationData) ViewData(io.opencensus.stats.ViewData) CountData(io.opencensus.stats.AggregationData.CountData)

Aggregations

DistributionData (io.opencensus.stats.AggregationData.DistributionData)6 Test (org.junit.Test)4 ViewData (io.opencensus.stats.ViewData)3 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)2 Exemplar (io.opencensus.metrics.data.Exemplar)2 AggregationData (io.opencensus.stats.AggregationData)2 CountData (io.opencensus.stats.AggregationData.CountData)2 View (io.opencensus.stats.View)2 Distribution (io.opencensus.stats.Aggregation.Distribution)1 LastValueDataDouble (io.opencensus.stats.AggregationData.LastValueDataDouble)1 LastValueDataLong (io.opencensus.stats.AggregationData.LastValueDataLong)1 SumDataDouble (io.opencensus.stats.AggregationData.SumDataDouble)1 SumDataLong (io.opencensus.stats.AggregationData.SumDataLong)1 TagValue (io.opencensus.tags.TagValue)1