Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving API breaking changes from 0.11.0 to 0.13.1 #63

Merged
merged 4 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ subprojects {
apply plugin: 'signing'

group = "com.google.cloud.opentelemetry"
version = "0.12.0-SNAPSHOT" // CURRENT_VERSION
version = "0.13.1-SNAPSHOT" // CURRENT_VERSION

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -23,8 +23,8 @@ subprojects {
slf4jVersion = '1.7.30'
googleCloudVersion = '1.0.2'
cloudMonitoringVersion = '2.0.1'
openTelemetryVersion = '0.11.0'
openTelemetryInstrumentationVersion = '0.11.0'
openTelemetryVersion = '0.13.1'
openTelemetryInstrumentationVersion = '0.13.1'
junitVersion = '4.13'
mockitoVersion = '3.5.10'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ public CompletableResultCode flush() {
}

@Override
public void shutdown() {
public CompletableResultCode shutdown() {
metricServiceClient.shutdown();

return CompletableResultCode.ofSuccess();
}

static class MetricWithLabels {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.google.cloud.opentelemetry.metric;

import static io.opentelemetry.sdk.metrics.data.MetricData.Type.MONOTONIC_DOUBLE;
import static io.opentelemetry.sdk.metrics.data.MetricData.Type.MONOTONIC_LONG;
import static io.opentelemetry.sdk.metrics.data.MetricData.Type.NON_MONOTONIC_DOUBLE;
import static io.opentelemetry.sdk.metrics.data.MetricData.Type.NON_MONOTONIC_LONG;
import static io.opentelemetry.sdk.metrics.data.MetricData.Type.DOUBLE_GAUGE;
import static io.opentelemetry.sdk.metrics.data.MetricData.Type.DOUBLE_SUM;
import static io.opentelemetry.sdk.metrics.data.MetricData.Type.LONG_GAUGE;
import static io.opentelemetry.sdk.metrics.data.MetricData.Type.LONG_SUM;

import com.google.api.LabelDescriptor;
import com.google.api.Metric;
Expand Down Expand Up @@ -37,10 +37,10 @@ public class MetricTranslator {
static final long NANO_PER_SECOND = (long) 1e9;
static final String METRIC_DESCRIPTOR_TIME_UNIT = "ns";

static final Set<Type> GAUGE_TYPES = ImmutableSet.of(NON_MONOTONIC_LONG, NON_MONOTONIC_DOUBLE);
static final Set<Type> CUMULATIVE_TYPES = ImmutableSet.of(MONOTONIC_LONG, MONOTONIC_DOUBLE);
static final Set<Type> LONG_TYPES = ImmutableSet.of(NON_MONOTONIC_LONG, MONOTONIC_LONG);
static final Set<Type> DOUBLE_TYPES = ImmutableSet.of(NON_MONOTONIC_DOUBLE, MONOTONIC_DOUBLE);
static final Set<Type> GAUGE_TYPES = ImmutableSet.of(LONG_GAUGE, DOUBLE_GAUGE);
static final Set<Type> CUMULATIVE_TYPES = ImmutableSet.of(LONG_SUM, DOUBLE_SUM);
static final Set<Type> LONG_TYPES = ImmutableSet.of(LONG_GAUGE, LONG_SUM);
static final Set<Type> DOUBLE_TYPES = ImmutableSet.of(DOUBLE_GAUGE, DOUBLE_SUM);
private static final int MIN_TIMESTAMP_INTERVAL_NANOS = 1000000;

static Metric mapMetric(MetricData.Point metricPoint, String type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,26 @@ public class FakeData {
Labels.of("label1", "value1", "label2", "False"),
32L);

static final Point aDoublePoint =
MetricData.DoublePoint.create(
1599030114 * NANO_PER_SECOND,
1599031814 * NANO_PER_SECOND,
Labels.of("label1", "value1", "label2", "False"),
32d);

// The name does not have to start with "opentelemetry/", it is set this way because of a bug in
// the mock server,
// and should be changed when the following issue is resolved:
// https://github.com/googleinterns/cloud-operations-api-mock/issues/56
static final MetricData aMetricData =
MetricData.create(
MetricData.createLongSum(
aGceResource,
anInstrumentationLibraryInfo,
"opentelemetry/name",
"description",
"ns",
Type.MONOTONIC_LONG,
ImmutableList.of(aLongPoint));
MetricData.LongSumData.create(
true,
MetricData.AggregationTemporality.CUMULATIVE,
ImmutableList.of(aLongPoint)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.google.cloud.opentelemetry.metric.FakeData.aFakeCredential;
import static com.google.cloud.opentelemetry.metric.FakeData.aGceResource;
import static com.google.cloud.opentelemetry.metric.FakeData.aLongPoint;
import static com.google.cloud.opentelemetry.metric.FakeData.aDoublePoint;
import static com.google.cloud.opentelemetry.metric.FakeData.aMetricData;
import static com.google.cloud.opentelemetry.metric.FakeData.aProjectId;
import static com.google.cloud.opentelemetry.metric.FakeData.anInstrumentationLibraryInfo;
Expand Down Expand Up @@ -153,14 +154,13 @@ public void testExportWithNonSupportedMetricTypeReturnsFailure() {
MetricExporter exporter = MetricExporter.createWithClient(aProjectId, mockClient);

MetricData metricData =
MetricData.create(
MetricData.createDoubleSummary(
aGceResource,
anInstrumentationLibraryInfo,
"Metric Name",
"description",
"ns",
Type.SUMMARY,
ImmutableList.of(aLongPoint));
MetricData.DoubleSummaryData.create(ImmutableList.of(aDoublePoint)));

CompletableResultCode result = exporter.export(ImmutableList.of(metricData));
verify(mockClient, times(0)).createMetricDescriptor(any());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.cloud.opentelemetry.metric;

import static com.google.cloud.opentelemetry.metric.FakeData.aGceResource;
import static com.google.cloud.opentelemetry.metric.FakeData.aDoublePoint;
import static com.google.cloud.opentelemetry.metric.FakeData.aLongPoint;
import static com.google.cloud.opentelemetry.metric.FakeData.aMetricData;
import static com.google.cloud.opentelemetry.metric.FakeData.anInstrumentationLibraryInfo;
Expand Down Expand Up @@ -69,14 +70,13 @@ public void testMapMetricDescriptorWithInvalidMetricKindReturnsNull() {
String description = "Metric Description";
String unit = "ns";
MetricData metricData =
MetricData.create(
MetricData.createDoubleSummary(
aGceResource,
anInstrumentationLibraryInfo,
name,
description,
unit,
Type.SUMMARY,
ImmutableList.of(aLongPoint));
MetricData.DoubleSummaryData.create(ImmutableList.of(aDoublePoint)));

MetricDescriptor actualDescriptor =
MetricTranslator.mapMetricDescriptor(metricData, aLongPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
import com.google.devtools.cloudtrace.v2.TruncatableString;
import com.google.protobuf.BoolValue;
import com.google.rpc.Status;
import io.opentelemetry.api.common.AttributeConsumer;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.SpanData.Event;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;

class TraceTranslator {

Expand Down Expand Up @@ -116,7 +116,7 @@ static com.google.protobuf.Timestamp toTimestampProto(long epochNanos) {
// attributes like the agent.
@VisibleForTesting
static Attributes toAttributesProto(
ReadableAttributes attributes, Map<String, AttributeValue> fixedAttributes) {
io.opentelemetry.api.common.Attributes attributes, Map<String, AttributeValue> fixedAttributes) {
Attributes.Builder attributesBuilder = toAttributesBuilderProto(attributes);
attributesBuilder.putAttributeMap(AGENT_LABEL_KEY, AGENT_LABEL_VALUE);
for (Map.Entry<String, AttributeValue> entry : fixedAttributes.entrySet()) {
Expand All @@ -129,14 +129,14 @@ private static Attributes toAttributesProto(io.opentelemetry.api.common.Attribut
return toAttributesProto(attributes, ImmutableMap.of());
}

private static Attributes.Builder toAttributesBuilderProto(ReadableAttributes attributes) {
private static Attributes.Builder toAttributesBuilderProto(io.opentelemetry.api.common.Attributes attributes) {
Attributes.Builder attributesBuilder =
// TODO (nilebox): Does OpenTelemetry support droppedAttributesCount?
Attributes.newBuilder().setDroppedAttributesCount(0);
attributes.forEach(
new AttributeConsumer() {
new BiConsumer<AttributeKey<?>, Object>() {
@Override
public <T> void accept(AttributeKey<T> key, T value) {
public void accept(AttributeKey<?> key, Object value) {
attributesBuilder.putAttributeMap(mapKey(key), toAttributeValueProto(key, value));
}
});
Expand Down Expand Up @@ -189,7 +189,23 @@ static Span.TimeEvents toTimeEventsProto(List<Event> events) {

@VisibleForTesting
static Status toStatusProto(SpanData.Status status) {
Status.Builder statusBuilder = Status.newBuilder().setCode(status.getStatusCode().value());

final Status.Builder statusBuilder = Status.newBuilder();

final StatusCode statusCode = status.getStatusCode();
switch (statusCode) {
case OK:
statusBuilder.setCode(0);
break;
case UNSET:
statusBuilder.setCode(1);
break;
case ERROR:
statusBuilder.setCode(2);
break;

}

if (status.getDescription() != null) {
statusBuilder.setMessage(status.getDescription());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@

import com.google.auto.value.AutoValue;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.ReadableAttributes;
import io.opentelemetry.api.trace.Span.Kind;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.SpanId;
import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.data.SpanData;

import javax.annotation.concurrent.Immutable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.concurrent.Immutable;

/**
* Immutable representation of all data collected by the {@link io.opentelemetry.api.trace.Span}
Expand All @@ -57,6 +58,7 @@ public abstract class TestSpanData implements SpanData {
public static Builder newBuilder() {
return new AutoValue_TestSpanData.Builder()
.setParentSpanId(SpanId.getInvalid())
.setParentSpanContext(SpanContext.getInvalid())
.setInstrumentationLibraryInfo(InstrumentationLibraryInfo.getEmpty())
.setLinks(Collections.emptyList())
.setTotalRecordedLinks(0)
Expand All @@ -74,6 +76,9 @@ public static Builder newBuilder() {

abstract boolean getInternalHasRemoteParent();

@Override
public abstract String getParentSpanId();

@Override
public final boolean hasEnded() {
return getInternalHasEnded();
Expand Down Expand Up @@ -145,6 +150,14 @@ public TestSpanData build() {
*/
public abstract Builder setParentSpanId(String parentSpanId);

/**
* The parent SpanContext associated for this span, which may be null.
*
* @param parentSpanContext the SpanContext of the parent
* @return this.
*/
public abstract Builder setParentSpanContext(SpanContext parentSpanContext);

/**
* Set the {@link Resource} associated with this span. Must not be null.
*
Expand Down Expand Up @@ -200,7 +213,7 @@ public abstract Builder setInstrumentationLibraryInfo(
* @return this
* @since 0.1.0
*/
public abstract Builder setAttributes(ReadableAttributes attributes);
public abstract Builder setAttributes(Attributes attributes);

/**
* Set timed events that are associated with this span. Must not be null, may be empty.
Expand Down