Search in sources :

Example 6 with Timestamp

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

the class IntervalBucketTest method preventCallingGetFractionOnPastBuckets.

@Test
public void preventCallingGetFractionOnPastBuckets() {
    IntervalBucket bucket = new IntervalBucket(START, MINUTE, MEAN, MEASURE_DOUBLE);
    Timestamp twoMinutesAfterStart = Timestamp.create(180, 0);
    thrown.expect(IllegalArgumentException.class);
    bucket.getFraction(twoMinutesAfterStart);
}
Also used : Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 7 with Timestamp

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

the class IntervalBucketTest method testGetFraction.

@Test
public void testGetFraction() {
    Timestamp thirtySecondsAfterStart = Timestamp.create(90, 0);
    assertThat(new IntervalBucket(START, MINUTE, MEAN, MEASURE_DOUBLE).getFraction(thirtySecondsAfterStart)).isWithin(TOLERANCE).of(0.5);
}
Also used : Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 8 with Timestamp

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

the class MutableViewDataTest method testTimeRewindsOnCountViewNoThrow.

@Test
public void testTimeRewindsOnCountViewNoThrow() {
    // First we set up some buckets THEN we rewind time for giggles.
    View tester = View.create(View.Name.create("view"), "Description", MeasureDouble.create("name", "desc", "us"), Count.create(), Collections.singletonList(TagKey.create("KEY")));
    Timestamp start = Timestamp.create(10000000, 0);
    Timestamp validPointTime = Timestamp.create(10000010, 0);
    CurrentState.State state = CurrentState.State.ENABLED;
    MutableViewData viewData = MutableViewData.create(tester, start);
    // Create a data points to get thrown away.
    viewData.record(TagMapImpl.EMPTY, 1.0, validPointTime, Collections.<String, AttachmentValue>emptyMap());
    // Rewind time and look for explosions.
    Timestamp thePast = Timestamp.create(0, 0);
    ViewData result = viewData.toViewData(thePast, state);
    assertThat(result.getAggregationMap()).isEmpty();
}
Also used : ViewData(io.opencensus.stats.ViewData) CurrentState(io.opencensus.implcore.internal.CurrentState) View(io.opencensus.stats.View) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 9 with Timestamp

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

the class MutableViewDataTest method testTimeRewindsOnDistributionViewNoThrow.

@Test
public void testTimeRewindsOnDistributionViewNoThrow() {
    // First we set up some buckets THEN we rewind time for giggles.
    Aggregation latencyDistribution = Distribution.create(BucketBoundaries.create(Arrays.asList(0.0, 25.0, 100.0, 200.0, 400.0, 800.0, 10000.0)));
    View tester = View.create(View.Name.create("view"), "Description", MeasureDouble.create("name", "desc", "us"), latencyDistribution, Collections.singletonList(TagKey.create("KEY")));
    Timestamp start = Timestamp.create(10000000, 0);
    Timestamp validPointTime = Timestamp.create(10000010, 0);
    CurrentState.State state = CurrentState.State.ENABLED;
    MutableViewData viewData = MutableViewData.create(tester, start);
    // Create a data points to get thrown away.
    viewData.record(TagMapImpl.EMPTY, 1.0, validPointTime, Collections.<String, AttachmentValue>emptyMap());
    // Rewind time and look for explosions.
    Timestamp thePast = Timestamp.create(0, 0);
    ViewData result = viewData.toViewData(thePast, state);
    assertThat(result.getAggregationMap()).isEmpty();
}
Also used : Aggregation(io.opencensus.stats.Aggregation) ViewData(io.opencensus.stats.ViewData) CurrentState(io.opencensus.implcore.internal.CurrentState) View(io.opencensus.stats.View) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 10 with Timestamp

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

the class StackdriverV2ExporterHandler method generateSpan.

@VisibleForTesting
Span generateSpan(SpanData spanData, Map<String, AttributeValue> resourceLabels, Map<String, AttributeValue> fixedAttributes) {
    SpanContext context = spanData.getContext();
    final String spanIdHex = context.getSpanId().toLowerBase16();
    SpanName spanName = SpanName.newBuilder().setProject(projectId).setTrace(context.getTraceId().toLowerBase16()).setSpan(spanIdHex).build();
    Span.Builder spanBuilder = Span.newBuilder().setName(spanName.toString()).setSpanId(spanIdHex).setDisplayName(toTruncatableStringProto(toDisplayName(spanData.getName(), spanData.getKind()))).setStartTime(toTimestampProto(spanData.getStartTimestamp())).setAttributes(toAttributesProto(spanData.getAttributes(), resourceLabels, fixedAttributes)).setTimeEvents(toTimeEventsProto(spanData.getAnnotations(), spanData.getMessageEvents()));
    io.opencensus.trace.Status status = spanData.getStatus();
    if (status != null) {
        spanBuilder.setStatus(toStatusProto(status));
    }
    Timestamp end = spanData.getEndTimestamp();
    if (end != null) {
        spanBuilder.setEndTime(toTimestampProto(end));
    }
    spanBuilder.setLinks(toLinksProto(spanData.getLinks()));
    Integer childSpanCount = spanData.getChildSpanCount();
    if (childSpanCount != null) {
        spanBuilder.setChildSpanCount(Int32Value.newBuilder().setValue(childSpanCount).build());
    }
    if (spanData.getParentSpanId() != null && spanData.getParentSpanId().isValid()) {
        spanBuilder.setParentSpanId(spanData.getParentSpanId().toLowerBase16());
    }
    /*@Nullable*/
    Boolean hasRemoteParent = spanData.getHasRemoteParent();
    if (hasRemoteParent != null) {
        spanBuilder.setSameProcessAsParentSpan(BoolValue.of(!hasRemoteParent));
    }
    return spanBuilder.build();
}
Also used : SpanName(com.google.devtools.cloudtrace.v2.SpanName) SpanContext(io.opencensus.trace.SpanContext) TruncatableString(com.google.devtools.cloudtrace.v2.TruncatableString) Span(com.google.devtools.cloudtrace.v2.Span) Timestamp(io.opencensus.common.Timestamp) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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