Search in sources :

Example 1 with Timestamp

use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.

the class ViewDataTest method testCumulativeViewData.

@Test
public void testCumulativeViewData() {
    View view = View.create(NAME, DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, TAG_KEYS, CUMULATIVE);
    Timestamp start = Timestamp.fromMillis(1000);
    Timestamp end = Timestamp.fromMillis(2000);
    AggregationWindowData windowData = CumulativeData.create(start, end);
    ViewData viewData = ViewData.create(view, ENTRIES, windowData);
    assertThat(viewData.getView()).isEqualTo(view);
    assertThat(viewData.getAggregationMap()).isEqualTo(ENTRIES);
    assertThat(viewData.getWindowData()).isEqualTo(windowData);
}
Also used : AggregationWindowData(io.opencensus.stats.ViewData.AggregationWindowData) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 2 with Timestamp

use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.

the class ViewDataTest method testAggregationWindowDataMatch.

@Test
public void testAggregationWindowDataMatch() {
    final Timestamp start = Timestamp.fromMillis(1000);
    final Timestamp end = Timestamp.fromMillis(2000);
    final AggregationWindowData windowData1 = CumulativeData.create(start, end);
    final AggregationWindowData windowData2 = IntervalData.create(end);
    windowData1.match(new Function<CumulativeData, Void>() {

        @Override
        public Void apply(CumulativeData windowData) {
            assertThat(windowData.getStart()).isEqualTo(start);
            assertThat(windowData.getEnd()).isEqualTo(end);
            return null;
        }
    }, new Function<IntervalData, Void>() {

        @Override
        public Void apply(IntervalData windowData) {
            fail("CumulativeData expected.");
            return null;
        }
    }, Functions.<Void>throwIllegalArgumentException());
    windowData2.match(new Function<CumulativeData, Void>() {

        @Override
        public Void apply(CumulativeData windowData) {
            fail("IntervalData expected.");
            return null;
        }
    }, new Function<IntervalData, Void>() {

        @Override
        public Void apply(IntervalData windowData) {
            assertThat(windowData.getEnd()).isEqualTo(end);
            return null;
        }
    }, Functions.<Void>throwIllegalArgumentException());
}
Also used : AggregationWindowData(io.opencensus.stats.ViewData.AggregationWindowData) Timestamp(io.opencensus.common.Timestamp) IntervalData(io.opencensus.stats.ViewData.AggregationWindowData.IntervalData) CumulativeData(io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData) Test(org.junit.Test)

Example 3 with Timestamp

use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.

the class ViewDataTest method testIntervalViewData.

@Test
public void testIntervalViewData() {
    View view = View.create(NAME, DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, TAG_KEYS, INTERVAL_HOUR);
    Timestamp end = Timestamp.fromMillis(2000);
    AggregationWindowData windowData = IntervalData.create(end);
    ViewData viewData = ViewData.create(view, ENTRIES, windowData);
    assertThat(viewData.getView()).isEqualTo(view);
    assertThat(viewData.getAggregationMap()).isEqualTo(ENTRIES);
    assertThat(viewData.getWindowData()).isEqualTo(windowData);
}
Also used : AggregationWindowData(io.opencensus.stats.ViewData.AggregationWindowData) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 4 with Timestamp

use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.

the class OcAgentNodeUtils method getNodeInfo.

// Creates a Node with information from the OpenCensus library and environment variables.
static Node getNodeInfo(String serviceName) {
    String jvmName = ManagementFactory.getRuntimeMXBean().getName();
    Timestamp censusTimestamp = Timestamp.fromMillis(System.currentTimeMillis());
    return Node.newBuilder().setIdentifier(getProcessIdentifier(jvmName, censusTimestamp)).setLibraryInfo(getLibraryInfo(OpenCensusLibraryInformation.VERSION)).setServiceInfo(getServiceInfo(serviceName)).build();
}
Also used : Timestamp(io.opencensus.common.Timestamp)

Example 5 with Timestamp

use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.

the class MutableAggregationTest method testAdd_DistributionWithExemplarAttachments.

