Update the OTLP proto to the latest released version (0.4.0) (#1390)
This commit is contained in:
parent
ee0d438147
commit
74f52dd738
|
|
@ -17,39 +17,92 @@
|
||||||
package io.opentelemetry.exporters.otlp;
|
package io.opentelemetry.exporters.otlp;
|
||||||
|
|
||||||
import io.opentelemetry.common.AttributeValue;
|
import io.opentelemetry.common.AttributeValue;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
|
import io.opentelemetry.proto.common.v1.AnyValue;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
|
import io.opentelemetry.proto.common.v1.ArrayValue;
|
||||||
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
|
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
|
||||||
|
import io.opentelemetry.proto.common.v1.KeyValue;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||||
|
|
||||||
final class CommonAdapter {
|
final class CommonAdapter {
|
||||||
static AttributeKeyValue toProtoAttribute(String key, AttributeValue attributeValue) {
|
static KeyValue toProtoAttribute(String key, AttributeValue attributeValue) {
|
||||||
AttributeKeyValue.Builder builder = AttributeKeyValue.newBuilder().setKey(key);
|
KeyValue.Builder builder = KeyValue.newBuilder().setKey(key);
|
||||||
switch (attributeValue.getType()) {
|
switch (attributeValue.getType()) {
|
||||||
case STRING:
|
case STRING:
|
||||||
return builder
|
return builder
|
||||||
.setType(ValueType.STRING)
|
.setValue(AnyValue.newBuilder().setStringValue(attributeValue.getStringValue()).build())
|
||||||
.setStringValue(attributeValue.getStringValue())
|
|
||||||
.build();
|
.build();
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
return builder
|
return builder
|
||||||
.setType(ValueType.BOOL)
|
.setValue(AnyValue.newBuilder().setBoolValue(attributeValue.getBooleanValue()).build())
|
||||||
.setBoolValue(attributeValue.getBooleanValue())
|
|
||||||
.build();
|
.build();
|
||||||
case LONG:
|
case LONG:
|
||||||
return builder.setType(ValueType.INT).setIntValue(attributeValue.getLongValue()).build();
|
return builder
|
||||||
|
.setValue(AnyValue.newBuilder().setIntValue(attributeValue.getLongValue()).build())
|
||||||
|
.build();
|
||||||
case DOUBLE:
|
case DOUBLE:
|
||||||
return builder
|
return builder
|
||||||
.setType(ValueType.DOUBLE)
|
.setValue(AnyValue.newBuilder().setDoubleValue(attributeValue.getDoubleValue()).build())
|
||||||
.setDoubleValue(attributeValue.getDoubleValue())
|
|
||||||
.build();
|
.build();
|
||||||
case BOOLEAN_ARRAY:
|
case BOOLEAN_ARRAY:
|
||||||
|
return builder
|
||||||
|
.setValue(
|
||||||
|
AnyValue.newBuilder()
|
||||||
|
.setArrayValue(makeBooleanArrayAnyValue(attributeValue))
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
case LONG_ARRAY:
|
case LONG_ARRAY:
|
||||||
|
return builder
|
||||||
|
.setValue(
|
||||||
|
AnyValue.newBuilder().setArrayValue(makeLongArrayAnyValue(attributeValue)).build())
|
||||||
|
.build();
|
||||||
case DOUBLE_ARRAY:
|
case DOUBLE_ARRAY:
|
||||||
|
return builder
|
||||||
|
.setValue(
|
||||||
|
AnyValue.newBuilder()
|
||||||
|
.setArrayValue(makeDoubleArrayAnyValue(attributeValue))
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
case STRING_ARRAY:
|
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(
|
static InstrumentationLibrary toProtoInstrumentationLibrary(
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics;
|
||||||
import io.opentelemetry.proto.metrics.v1.Int64DataPoint;
|
import io.opentelemetry.proto.metrics.v1.Int64DataPoint;
|
||||||
import io.opentelemetry.proto.metrics.v1.Metric;
|
import io.opentelemetry.proto.metrics.v1.Metric;
|
||||||
import io.opentelemetry.proto.metrics.v1.MetricDescriptor;
|
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.MetricDescriptor.Type;
|
||||||
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
|
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
|
||||||
import io.opentelemetry.proto.metrics.v1.SummaryDataPoint;
|
import io.opentelemetry.proto.metrics.v1.SummaryDataPoint;
|
||||||
|
|
@ -100,25 +101,26 @@ final class MetricAdapter {
|
||||||
if (metricData.getPoints().isEmpty()) {
|
if (metricData.getPoints().isEmpty()) {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (builder.getMetricDescriptor().getType()) {
|
switch (builder.getMetricDescriptor().getType()) {
|
||||||
case UNSPECIFIED:
|
|
||||||
case UNRECOGNIZED:
|
case UNRECOGNIZED:
|
||||||
|
case INVALID_TYPE:
|
||||||
break;
|
break;
|
||||||
case GAUGE_INT64:
|
case MONOTONIC_INT64:
|
||||||
case COUNTER_INT64:
|
case INT64:
|
||||||
builder.addAllInt64DataPoints(toInt64DataPoints(metricData.getPoints()));
|
builder.addAllInt64DataPoints(
|
||||||
|
toInt64DataPoints(metricData.getPoints(), metricData.getDescriptor()));
|
||||||
break;
|
break;
|
||||||
case GAUGE_DOUBLE:
|
case MONOTONIC_DOUBLE:
|
||||||
case COUNTER_DOUBLE:
|
case DOUBLE:
|
||||||
builder.addAllDoubleDataPoints(toDoubleDataPoints(metricData.getPoints()));
|
builder.addAllDoubleDataPoints(
|
||||||
|
toDoubleDataPoints(metricData.getPoints(), metricData.getDescriptor()));
|
||||||
break;
|
break;
|
||||||
case GAUGE_HISTOGRAM:
|
case HISTOGRAM:
|
||||||
case CUMULATIVE_HISTOGRAM:
|
|
||||||
// TODO: Add support for histogram.
|
// TODO: Add support for histogram.
|
||||||
break;
|
break;
|
||||||
case SUMMARY:
|
case SUMMARY:
|
||||||
builder.addAllSummaryDataPoints(toSummaryDataPoints(metricData.getPoints()));
|
builder.addAllSummaryDataPoints(
|
||||||
|
toSummaryDataPoints(metricData.getPoints(), metricData.getDescriptor()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|
@ -130,11 +132,25 @@ final class MetricAdapter {
|
||||||
.setDescription(descriptor.getDescription())
|
.setDescription(descriptor.getDescription())
|
||||||
.setUnit(descriptor.getUnit())
|
.setUnit(descriptor.getUnit())
|
||||||
.setType(toProtoMetricDescriptorType(descriptor.getType()))
|
.setType(toProtoMetricDescriptorType(descriptor.getType()))
|
||||||
.addAllLabels(toProtoLabels(descriptor.getConstantLabels()))
|
.setTemporality(mapToTemporality(descriptor))
|
||||||
.build();
|
.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());
|
List<Int64DataPoint> result = new ArrayList<>(points.size());
|
||||||
for (Point point : points) {
|
for (Point point : points) {
|
||||||
LongPoint longPoint = (LongPoint) point;
|
LongPoint longPoint = (LongPoint) point;
|
||||||
|
|
@ -144,6 +160,9 @@ final class MetricAdapter {
|
||||||
.setTimeUnixNano(longPoint.getEpochNanos())
|
.setTimeUnixNano(longPoint.getEpochNanos())
|
||||||
.setValue(longPoint.getValue());
|
.setValue(longPoint.getValue());
|
||||||
// Not calling directly addAllLabels because that generates couple of unnecessary allocations.
|
// 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());
|
Collection<StringKeyValue> labels = toProtoLabels(longPoint.getLabels());
|
||||||
if (!labels.isEmpty()) {
|
if (!labels.isEmpty()) {
|
||||||
builder.addAllLabels(labels);
|
builder.addAllLabels(labels);
|
||||||
|
|
@ -153,7 +172,8 @@ final class MetricAdapter {
|
||||||
return result;
|
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());
|
List<DoubleDataPoint> result = new ArrayList<>(points.size());
|
||||||
for (Point point : points) {
|
for (Point point : points) {
|
||||||
DoublePoint doublePoint = (DoublePoint) point;
|
DoublePoint doublePoint = (DoublePoint) point;
|
||||||
|
|
@ -163,6 +183,9 @@ final class MetricAdapter {
|
||||||
.setTimeUnixNano(doublePoint.getEpochNanos())
|
.setTimeUnixNano(doublePoint.getEpochNanos())
|
||||||
.setValue(doublePoint.getValue());
|
.setValue(doublePoint.getValue());
|
||||||
// Not calling directly addAllLabels because that generates couple of unnecessary allocations.
|
// 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());
|
Collection<StringKeyValue> labels = toProtoLabels(doublePoint.getLabels());
|
||||||
if (!labels.isEmpty()) {
|
if (!labels.isEmpty()) {
|
||||||
builder.addAllLabels(labels);
|
builder.addAllLabels(labels);
|
||||||
|
|
@ -172,7 +195,8 @@ final class MetricAdapter {
|
||||||
return result;
|
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());
|
List<SummaryDataPoint> result = new ArrayList<>(points.size());
|
||||||
for (Point point : points) {
|
for (Point point : points) {
|
||||||
SummaryPoint summaryPoint = (SummaryPoint) point;
|
SummaryPoint summaryPoint = (SummaryPoint) point;
|
||||||
|
|
@ -184,6 +208,9 @@ final class MetricAdapter {
|
||||||
.setSum(summaryPoint.getSum());
|
.setSum(summaryPoint.getSum());
|
||||||
// Not calling directly addAllLabels because that generates couple of unnecessary allocations
|
// Not calling directly addAllLabels because that generates couple of unnecessary allocations
|
||||||
// if empty list.
|
// if empty list.
|
||||||
|
if (descriptor.getConstantLabels() != null && !descriptor.getConstantLabels().isEmpty()) {
|
||||||
|
builder.addAllLabels(toProtoLabels(descriptor.getConstantLabels()));
|
||||||
|
}
|
||||||
Collection<StringKeyValue> labels = toProtoLabels(summaryPoint.getLabels());
|
Collection<StringKeyValue> labels = toProtoLabels(summaryPoint.getLabels());
|
||||||
if (!labels.isEmpty()) {
|
if (!labels.isEmpty()) {
|
||||||
builder.addAllLabels(labels);
|
builder.addAllLabels(labels);
|
||||||
|
|
@ -221,17 +248,17 @@ final class MetricAdapter {
|
||||||
static MetricDescriptor.Type toProtoMetricDescriptorType(Descriptor.Type descriptorType) {
|
static MetricDescriptor.Type toProtoMetricDescriptorType(Descriptor.Type descriptorType) {
|
||||||
switch (descriptorType) {
|
switch (descriptorType) {
|
||||||
case NON_MONOTONIC_LONG:
|
case NON_MONOTONIC_LONG:
|
||||||
return Type.GAUGE_INT64;
|
return Type.INT64;
|
||||||
case NON_MONOTONIC_DOUBLE:
|
case NON_MONOTONIC_DOUBLE:
|
||||||
return Type.GAUGE_DOUBLE;
|
return Type.DOUBLE;
|
||||||
case MONOTONIC_LONG:
|
case MONOTONIC_LONG:
|
||||||
return Type.COUNTER_INT64;
|
return Type.MONOTONIC_INT64;
|
||||||
case MONOTONIC_DOUBLE:
|
case MONOTONIC_DOUBLE:
|
||||||
return Type.COUNTER_DOUBLE;
|
return Type.MONOTONIC_DOUBLE;
|
||||||
case SUMMARY:
|
case SUMMARY:
|
||||||
return Type.SUMMARY;
|
return Type.SUMMARY;
|
||||||
}
|
}
|
||||||
return Type.UNSPECIFIED;
|
return Type.UNRECOGNIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("MixedMutabilityReturnType")
|
@SuppressWarnings("MixedMutabilityReturnType")
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,10 @@ package io.opentelemetry.exporters.otlp;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import io.opentelemetry.common.AttributeValue;
|
import io.opentelemetry.common.AttributeValue;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
|
import io.opentelemetry.proto.common.v1.AnyValue;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
|
import io.opentelemetry.proto.common.v1.ArrayValue;
|
||||||
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
|
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
|
||||||
|
import io.opentelemetry.proto.common.v1.KeyValue;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
@ -34,10 +35,27 @@ public class CommonAdapterTest {
|
||||||
public void toProtoAttribute_Bool() {
|
public void toProtoAttribute_Bool() {
|
||||||
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.booleanAttributeValue(true)))
|
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.booleanAttributeValue(true)))
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key")
|
.setKey("key")
|
||||||
.setBoolValue(true)
|
.setValue(AnyValue.newBuilder().setBoolValue(true).build())
|
||||||
.setType(ValueType.BOOL)
|
.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());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,10 +63,28 @@ public class CommonAdapterTest {
|
||||||
public void toProtoAttribute_String() {
|
public void toProtoAttribute_String() {
|
||||||
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.stringAttributeValue("string")))
|
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.stringAttributeValue("string")))
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key")
|
.setKey("key")
|
||||||
.setStringValue("string")
|
.setValue(AnyValue.newBuilder().setStringValue("string").build())
|
||||||
.setType(ValueType.STRING)
|
.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());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,10 +92,27 @@ public class CommonAdapterTest {
|
||||||
public void toProtoAttribute_Int() {
|
public void toProtoAttribute_Int() {
|
||||||
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.longAttributeValue(100)))
|
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.longAttributeValue(100)))
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key")
|
.setKey("key")
|
||||||
.setIntValue(100)
|
.setValue(AnyValue.newBuilder().setIntValue(100).build())
|
||||||
.setType(ValueType.INT)
|
.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());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,10 +120,27 @@ public class CommonAdapterTest {
|
||||||
public void toProtoAttribute_Double() {
|
public void toProtoAttribute_Double() {
|
||||||
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.doubleAttributeValue(100.3)))
|
assertThat(CommonAdapter.toProtoAttribute("key", AttributeValue.doubleAttributeValue(100.3)))
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key")
|
.setKey("key")
|
||||||
.setDoubleValue(100.3)
|
.setValue(AnyValue.newBuilder().setDoubleValue(100.3).build())
|
||||||
.setType(ValueType.DOUBLE)
|
.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());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,20 +17,22 @@
|
||||||
package io.opentelemetry.exporters.otlp;
|
package io.opentelemetry.exporters.otlp;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import io.opentelemetry.common.AttributeValue;
|
import io.opentelemetry.common.AttributeValue;
|
||||||
import io.opentelemetry.common.Attributes;
|
import io.opentelemetry.common.Attributes;
|
||||||
import io.opentelemetry.common.Labels;
|
import io.opentelemetry.common.Labels;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
|
import io.opentelemetry.proto.common.v1.AnyValue;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
|
|
||||||
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
|
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.common.v1.StringKeyValue;
|
||||||
import io.opentelemetry.proto.metrics.v1.DoubleDataPoint;
|
import io.opentelemetry.proto.metrics.v1.DoubleDataPoint;
|
||||||
import io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics;
|
import io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics;
|
||||||
import io.opentelemetry.proto.metrics.v1.Int64DataPoint;
|
import io.opentelemetry.proto.metrics.v1.Int64DataPoint;
|
||||||
import io.opentelemetry.proto.metrics.v1.Metric;
|
import io.opentelemetry.proto.metrics.v1.Metric;
|
||||||
import io.opentelemetry.proto.metrics.v1.MetricDescriptor;
|
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.MetricDescriptor.Type;
|
||||||
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
|
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
|
||||||
import io.opentelemetry.proto.metrics.v1.SummaryDataPoint;
|
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;
|
||||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||||
import io.opentelemetry.sdk.resources.Resource;
|
import io.opentelemetry.sdk.resources.Resource;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
@ -61,13 +64,13 @@ public class MetricAdapterTest {
|
||||||
@Test
|
@Test
|
||||||
public void toProtoMetricDescriptorType() {
|
public void toProtoMetricDescriptorType() {
|
||||||
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.NON_MONOTONIC_DOUBLE))
|
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.NON_MONOTONIC_DOUBLE))
|
||||||
.isEqualTo(Type.GAUGE_DOUBLE);
|
.isEqualTo(Type.DOUBLE);
|
||||||
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.NON_MONOTONIC_LONG))
|
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.NON_MONOTONIC_LONG))
|
||||||
.isEqualTo(Type.GAUGE_INT64);
|
.isEqualTo(Type.INT64);
|
||||||
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.MONOTONIC_DOUBLE))
|
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.MONOTONIC_DOUBLE))
|
||||||
.isEqualTo(Type.COUNTER_DOUBLE);
|
.isEqualTo(Type.MONOTONIC_DOUBLE);
|
||||||
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.MONOTONIC_LONG))
|
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.MONOTONIC_LONG))
|
||||||
.isEqualTo(Type.COUNTER_INT64);
|
.isEqualTo(Type.MONOTONIC_INT64);
|
||||||
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.SUMMARY))
|
assertThat(MetricAdapter.toProtoMetricDescriptorType(Descriptor.Type.SUMMARY))
|
||||||
.isEqualTo(Type.SUMMARY);
|
.isEqualTo(Type.SUMMARY);
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +80,7 @@ public class MetricAdapterTest {
|
||||||
assertThat(MetricAdapter.toProtoValueAtPercentiles(Collections.emptyList())).isEmpty();
|
assertThat(MetricAdapter.toProtoValueAtPercentiles(Collections.emptyList())).isEmpty();
|
||||||
assertThat(
|
assertThat(
|
||||||
MetricAdapter.toProtoValueAtPercentiles(
|
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());
|
.containsExactly(ValueAtPercentile.newBuilder().setPercentile(0.9).setValue(1.1).build());
|
||||||
assertThat(
|
assertThat(
|
||||||
MetricAdapter.toProtoValueAtPercentiles(
|
MetricAdapter.toProtoValueAtPercentiles(
|
||||||
|
|
@ -91,17 +94,25 @@ public class MetricAdapterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toInt64DataPoints() {
|
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(
|
assertThat(
|
||||||
MetricAdapter.toInt64DataPoints(
|
MetricAdapter.toInt64DataPoints(
|
||||||
Collections.singletonList(
|
singletonList(MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5)),
|
||||||
MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5))))
|
descriptor))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
Int64DataPoint.newBuilder()
|
Int64DataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(123)
|
.setStartTimeUnixNano(123)
|
||||||
.setTimeUnixNano(456)
|
.setTimeUnixNano(456)
|
||||||
.addAllLabels(
|
.addAllLabels(
|
||||||
Collections.singletonList(
|
Arrays.asList(
|
||||||
|
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
||||||
.setValue(5)
|
.setValue(5)
|
||||||
.build());
|
.build());
|
||||||
|
|
@ -109,18 +120,22 @@ public class MetricAdapterTest {
|
||||||
MetricAdapter.toInt64DataPoints(
|
MetricAdapter.toInt64DataPoints(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
MetricData.LongPoint.create(123, 456, Labels.empty(), 5),
|
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(
|
.containsExactly(
|
||||||
Int64DataPoint.newBuilder()
|
Int64DataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(123)
|
.setStartTimeUnixNano(123)
|
||||||
.setTimeUnixNano(456)
|
.setTimeUnixNano(456)
|
||||||
|
.addAllLabels(
|
||||||
|
singletonList(StringKeyValue.newBuilder().setKey("ck").setValue("cv").build()))
|
||||||
.setValue(5)
|
.setValue(5)
|
||||||
.build(),
|
.build(),
|
||||||
Int64DataPoint.newBuilder()
|
Int64DataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(321)
|
.setStartTimeUnixNano(321)
|
||||||
.setTimeUnixNano(654)
|
.setTimeUnixNano(654)
|
||||||
.addAllLabels(
|
.addAllLabels(
|
||||||
Collections.singletonList(
|
Arrays.asList(
|
||||||
|
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
||||||
.setValue(7)
|
.setValue(7)
|
||||||
.build());
|
.build());
|
||||||
|
|
@ -128,17 +143,25 @@ public class MetricAdapterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toDoubleDataPoints() {
|
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(
|
assertThat(
|
||||||
MetricAdapter.toDoubleDataPoints(
|
MetricAdapter.toDoubleDataPoints(
|
||||||
Collections.singletonList(
|
singletonList(MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1)),
|
||||||
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1))))
|
descriptor))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
DoubleDataPoint.newBuilder()
|
DoubleDataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(123)
|
.setStartTimeUnixNano(123)
|
||||||
.setTimeUnixNano(456)
|
.setTimeUnixNano(456)
|
||||||
.addAllLabels(
|
.addAllLabels(
|
||||||
Collections.singletonList(
|
Arrays.asList(
|
||||||
|
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
||||||
.setValue(5.1)
|
.setValue(5.1)
|
||||||
.build());
|
.build());
|
||||||
|
|
@ -146,18 +169,22 @@ public class MetricAdapterTest {
|
||||||
MetricAdapter.toDoubleDataPoints(
|
MetricAdapter.toDoubleDataPoints(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
MetricData.DoublePoint.create(123, 456, Labels.empty(), 5.1),
|
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(
|
.containsExactly(
|
||||||
DoubleDataPoint.newBuilder()
|
DoubleDataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(123)
|
.setStartTimeUnixNano(123)
|
||||||
.setTimeUnixNano(456)
|
.setTimeUnixNano(456)
|
||||||
|
.addAllLabels(
|
||||||
|
singletonList(StringKeyValue.newBuilder().setKey("ck").setValue("cv").build()))
|
||||||
.setValue(5.1)
|
.setValue(5.1)
|
||||||
.build(),
|
.build(),
|
||||||
DoubleDataPoint.newBuilder()
|
DoubleDataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(321)
|
.setStartTimeUnixNano(321)
|
||||||
.setTimeUnixNano(654)
|
.setTimeUnixNano(654)
|
||||||
.addAllLabels(
|
.addAllLabels(
|
||||||
Collections.singletonList(
|
Arrays.asList(
|
||||||
|
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
||||||
.setValue(7.1)
|
.setValue(7.1)
|
||||||
.build());
|
.build());
|
||||||
|
|
@ -165,28 +192,32 @@ public class MetricAdapterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toSummaryDataPoints() {
|
public void toSummaryDataPoints() {
|
||||||
assertThat(MetricAdapter.toSummaryDataPoints(Collections.emptyList())).isEmpty();
|
Descriptor descriptor =
|
||||||
|
Descriptor.create(
|
||||||
|
"test", "testDescription", "unit", Descriptor.Type.SUMMARY, Labels.of("ck", "cv"));
|
||||||
assertThat(
|
assertThat(
|
||||||
MetricAdapter.toSummaryDataPoints(
|
MetricAdapter.toSummaryDataPoints(
|
||||||
Collections.singletonList(
|
singletonList(
|
||||||
MetricData.SummaryPoint.create(
|
MetricData.SummaryPoint.create(
|
||||||
123,
|
123,
|
||||||
456,
|
456,
|
||||||
Labels.of("k", "v"),
|
Labels.of("k", "v"),
|
||||||
5,
|
5,
|
||||||
14.2,
|
14.2,
|
||||||
Collections.singletonList(MetricData.ValueAtPercentile.create(0.9, 1.1))))))
|
singletonList(MetricData.ValueAtPercentile.create(0.9, 1.1)))),
|
||||||
|
descriptor))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
SummaryDataPoint.newBuilder()
|
SummaryDataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(123)
|
.setStartTimeUnixNano(123)
|
||||||
.setTimeUnixNano(456)
|
.setTimeUnixNano(456)
|
||||||
.addAllLabels(
|
.addAllLabels(
|
||||||
Collections.singletonList(
|
Arrays.asList(
|
||||||
|
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
||||||
.setCount(5)
|
.setCount(5)
|
||||||
.setSum(14.2)
|
.setSum(14.2)
|
||||||
.addAllPercentileValues(
|
.addAllPercentileValues(
|
||||||
Collections.singletonList(
|
singletonList(
|
||||||
ValueAtPercentile.newBuilder().setPercentile(0.9).setValue(1.1).build()))
|
ValueAtPercentile.newBuilder().setPercentile(0.9).setValue(1.1).build()))
|
||||||
.build());
|
.build());
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
@ -202,11 +233,14 @@ public class MetricAdapterTest {
|
||||||
18.3,
|
18.3,
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
MetricData.ValueAtPercentile.create(0.9, 1.1),
|
MetricData.ValueAtPercentile.create(0.9, 1.1),
|
||||||
MetricData.ValueAtPercentile.create(0.99, 20.3))))))
|
MetricData.ValueAtPercentile.create(0.99, 20.3)))),
|
||||||
|
descriptor))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
SummaryDataPoint.newBuilder()
|
SummaryDataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(123)
|
.setStartTimeUnixNano(123)
|
||||||
.setTimeUnixNano(456)
|
.setTimeUnixNano(456)
|
||||||
|
.addAllLabels(
|
||||||
|
singletonList(StringKeyValue.newBuilder().setKey("ck").setValue("cv").build()))
|
||||||
.setCount(7)
|
.setCount(7)
|
||||||
.setSum(15.3)
|
.setSum(15.3)
|
||||||
.build(),
|
.build(),
|
||||||
|
|
@ -214,7 +248,8 @@ public class MetricAdapterTest {
|
||||||
.setStartTimeUnixNano(321)
|
.setStartTimeUnixNano(321)
|
||||||
.setTimeUnixNano(654)
|
.setTimeUnixNano(654)
|
||||||
.addAllLabels(
|
.addAllLabels(
|
||||||
Collections.singletonList(
|
Arrays.asList(
|
||||||
|
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
||||||
.setCount(9)
|
.setCount(9)
|
||||||
.setSum(18.3)
|
.setSum(18.3)
|
||||||
|
|
@ -240,21 +275,36 @@ public class MetricAdapterTest {
|
||||||
.setName("name")
|
.setName("name")
|
||||||
.setDescription("description")
|
.setDescription("description")
|
||||||
.setUnit("1")
|
.setUnit("1")
|
||||||
.setType(Type.COUNTER_DOUBLE)
|
.setType(Type.MONOTONIC_DOUBLE)
|
||||||
.addAllLabels(
|
.setTemporality(Temporality.CUMULATIVE)
|
||||||
Collections.singletonList(
|
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
|
||||||
.build());
|
.build());
|
||||||
assertThat(
|
assertThat(
|
||||||
MetricAdapter.toProtoMetricDescriptor(
|
MetricAdapter.toProtoMetricDescriptor(
|
||||||
Descriptor.create(
|
Descriptor.create(
|
||||||
"name", "description", "1", Descriptor.Type.MONOTONIC_DOUBLE, Labels.empty())))
|
"name",
|
||||||
|
"description",
|
||||||
|
"1",
|
||||||
|
Descriptor.Type.NON_MONOTONIC_DOUBLE,
|
||||||
|
Labels.empty())))
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
MetricDescriptor.newBuilder()
|
MetricDescriptor.newBuilder()
|
||||||
.setName("name")
|
.setName("name")
|
||||||
.setDescription("description")
|
.setDescription("description")
|
||||||
.setUnit("1")
|
.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());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,11 +318,10 @@ public class MetricAdapterTest {
|
||||||
"description",
|
"description",
|
||||||
"1",
|
"1",
|
||||||
Descriptor.Type.MONOTONIC_LONG,
|
Descriptor.Type.MONOTONIC_LONG,
|
||||||
Labels.of("k", "v")),
|
Labels.of("ck", "cv")),
|
||||||
Resource.getEmpty(),
|
Resource.getEmpty(),
|
||||||
InstrumentationLibraryInfo.getEmpty(),
|
InstrumentationLibraryInfo.getEmpty(),
|
||||||
Collections.singletonList(
|
singletonList(MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5)))))
|
||||||
MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5)))))
|
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
Metric.newBuilder()
|
Metric.newBuilder()
|
||||||
.setMetricDescriptor(
|
.setMetricDescriptor(
|
||||||
|
|
@ -280,18 +329,17 @@ public class MetricAdapterTest {
|
||||||
.setName("name")
|
.setName("name")
|
||||||
.setDescription("description")
|
.setDescription("description")
|
||||||
.setUnit("1")
|
.setUnit("1")
|
||||||
.setType(Type.COUNTER_INT64)
|
.setType(Type.MONOTONIC_INT64)
|
||||||
.addAllLabels(
|
.setTemporality(Temporality.CUMULATIVE)
|
||||||
Collections.singletonList(
|
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
|
||||||
.build())
|
.build())
|
||||||
.addAllInt64DataPoints(
|
.addAllInt64DataPoints(
|
||||||
Collections.singletonList(
|
singletonList(
|
||||||
Int64DataPoint.newBuilder()
|
Int64DataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(123)
|
.setStartTimeUnixNano(123)
|
||||||
.setTimeUnixNano(456)
|
.setTimeUnixNano(456)
|
||||||
.addAllLabels(
|
.addAllLabels(
|
||||||
Collections.singletonList(
|
Arrays.asList(
|
||||||
|
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
||||||
.setValue(5)
|
.setValue(5)
|
||||||
.build()))
|
.build()))
|
||||||
|
|
@ -304,10 +352,10 @@ public class MetricAdapterTest {
|
||||||
"description",
|
"description",
|
||||||
"1",
|
"1",
|
||||||
Descriptor.Type.MONOTONIC_DOUBLE,
|
Descriptor.Type.MONOTONIC_DOUBLE,
|
||||||
Labels.of("k", "v")),
|
Labels.of("ck", "cv")),
|
||||||
Resource.getEmpty(),
|
Resource.getEmpty(),
|
||||||
InstrumentationLibraryInfo.getEmpty(),
|
InstrumentationLibraryInfo.getEmpty(),
|
||||||
Collections.singletonList(
|
singletonList(
|
||||||
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1)))))
|
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1)))))
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
Metric.newBuilder()
|
Metric.newBuilder()
|
||||||
|
|
@ -316,18 +364,17 @@ public class MetricAdapterTest {
|
||||||
.setName("name")
|
.setName("name")
|
||||||
.setDescription("description")
|
.setDescription("description")
|
||||||
.setUnit("1")
|
.setUnit("1")
|
||||||
.setType(Type.COUNTER_DOUBLE)
|
.setType(Type.MONOTONIC_DOUBLE)
|
||||||
.addAllLabels(
|
.setTemporality(Temporality.CUMULATIVE)
|
||||||
Collections.singletonList(
|
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
|
||||||
.build())
|
.build())
|
||||||
.addAllDoubleDataPoints(
|
.addAllDoubleDataPoints(
|
||||||
Collections.singletonList(
|
singletonList(
|
||||||
DoubleDataPoint.newBuilder()
|
DoubleDataPoint.newBuilder()
|
||||||
.setStartTimeUnixNano(123)
|
.setStartTimeUnixNano(123)
|
||||||
.setTimeUnixNano(456)
|
.setTimeUnixNano(456)
|
||||||
.addAllLabels(
|
.addAllLabels(
|
||||||
Collections.singletonList(
|
Arrays.asList(
|
||||||
|
StringKeyValue.newBuilder().setKey("ck").setValue("cv").build(),
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
||||||
.setValue(5.1)
|
.setValue(5.1)
|
||||||
.build()))
|
.build()))
|
||||||
|
|
@ -344,11 +391,10 @@ public class MetricAdapterTest {
|
||||||
io.opentelemetry.proto.resource.v1.Resource resourceProto =
|
io.opentelemetry.proto.resource.v1.Resource resourceProto =
|
||||||
io.opentelemetry.proto.resource.v1.Resource.newBuilder()
|
io.opentelemetry.proto.resource.v1.Resource.newBuilder()
|
||||||
.addAllAttributes(
|
.addAllAttributes(
|
||||||
Collections.singletonList(
|
singletonList(
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("ka")
|
.setKey("ka")
|
||||||
.setStringValue("va")
|
.setValue(AnyValue.newBuilder().setStringValue("va").build())
|
||||||
.setType(ValueType.STRING)
|
|
||||||
.build()))
|
.build()))
|
||||||
.build();
|
.build();
|
||||||
io.opentelemetry.proto.resource.v1.Resource emptyResourceProto =
|
io.opentelemetry.proto.resource.v1.Resource emptyResourceProto =
|
||||||
|
|
@ -366,10 +412,8 @@ public class MetricAdapterTest {
|
||||||
.setName("name")
|
.setName("name")
|
||||||
.setDescription("description")
|
.setDescription("description")
|
||||||
.setUnit("1")
|
.setUnit("1")
|
||||||
.setType(Type.COUNTER_DOUBLE)
|
.setType(Type.MONOTONIC_DOUBLE)
|
||||||
.addAllLabels(
|
.setTemporality(Temporality.CUMULATIVE)
|
||||||
Collections.singletonList(
|
|
||||||
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
|
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -394,7 +438,7 @@ public class MetricAdapterTest {
|
||||||
ResourceMetrics.newBuilder()
|
ResourceMetrics.newBuilder()
|
||||||
.setResource(resourceProto)
|
.setResource(resourceProto)
|
||||||
.addAllInstrumentationLibraryMetrics(
|
.addAllInstrumentationLibraryMetrics(
|
||||||
Collections.singletonList(
|
singletonList(
|
||||||
InstrumentationLibraryMetrics.newBuilder()
|
InstrumentationLibraryMetrics.newBuilder()
|
||||||
.setInstrumentationLibrary(instrumentationLibraryProto)
|
.setInstrumentationLibrary(instrumentationLibraryProto)
|
||||||
.addAllMetrics(ImmutableList.of(metricNoPoints, metricNoPoints))
|
.addAllMetrics(ImmutableList.of(metricNoPoints, metricNoPoints))
|
||||||
|
|
@ -406,11 +450,11 @@ public class MetricAdapterTest {
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
InstrumentationLibraryMetrics.newBuilder()
|
InstrumentationLibraryMetrics.newBuilder()
|
||||||
.setInstrumentationLibrary(emptyInstrumentationLibraryProto)
|
.setInstrumentationLibrary(emptyInstrumentationLibraryProto)
|
||||||
.addAllMetrics(Collections.singletonList(metricNoPoints))
|
.addAllMetrics(singletonList(metricNoPoints))
|
||||||
.build(),
|
.build(),
|
||||||
InstrumentationLibraryMetrics.newBuilder()
|
InstrumentationLibraryMetrics.newBuilder()
|
||||||
.setInstrumentationLibrary(instrumentationLibraryProto)
|
.setInstrumentationLibrary(instrumentationLibraryProto)
|
||||||
.addAllMetrics(Collections.singletonList(metricNoPoints))
|
.addAllMetrics(singletonList(metricNoPoints))
|
||||||
.build()))
|
.build()))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import io.opentelemetry.common.AttributeValue;
|
import io.opentelemetry.common.AttributeValue;
|
||||||
import io.opentelemetry.common.Attributes;
|
import io.opentelemetry.common.Attributes;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
|
import io.opentelemetry.proto.common.v1.AnyValue;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
|
import io.opentelemetry.proto.common.v1.KeyValue;
|
||||||
import io.opentelemetry.sdk.resources.Resource;
|
import io.opentelemetry.sdk.resources.Resource;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
@ -46,25 +46,21 @@ public class ResourceAdapterTest {
|
||||||
AttributeValue.doubleAttributeValue(100.3))))
|
AttributeValue.doubleAttributeValue(100.3))))
|
||||||
.getAttributesList())
|
.getAttributesList())
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key_bool")
|
.setKey("key_bool")
|
||||||
.setBoolValue(true)
|
.setValue(AnyValue.newBuilder().setBoolValue(true).build())
|
||||||
.setType(ValueType.BOOL)
|
|
||||||
.build(),
|
.build(),
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key_string")
|
.setKey("key_string")
|
||||||
.setStringValue("string")
|
.setValue(AnyValue.newBuilder().setStringValue("string").build())
|
||||||
.setType(ValueType.STRING)
|
|
||||||
.build(),
|
.build(),
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key_int")
|
.setKey("key_int")
|
||||||
.setIntValue(100)
|
.setValue(AnyValue.newBuilder().setIntValue(100).build())
|
||||||
.setType(ValueType.INT)
|
|
||||||
.build(),
|
.build(),
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key_double")
|
.setKey("key_double")
|
||||||
.setDoubleValue(100.3)
|
.setValue(AnyValue.newBuilder().setDoubleValue(100.3).build())
|
||||||
.setType(ValueType.DOUBLE)
|
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import io.opentelemetry.common.AttributeValue;
|
import io.opentelemetry.common.AttributeValue;
|
||||||
import io.opentelemetry.common.Attributes;
|
import io.opentelemetry.common.Attributes;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
|
import io.opentelemetry.proto.common.v1.AnyValue;
|
||||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
|
import io.opentelemetry.proto.common.v1.KeyValue;
|
||||||
import io.opentelemetry.proto.trace.v1.Span;
|
import io.opentelemetry.proto.trace.v1.Span;
|
||||||
import io.opentelemetry.proto.trace.v1.Span.SpanKind;
|
import io.opentelemetry.proto.trace.v1.Span.SpanKind;
|
||||||
import io.opentelemetry.proto.trace.v1.Status;
|
import io.opentelemetry.proto.trace.v1.Status;
|
||||||
|
|
@ -87,10 +87,9 @@ public class SpanAdapterTest {
|
||||||
assertThat(span.getEndTimeUnixNano()).isEqualTo(12349);
|
assertThat(span.getEndTimeUnixNano()).isEqualTo(12349);
|
||||||
assertThat(span.getAttributesList())
|
assertThat(span.getAttributesList())
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key")
|
.setKey("key")
|
||||||
.setBoolValue(true)
|
.setValue(AnyValue.newBuilder().setBoolValue(true).build())
|
||||||
.setType(ValueType.BOOL)
|
|
||||||
.build());
|
.build());
|
||||||
assertThat(span.getDroppedAttributesCount()).isEqualTo(1);
|
assertThat(span.getDroppedAttributesCount()).isEqualTo(1);
|
||||||
assertThat(span.getEventsList())
|
assertThat(span.getEventsList())
|
||||||
|
|
@ -255,10 +254,9 @@ public class SpanAdapterTest {
|
||||||
.setTimeUnixNano(12345)
|
.setTimeUnixNano(12345)
|
||||||
.setName("test_with_attributes")
|
.setName("test_with_attributes")
|
||||||
.addAttributes(
|
.addAttributes(
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key_string")
|
.setKey("key_string")
|
||||||
.setStringValue("string")
|
.setValue(AnyValue.newBuilder().setStringValue("string").build())
|
||||||
.setType(ValueType.STRING)
|
|
||||||
.build())
|
.build())
|
||||||
.setDroppedAttributesCount(4)
|
.setDroppedAttributesCount(4)
|
||||||
.build());
|
.build());
|
||||||
|
|
@ -287,10 +285,9 @@ public class SpanAdapterTest {
|
||||||
.setTraceId(ByteString.copyFrom(TRACE_ID_BYTES))
|
.setTraceId(ByteString.copyFrom(TRACE_ID_BYTES))
|
||||||
.setSpanId(ByteString.copyFrom(SPAN_ID_BYTES))
|
.setSpanId(ByteString.copyFrom(SPAN_ID_BYTES))
|
||||||
.addAttributes(
|
.addAttributes(
|
||||||
AttributeKeyValue.newBuilder()
|
KeyValue.newBuilder()
|
||||||
.setKey("key_string")
|
.setKey("key_string")
|
||||||
.setStringValue("string")
|
.setValue(AnyValue.newBuilder().setStringValue("string").build())
|
||||||
.setType(ValueType.STRING)
|
|
||||||
.build())
|
.build())
|
||||||
.setDroppedAttributesCount(4)
|
.setDroppedAttributesCount(4)
|
||||||
.build());
|
.build());
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6a4eb2fa6f25569910f7b17216e3a2087496bbce
|
Subproject commit e43e1abc40428a6ee98e3bfd79bec1dfa2ed18cd
|
||||||
Loading…
Reference in New Issue