Update the OTLP proto to the latest released version (0.4.0) (#1390)

This commit is contained in:
John Watson 2020-07-01 15:19:09 -07:00 committed by GitHub
parent ee0d438147
commit 74f52dd738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 320 additions and 133 deletions

View File

@ -17,39 +17,92 @@
package io.opentelemetry.exporters.otlp;
import io.opentelemetry.common.AttributeValue;
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
import io.opentelemetry.proto.common.v1.AnyValue;
import io.opentelemetry.proto.common.v1.ArrayValue;
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
import io.opentelemetry.proto.common.v1.KeyValue;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
final class CommonAdapter {
static AttributeKeyValue toProtoAttribute(String key, AttributeValue attributeValue) {
AttributeKeyValue.Builder builder = AttributeKeyValue.newBuilder().setKey(key);
static KeyValue toProtoAttribute(String key, AttributeValue attributeValue) {
KeyValue.Builder builder = KeyValue.newBuilder().setKey(key);
switch (attributeValue.getType()) {
case STRING:
return builder
.setType(ValueType.STRING)
.setStringValue(attributeValue.getStringValue())
.setValue(AnyValue.newBuilder().setStringValue(attributeValue.getStringValue()).build())
.build();
case BOOLEAN:
return builder
.setType(ValueType.BOOL)
.setBoolValue(attributeValue.getBooleanValue())
.setValue(AnyValue.newBuilder().setBoolValue(attributeValue.getBooleanValue()).build())
.build();
case LONG:
return builder.setType(ValueType.INT).setIntValue(attributeValue.getLongValue()).build();
return builder
.setValue(AnyValue.newBuilder().setIntValue(attributeValue.getLongValue()).build())
.build();
case DOUBLE:
return builder
.setType(ValueType.DOUBLE)
.setDoubleValue(attributeValue.getDoubleValue())
.setValue(AnyValue.newBuilder().setDoubleValue(attributeValue.getDoubleValue()).build())
.build();
case BOOLEAN_ARRAY:
return builder
.setValue(
AnyValue.newBuilder()
.setArrayValue(makeBooleanArrayAnyValue(attributeValue))
.build())
.build();
case LONG_ARRAY:
return builder
.setValue(
AnyValue.newBuilder().setArrayValue(makeLongArrayAnyValue(attributeValue)).build())
.build();
case DOUBLE_ARRAY:
return builder
.setValue(
AnyValue.newBuilder()
.setArrayValue(makeDoubleArrayAnyValue(attributeValue))
.build())
.build();
case STRING_ARRAY:
return builder.setType(ValueType.UNRECOGNIZED).build();
return builder
.setValue(
AnyValue.newBuilder()
.setArrayValue(makeStringArrayAnyValue(attributeValue))
.build())
.build();
}
return builder.setType(ValueType.UNRECOGNIZED).build();
return builder.setValue(AnyValue.getDefaultInstance()).build();
}
private static ArrayValue makeDoubleArrayAnyValue(AttributeValue attributeValue) {
ArrayValue.Builder builder = ArrayValue.newBuilder();
for (Double doubleValue : attributeValue.getDoubleArrayValue()) {
builder.addValues(AnyValue.newBuilder().setDoubleValue(doubleValue).build());
}
return builder.build();
}
private static ArrayValue makeLongArrayAnyValue(AttributeValue attributeValue) {
ArrayValue.Builder builder = ArrayValue.newBuilder();
for (Long intValue : attributeValue.getLongArrayValue()) {
builder.addValues(AnyValue.newBuilder().setIntValue(intValue).build());
}
return builder.build();
}
private static ArrayValue makeStringArrayAnyValue(AttributeValue attributeValue) {
ArrayValue.Builder builder = ArrayValue.newBuilder();
for (String string : attributeValue.getStringArrayValue()) {
builder.addValues(AnyValue.newBuilder().setStringValue(string).build());
}
return builder.build();
}
private static ArrayValue makeBooleanArrayAnyValue(AttributeValue attributeValue) {
ArrayValue.Builder builder = ArrayValue.newBuilder();
for (Boolean bool : attributeValue.getBooleanArrayValue()) {
builder.addValues(AnyValue.newBuilder().setBoolValue(bool).build());
}
return builder.build();
}
static InstrumentationLibrary toProtoInstrumentationLibrary(

View File

@ -24,6 +24,7 @@ import io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics;
import io.opentelemetry.proto.metrics.v1.Int64DataPoint;
import io.opentelemetry.proto.metrics.v1.Metric;
import io.opentelemetry.proto.metrics.v1.MetricDescriptor;
import io.opentelemetry.proto.metrics.v1.MetricDescriptor.Temporality;
import io.opentelemetry.proto.metrics.v1.MetricDescriptor.Type;
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
import io.opentelemetry.proto.metrics.v1.SummaryDataPoint;
@ -100,25 +101,26 @@ final class MetricAdapter {
if (metricData.getPoints().isEmpty()) {
return builder.build();
}
switch (builder.getMetricDescriptor().getType()) {
case UNSPECIFIED:
case UNRECOGNIZED:
case INVALID_TYPE:
break;
case GAUGE_INT64:
case COUNTER_INT64:
builder.addAllInt64DataPoints(toInt64DataPoints(metricData.getPoints()));
case MONOTONIC_INT64:
case INT64:
builder.addAllInt64DataPoints(
toInt64DataPoints(metricData.getPoints(), metricData.getDescriptor()));
break;
case GAUGE_DOUBLE:
case COUNTER_DOUBLE:
builder.addAllDoubleDataPoints(toDoubleDataPoints(metricData.getPoints()));
case MONOTONIC_DOUBLE:
case DOUBLE:
builder.addAllDoubleDataPoints(
toDoubleDataPoints(metricData.getPoints(), metricData.getDescriptor()));
break;
case GAUGE_HISTOGRAM:
case CUMULATIVE_HISTOGRAM:
case HISTOGRAM:
// TODO: Add support for histogram.
break;
case SUMMARY:
builder.addAllSummaryDataPoints(toSummaryDataPoints(metricData.getPoints()));
builder.addAllSummaryDataPoints(
toSummaryDataPoints(metricData.getPoints(), metricData.getDescriptor()));
break;
}
return builder.build();
@ -130,11 +132,25 @@ final class MetricAdapter {
.setDescription(descriptor.getDescription())
.setUnit(descriptor.getUnit())
.setType(toProtoMetricDescriptorType(descriptor.getType()))
.addAllLabels(toProtoLabels(descriptor.getConstantLabels()))
.setTemporality(mapToTemporality(descriptor))
.build();
}
static Collection<Int64DataPoint> toInt64DataPoints(Collection<Point> points) {
private static Temporality mapToTemporality(Descriptor descriptor) {
switch (descriptor.getType()) {
case NON_MONOTONIC_LONG:
case NON_MONOTONIC_DOUBLE:
case MONOTONIC_LONG:
case MONOTONIC_DOUBLE:
return Temporality.CUMULATIVE;
case SUMMARY:
return Temporality.DELTA;
}
return Temporality.UNRECOGNIZED;
}
static Collection<Int64DataPoint> toInt64DataPoints(
Collection<Point> points, Descriptor descriptor) {
List<Int64DataPoint> result = new ArrayList<>(points.size());
for (Point point : points) {
LongPoint longPoint = (LongPoint) point;
@ -144,6 +160,9 @@ final class MetricAdapter {
.setTimeUnixNano(longPoint.getEpochNanos())
.setValue(longPoint.getValue());
// Not calling directly addAllLabels because that generates couple of unnecessary allocations.
if (descriptor.getConstantLabels() != null && !descriptor.getConstantLabels().isEmpty()) {
builder.addAllLabels(toProtoLabels(descriptor.getConstantLabels()));
}
Collection<StringKeyValue> labels = toProtoLabels(longPoint.getLabels());
if (!labels.isEmpty()) {
builder.addAllLabels(labels);
@ -153,7 +172,8 @@ final class MetricAdapter {
return result;
}
static Collection<DoubleDataPoint> toDoubleDataPoints(Collection<Point> points) {
static Collection<DoubleDataPoint> toDoubleDataPoints(
Collection<Point> points, Descriptor descriptor) {
List<DoubleDataPoint> result = new ArrayList<>(points.size());
for (Point point : points) {
DoublePoint doublePoint = (DoublePoint) point;
@ -163,6 +183,9 @@ final class MetricAdapter {
.setTimeUnixNano(doublePoint.getEpochNanos())
.setValue(doublePoint.getValue());
// Not calling directly addAllLabels because that generates couple of unnecessary allocations.
if (descriptor.getConstantLabels() != null && !descriptor.getConstantLabels().isEmpty()) {
builder.addAllLabels(toProtoLabels(descriptor.getConstantLabels()));
}
Collection<StringKeyValue> labels = toProtoLabels(doublePoint.getLabels());
if (!labels.isEmpty()) {
builder.addAllLabels(labels);
@ -172,7 +195,8 @@ final class MetricAdapter {
return result;
}
static Collection<SummaryDataPoint> toSummaryDataPoints(Collection<Point> points) {
static Collection<SummaryDataPoint> toSummaryDataPoints(
Collection<Point> points, Descriptor descriptor) {
List<SummaryDataPoint> result = new ArrayList<>(points.size());
for (Point point : points) {
SummaryPoint summaryPoint = (SummaryPoint) point;
@ -184,6 +208,9 @@ final class MetricAdapter {
.setSum(summaryPoint.getSum());
// Not calling directly addAllLabels because that generates couple of unnecessary allocations
// if empty list.
if (descriptor.getConstantLabels() != null && !descriptor.getConstantLabels().isEmpty()) {
builder.addAllLabels(toProtoLabels(descriptor.getConstantLabels()));
}
Collection<StringKeyValue> labels = toProtoLabels(summaryPoint.getLabels());
if (!labels.isEmpty()) {
builder.addAllLabels(labels);
@ -221,17 +248,17 @@ final class MetricAdapter {
static MetricDescriptor.Type toProtoMetricDescriptorType(Descriptor.Type descriptorType) {
switch (descriptorType) {
case NON_MONOTONIC_LONG:
return Type.GAUGE_INT64;
return Type.INT64;
case NON_MONOTONIC_DOUBLE:
return Type.GAUGE_DOUBLE;
return Type.DOUBLE;
case MONOTONIC_LONG:
return Type.COUNTER_INT64;
return Type.MONOTONIC_INT64;
case MONOTONIC_DOUBLE:
return Type.COUNTER_DOUBLE;
return Type.MONOTONIC_DOUBLE;
case SUMMARY:
return Type.SUMMARY;
}
return Type.UNSPECIFIED;
return Type.UNRECOGNIZED;
}
@SuppressWarnings("MixedMutabilityReturnType")

View File

@ -19,9 +19,10 @@ package io.opentelemetry.exporters.otlp;
import static com.google.common.truth.Truth.assertThat;
import io.opentelemetry.common.AttributeValue;
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
import io.opentelemetry.proto.common.v1.AnyValue;
import io.opentelemetry.proto.common.v1.ArrayValue;
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
import io.opentelemetry.proto.common.v1.KeyValue;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -34,10 +35,27 @@ public class CommonAdapterTest {
public void toProtoAttribute_Bool() {
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.booleanAttributeValue(true)))
.isEqualTo(
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key")
.setBoolValue(true)
.setType(ValueType.BOOL)
.setValue(AnyValue.newBuilder().setBoolValue(true).build())
.build());
}
@Test
public void toProtoAttribute_BoolArray() {
assertThat(
CommonAdapter.toProtoAttribute("key", AttributeValue.arrayAttributeValue(true, false)))
.isEqualTo(
KeyValue.newBuilder()
.setKey("key")
.setValue(
AnyValue.newBuilder()
.setArrayValue(
ArrayValue.newBuilder()
.addValues(AnyValue.newBuilder().setBoolValue(true).build())
.addValues(AnyValue.newBuilder().setBoolValue(false).build())
.build())
.build())
.build());
}
@ -45,10 +63,28 @@ public class CommonAdapterTest {
public void toProtoAttribute_String() {
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.stringAttributeValue("string")))
.isEqualTo(
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key")
.setStringValue("string")
.setType(ValueType.STRING)
.setValue(AnyValue.newBuilder().setStringValue("string").build())
.build());
}
@Test
public void toProtoAttribute_StringArray() {
assertThat(
CommonAdapter.toProtoAttribute(
"key", AttributeValue.arrayAttributeValue("string1", "string2")))
.isEqualTo(
KeyValue.newBuilder()
.setKey("key")
.setValue(
AnyValue.newBuilder()
.setArrayValue(
ArrayValue.newBuilder()
.addValues(AnyValue.newBuilder().setStringValue("string1").build())
.addValues(AnyValue.newBuilder().setStringValue("string2").build())
.build())
.build())
.build());
}
@ -56,10 +92,27 @@ public class CommonAdapterTest {
public void toProtoAttribute_Int() {
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.longAttributeValue(100)))
.isEqualTo(
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key")
.setIntValue(100)
.setType(ValueType.INT)
.setValue(AnyValue.newBuilder().setIntValue(100).build())
.build());
}
@Test
public void toProtoAttribute_IntArray() {
assertThat(
CommonAdapter.toProtoAttribute("key", AttributeValue.arrayAttributeValue(100L, 200L)))
.isEqualTo(
KeyValue.newBuilder()
.setKey("key")
.setValue(
AnyValue.newBuilder()
.setArrayValue(
ArrayValue.newBuilder()
.addValues(AnyValue.newBuilder().setIntValue(100).build())
.addValues(AnyValue.newBuilder().setIntValue(200).build())
.build())
.build())
.build());
}
@ -67,10 +120,27 @@ public class CommonAdapterTest {
public void toProtoAttribute_Double() {
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.doubleAttributeValue(100.3)))
.isEqualTo(
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key")
.setDoubleValue(100.3)
.setType(ValueType.DOUBLE)
.setValue(AnyValue.newBuilder().setDoubleValue(100.3).build())
.build());
}
@Test
public void toProtoAttribute_DoubleArray() {
assertThat(
CommonAdapter.toProtoAttribute("key", AttributeValue.arrayAttributeValue(100.3, 200.5)))
.isEqualTo(
KeyValue.newBuilder()
.setKey("key")
.setValue(
AnyValue.newBuilder()
.setArrayValue(
ArrayValue.newBuilder()
.addValues(AnyValue.newBuilder().setDoubleValue(100.3).build())
.addValues(AnyValue.newBuilder().setDoubleValue(200.5).build())
.build())
.build())
.build());
}

View File

@ -17,20 +17,22 @@
package io.opentelemetry.exporters.otlp;
import static com.google.common.truth.Truth.assertThat;
import static java.util.Collections.singletonList;
import com.google.common.collect.ImmutableList;
import io.opentelemetry.common.AttributeValue;
import io.opentelemetry.common.Attributes;
import io.opentelemetry.common.Labels;
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
import io.opentelemetry.proto.common.v1.AnyValue;
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
import io.opentelemetry.proto.common.v1.KeyValue;
import io.opentelemetry.proto.common.v1.StringKeyValue;
import io.opentelemetry.proto.metrics.v1.DoubleDataPoint;
import io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics;
import io.opentelemetry.proto.metrics.v1.Int64DataPoint;
import io.opentelemetry.proto.metrics.v1.Metric;
import io.opentelemetry.proto.metrics.v1.MetricDescriptor;
import io.opentelemetry.proto.metrics.v1.MetricDescriptor.Temporality;
import io.opentelemetry.proto.metrics.v1.MetricDescriptor.Type;
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
import io.opentelemetry.proto.metrics.v1.SummaryDataPoint;
@ -39,6 +41,7 @@ import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -61,13 +64,13 @@ public class MetricAdapterTest {
@Test
public void toProtoMetricDescriptorType() {
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.NON_MONOTONIC_DOUBLE))
.isEqualTo(Type.GAUGE_DOUBLE);
.isEqualTo(Type.DOUBLE);
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.NON_MONOTONIC_LONG))
.isEqualTo(Type.GAUGE_INT64);
.isEqualTo(Type.INT64);
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.MONOTONIC_DOUBLE))
.isEqualTo(Type.COUNTER_DOUBLE);
.isEqualTo(Type.MONOTONIC_DOUBLE);
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.MONOTONIC_LONG))
.isEqualTo(Type.COUNTER_INT64);
.isEqualTo(Type.MONOTONIC_INT64);
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.SUMMARY))
.isEqualTo(Type.SUMMARY);
}
@ -77,7 +80,7 @@ public class MetricAdapterTest {
assertThat(MetricAdapter.toProtoValueAtPercentiles(Collections.emptyList())).isEmpty();
assertThat(
MetricAdapter.toProtoValueAtPercentiles(
Collections.singletonList(MetricData.ValueAtPercentile.create(0.9, 1.1))))
singletonList(MetricData.ValueAtPercentile.create(0.9, 1.1))))
.containsExactly(ValueAtPercentile.newBuilder().setPercentile(0.9).setValue(1.1).build());
assertThat(
MetricAdapter.toProtoValueAtPercentiles(
@ -91,17 +94,25 @@ public class MetricAdapterTest {
@Test
public void toInt64DataPoints() {
assertThat(MetricAdapter.toInt64DataPoints(Collections.emptyList())).isEmpty();
Descriptor descriptor =
Descriptor.create(
"test",
"testDescription",
"unit",
Descriptor.Type.MONOTONIC_LONG,
Labels.of("ck", "cv"));
assertThat(MetricAdapter.toInt64DataPoints(Collections.emptyList(), descriptor)).isEmpty();
assertThat(
MetricAdapter.toInt64DataPoints(
Collections.singletonList(
MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5))))
singletonList(MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5)),
descriptor))
.containsExactly(
Int64DataPoint.newBuilder()
.setStartTimeUnixNano(123)
.setTimeUnixNano(456)
.addAllLabels(
Collections.singletonList(
Arrays.asList(
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setValue(5)
.build());
@ -109,18 +120,22 @@ public class MetricAdapterTest {
MetricAdapter.toInt64DataPoints(
ImmutableList.of(
MetricData.LongPoint.create(123, 456, Labels.empty(), 5),
MetricData.LongPoint.create(321, 654, Labels.of("k", "v"), 7))))
MetricData.LongPoint.create(321, 654, Labels.of("k", "v"), 7)),
descriptor))
.containsExactly(
Int64DataPoint.newBuilder()
.setStartTimeUnixNano(123)
.setTimeUnixNano(456)
.addAllLabels(
singletonList(StringKeyValue.newBuilder().setKey("ck").setValue("cv").build()))
.setValue(5)
.build(),
Int64DataPoint.newBuilder()
.setStartTimeUnixNano(321)
.setTimeUnixNano(654)
.addAllLabels(
Collections.singletonList(
Arrays.asList(
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setValue(7)
.build());
@ -128,17 +143,25 @@ public class MetricAdapterTest {
@Test
public void toDoubleDataPoints() {
assertThat(MetricAdapter.toDoubleDataPoints(Collections.emptyList())).isEmpty();
Descriptor descriptor =
Descriptor.create(
"test",
"testDescription",
"unit",
Descriptor.Type.MONOTONIC_DOUBLE,
Labels.of("ck", "cv"));
assertThat(MetricAdapter.toDoubleDataPoints(Collections.emptyList(), descriptor)).isEmpty();
assertThat(
MetricAdapter.toDoubleDataPoints(
Collections.singletonList(
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1))))
singletonList(MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1)),
descriptor))
.containsExactly(
DoubleDataPoint.newBuilder()
.setStartTimeUnixNano(123)
.setTimeUnixNano(456)
.addAllLabels(
Collections.singletonList(
Arrays.asList(
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setValue(5.1)
.build());
@ -146,18 +169,22 @@ public class MetricAdapterTest {
MetricAdapter.toDoubleDataPoints(
ImmutableList.of(
MetricData.DoublePoint.create(123, 456, Labels.empty(), 5.1),
MetricData.DoublePoint.create(321, 654, Labels.of("k", "v"), 7.1))))
MetricData.DoublePoint.create(321, 654, Labels.of("k", "v"), 7.1)),
descriptor))
.containsExactly(
DoubleDataPoint.newBuilder()
.setStartTimeUnixNano(123)
.setTimeUnixNano(456)
.addAllLabels(
singletonList(StringKeyValue.newBuilder().setKey("ck").setValue("cv").build()))
.setValue(5.1)
.build(),
DoubleDataPoint.newBuilder()
.setStartTimeUnixNano(321)
.setTimeUnixNano(654)
.addAllLabels(
Collections.singletonList(
Arrays.asList(
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setValue(7.1)
.build());
@ -165,28 +192,32 @@ public class MetricAdapterTest {
@Test
public void toSummaryDataPoints() {
assertThat(MetricAdapter.toSummaryDataPoints(Collections.emptyList())).isEmpty();
Descriptor descriptor =
Descriptor.create(
"test", "testDescription", "unit", Descriptor.Type.SUMMARY, Labels.of("ck", "cv"));
assertThat(
MetricAdapter.toSummaryDataPoints(
Collections.singletonList(
singletonList(
MetricData.SummaryPoint.create(
123,
456,
Labels.of("k", "v"),
5,
14.2,
Collections.singletonList(MetricData.ValueAtPercentile.create(0.9, 1.1))))))
singletonList(MetricData.ValueAtPercentile.create(0.9, 1.1)))),
descriptor))
.containsExactly(
SummaryDataPoint.newBuilder()
.setStartTimeUnixNano(123)
.setTimeUnixNano(456)
.addAllLabels(
Collections.singletonList(
Arrays.asList(
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setCount(5)
.setSum(14.2)
.addAllPercentileValues(
Collections.singletonList(
singletonList(
ValueAtPercentile.newBuilder().setPercentile(0.9).setValue(1.1).build()))
.build());
assertThat(
@ -202,11 +233,14 @@ public class MetricAdapterTest {
18.3,
ImmutableList.of(
MetricData.ValueAtPercentile.create(0.9, 1.1),
MetricData.ValueAtPercentile.create(0.99, 20.3))))))
MetricData.ValueAtPercentile.create(0.99, 20.3)))),
descriptor))
.containsExactly(
SummaryDataPoint.newBuilder()
.setStartTimeUnixNano(123)
.setTimeUnixNano(456)
.addAllLabels(
singletonList(StringKeyValue.newBuilder().setKey("ck").setValue("cv").build()))
.setCount(7)
.setSum(15.3)
.build(),
@ -214,7 +248,8 @@ public class MetricAdapterTest {
.setStartTimeUnixNano(321)
.setTimeUnixNano(654)
.addAllLabels(
Collections.singletonList(
Arrays.asList(
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setCount(9)
.setSum(18.3)
@ -240,21 +275,36 @@ public class MetricAdapterTest {
.setName("name")
.setDescription("description")
.setUnit("1")
.setType(Type.COUNTER_DOUBLE)
.addAllLabels(
Collections.singletonList(
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setType(Type.MONOTONIC_DOUBLE)
.setTemporality(Temporality.CUMULATIVE)
.build());
assertThat(
MetricAdapter.toProtoMetricDescriptor(
Descriptor.create(
"name", "description", "1", Descriptor.Type.MONOTONIC_DOUBLE, Labels.empty())))
"name",
"description",
"1",
Descriptor.Type.NON_MONOTONIC_DOUBLE,
Labels.empty())))
.isEqualTo(
MetricDescriptor.newBuilder()
.setName("name")
.setDescription("description")
.setUnit("1")
.setType(Type.COUNTER_DOUBLE)
.setType(Type.DOUBLE)
.setTemporality(Temporality.CUMULATIVE)
.build());
assertThat(
MetricAdapter.toProtoMetricDescriptor(
Descriptor.create(
"name", "description", "1", Descriptor.Type.SUMMARY, Labels.empty())))
.isEqualTo(
MetricDescriptor.newBuilder()
.setName("name")
.setDescription("description")
.setUnit("1")
.setType(Type.SUMMARY)
.setTemporality(Temporality.DELTA)
.build());
}
@ -268,11 +318,10 @@ public class MetricAdapterTest {
"description",
"1",
Descriptor.Type.MONOTONIC_LONG,
Labels.of("k", "v")),
Labels.of("ck", "cv")),
Resource.getEmpty(),
InstrumentationLibraryInfo.getEmpty(),
Collections.singletonList(
MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5)))))
singletonList(MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5)))))
.isEqualTo(
Metric.newBuilder()
.setMetricDescriptor(
@ -280,18 +329,17 @@ public class MetricAdapterTest {
.setName("name")
.setDescription("description")
.setUnit("1")
.setType(Type.COUNTER_INT64)
.addAllLabels(
Collections.singletonList(
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setType(Type.MONOTONIC_INT64)
.setTemporality(Temporality.CUMULATIVE)
.build())
.addAllInt64DataPoints(
Collections.singletonList(
singletonList(
Int64DataPoint.newBuilder()
.setStartTimeUnixNano(123)
.setTimeUnixNano(456)
.addAllLabels(
Collections.singletonList(
Arrays.asList(
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setValue(5)
.build()))
@ -304,10 +352,10 @@ public class MetricAdapterTest {
"description",
"1",
Descriptor.Type.MONOTONIC_DOUBLE,
Labels.of("k", "v")),
Labels.of("ck", "cv")),
Resource.getEmpty(),
InstrumentationLibraryInfo.getEmpty(),
Collections.singletonList(
singletonList(
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1)))))
.isEqualTo(
Metric.newBuilder()
@ -316,18 +364,17 @@ public class MetricAdapterTest {
.setName("name")
.setDescription("description")
.setUnit("1")
.setType(Type.COUNTER_DOUBLE)
.addAllLabels(
Collections.singletonList(
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setType(Type.MONOTONIC_DOUBLE)
.setTemporality(Temporality.CUMULATIVE)
.build())
.addAllDoubleDataPoints(
Collections.singletonList(
singletonList(
DoubleDataPoint.newBuilder()
.setStartTimeUnixNano(123)
.setTimeUnixNano(456)
.addAllLabels(
Collections.singletonList(
Arrays.asList(
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setValue(5.1)
.build()))
@ -344,11 +391,10 @@ public class MetricAdapterTest {
io.opentelemetry.proto.resource.v1.Resource resourceProto =
io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAllAttributes(
Collections.singletonList(
AttributeKeyValue.newBuilder()
singletonList(
KeyValue.newBuilder()
.setKey("ka")
.setStringValue("va")
.setType(ValueType.STRING)
.setValue(AnyValue.newBuilder().setStringValue("va").build())
.build()))
.build();
io.opentelemetry.proto.resource.v1.Resource emptyResourceProto =
@ -366,10 +412,8 @@ public class MetricAdapterTest {
.setName("name")
.setDescription("description")
.setUnit("1")
.setType(Type.COUNTER_DOUBLE)
.addAllLabels(
Collections.singletonList(
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setType(Type.MONOTONIC_DOUBLE)
.setTemporality(Temporality.CUMULATIVE)
.build())
.build();
@ -394,7 +438,7 @@ public class MetricAdapterTest {
ResourceMetrics.newBuilder()
.setResource(resourceProto)
.addAllInstrumentationLibraryMetrics(
Collections.singletonList(
singletonList(
InstrumentationLibraryMetrics.newBuilder()
.setInstrumentationLibrary(instrumentationLibraryProto)
.addAllMetrics(ImmutableList.of(metricNoPoints, metricNoPoints))
@ -406,11 +450,11 @@ public class MetricAdapterTest {
ImmutableList.of(
InstrumentationLibraryMetrics.newBuilder()
.setInstrumentationLibrary(emptyInstrumentationLibraryProto)
.addAllMetrics(Collections.singletonList(metricNoPoints))
.addAllMetrics(singletonList(metricNoPoints))
.build(),
InstrumentationLibraryMetrics.newBuilder()
.setInstrumentationLibrary(instrumentationLibraryProto)
.addAllMetrics(Collections.singletonList(metricNoPoints))
.addAllMetrics(singletonList(metricNoPoints))
.build()))
.build());
}

View File

@ -20,8 +20,8 @@ import static com.google.common.truth.Truth.assertThat;
import io.opentelemetry.common.AttributeValue;
import io.opentelemetry.common.Attributes;
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
import io.opentelemetry.proto.common.v1.AnyValue;
import io.opentelemetry.proto.common.v1.KeyValue;
import io.opentelemetry.sdk.resources.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -46,25 +46,21 @@ public class ResourceAdapterTest {
AttributeValue.doubleAttributeValue(100.3))))
.getAttributesList())
.containsExactly(
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key_bool")
.setBoolValue(true)
.setType(ValueType.BOOL)
.setValue(AnyValue.newBuilder().setBoolValue(true).build())
.build(),
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key_string")
.setStringValue("string")
.setType(ValueType.STRING)
.setValue(AnyValue.newBuilder().setStringValue("string").build())
.build(),
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key_int")
.setIntValue(100)
.setType(ValueType.INT)
.setValue(AnyValue.newBuilder().setIntValue(100).build())
.build(),
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key_double")
.setDoubleValue(100.3)
.setType(ValueType.DOUBLE)
.setValue(AnyValue.newBuilder().setDoubleValue(100.3).build())
.build());
}

View File

@ -21,8 +21,8 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.protobuf.ByteString;
import io.opentelemetry.common.AttributeValue;
import io.opentelemetry.common.Attributes;
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
import io.opentelemetry.proto.common.v1.AnyValue;
import io.opentelemetry.proto.common.v1.KeyValue;
import io.opentelemetry.proto.trace.v1.Span;
import io.opentelemetry.proto.trace.v1.Span.SpanKind;
import io.opentelemetry.proto.trace.v1.Status;
@ -87,10 +87,9 @@ public class SpanAdapterTest {
assertThat(span.getEndTimeUnixNano()).isEqualTo(12349);
assertThat(span.getAttributesList())
.containsExactly(
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key")
.setBoolValue(true)
.setType(ValueType.BOOL)
.setValue(AnyValue.newBuilder().setBoolValue(true).build())
.build());
assertThat(span.getDroppedAttributesCount()).isEqualTo(1);
assertThat(span.getEventsList())
@ -255,10 +254,9 @@ public class SpanAdapterTest {
.setTimeUnixNano(12345)
.setName("test_with_attributes")
.addAttributes(
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key_string")
.setStringValue("string")
.setType(ValueType.STRING)
.setValue(AnyValue.newBuilder().setStringValue("string").build())
.build())
.setDroppedAttributesCount(4)
.build());
@ -287,10 +285,9 @@ public class SpanAdapterTest {
.setTraceId(ByteString.copyFrom(TRACE_ID_BYTES))
.setSpanId(ByteString.copyFrom(SPAN_ID_BYTES))
.addAttributes(
AttributeKeyValue.newBuilder()
KeyValue.newBuilder()
.setKey("key_string")
.setStringValue("string")
.setType(ValueType.STRING)
.setValue(AnyValue.newBuilder().setStringValue("string").build())
.build())
.setDroppedAttributesCount(4)
.build());

@ -1 +1 @@
Subproject commit 6a4eb2fa6f25569910f7b17216e3a2087496bbce
Subproject commit e43e1abc40428a6ee98e3bfd79bec1dfa2ed18cd