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);
}
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);
}
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();
}
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();
}
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();
}
Aggregations