@Test
public void testAdd_DistributionWithExemplarAttachments() {
    MutableDistribution mutableDistribution = MutableDistribution.create(BUCKET_BOUNDARIES);
    MutableDistribution mutableDistributionNoHistogram = MutableDistribution.create(BUCKET_BOUNDARIES_EMPTY);
    List<Double> values = Arrays.asList(-1.0, 1.0, -5.0, 20.0, 5.0);
    List<Map<String, AttachmentValue>> attachmentsList = ImmutableList.<Map<String, AttachmentValue>>of(Collections.<String, AttachmentValue>singletonMap("k1", ATTACHMENT_VALUE_1), Collections.<String, AttachmentValue>singletonMap("k2", ATTACHMENT_VALUE_2), Collections.<String, AttachmentValue>singletonMap("k3", ATTACHMENT_VALUE_3), Collections.<String, AttachmentValue>singletonMap("k4", ATTACHMENT_VALUE_4), Collections.<String, AttachmentValue>singletonMap("k5", ATTACHMENT_VALUE_5));
    List<Timestamp> timestamps = Arrays.asList(Timestamp.fromMillis(500), Timestamp.fromMillis(1000), Timestamp.fromMillis(2000), Timestamp.fromMillis(3000), Timestamp.fromMillis(4000));
    for (int i = 0; i < values.size(); i++) {
        mutableDistribution.add(values.get(i), attachmentsList.get(i), timestamps.get(i));
        mutableDistributionNoHistogram.add(values.get(i), attachmentsList.get(i), timestamps.get(i));
    }
    // Each bucket can only have up to one exemplar. If there are more than one exemplars in a
    // bucket, only the last one will be kept.
    List<Exemplar> expected = Arrays.<Exemplar>asList(Exemplar.create(values.get(4), timestamps.get(4), attachmentsList.get(4)), Exemplar.create(values.get(3), timestamps.get(3), attachmentsList.get(3)));
    assertThat(mutableDistribution.getExemplars()).asList().containsExactlyElementsIn(expected).inOrder();
    assertThat(mutableDistributionNoHistogram.getExemplars()).isNull();
}
Also used : Exemplar(io.opencensus.metrics.data.Exemplar) MutableDistribution(io.opencensus.implcore.stats.MutableAggregation.MutableDistribution) MutableLastValueDouble(io.opencensus.implcore.stats.MutableAggregation.MutableLastValueDouble) MutableSumDouble(io.opencensus.implcore.stats.MutableAggregation.MutableSumDouble) SumDataDouble(io.opencensus.stats.AggregationData.SumDataDouble) LastValueDataDouble(io.opencensus.stats.AggregationData.LastValueDataDouble) Map(java.util.Map) Timestamp(io.opencensus.common.Timestamp) Point(io.opencensus.metrics.export.Point) Test(org.junit.Test)

Aggregations

Timestamp (io.opencensus.common.Timestamp)40 Test (org.junit.Test)29 Metric (io.opencensus.metrics.export.Metric)19 ArrayList (java.util.ArrayList)12 TimeSeries (io.opencensus.metrics.export.TimeSeries)8 SpanContext (io.opencensus.trace.SpanContext)6 DoublePoint (io.opencensus.metrics.DoubleCumulative.DoublePoint)4 LabelKey (io.opencensus.metrics.LabelKey)4 LabelValue (io.opencensus.metrics.LabelValue)4 LongPoint (io.opencensus.metrics.LongCumulative.LongPoint)4 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)4 AggregationWindowData (io.opencensus.stats.ViewData.AggregationWindowData)4 View (io.opencensus.stats.View)3 ViewData (io.opencensus.stats.ViewData)3 AttributeValue (io.opencensus.trace.AttributeValue)3 SpanId (io.opencensus.trace.SpanId)3 Status (io.opencensus.trace.Status)3 SpanData (io.opencensus.trace.export.SpanData)3 CurrentState (io.opencensus.implcore.internal.CurrentState)2 CumulativeData (io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData)2