Manual cherrypick for commit 5e6be2bb52
This commit is contained in:
parent
f13fe7961d
commit
a43a962807
|
|
@ -97,6 +97,10 @@ class OtlpJsonLoggingMetricExporterTest {
|
||||||
+ " \"key\": \"cat\","
|
+ " \"key\": \"cat\","
|
||||||
+ " \"value\": {\"stringValue\": \"meow\"}"
|
+ " \"value\": {\"stringValue\": \"meow\"}"
|
||||||
+ " }],"
|
+ " }],"
|
||||||
|
+ " \"labels\": [{"
|
||||||
|
+ " \"key\": \"cat\","
|
||||||
|
+ " \"value\": \"meow\""
|
||||||
|
+ " }],"
|
||||||
+ " \"startTimeUnixNano\": \"1\","
|
+ " \"startTimeUnixNano\": \"1\","
|
||||||
+ " \"timeUnixNano\": \"2\","
|
+ " \"timeUnixNano\": \"2\","
|
||||||
+ " \"asDouble\": 4.0"
|
+ " \"asDouble\": 4.0"
|
||||||
|
|
@ -120,6 +124,10 @@ class OtlpJsonLoggingMetricExporterTest {
|
||||||
+ " \"key\": \"cat\","
|
+ " \"key\": \"cat\","
|
||||||
+ " \"value\": {\"stringValue\": \"meow\"}"
|
+ " \"value\": {\"stringValue\": \"meow\"}"
|
||||||
+ " }],"
|
+ " }],"
|
||||||
|
+ " \"labels\": [{"
|
||||||
|
+ " \"key\": \"cat\","
|
||||||
|
+ " \"value\": \"meow\""
|
||||||
|
+ " }],"
|
||||||
+ " \"startTimeUnixNano\": \"1\","
|
+ " \"startTimeUnixNano\": \"1\","
|
||||||
+ " \"timeUnixNano\": \"2\","
|
+ " \"timeUnixNano\": \"2\","
|
||||||
+ " \"asDouble\": 4.0"
|
+ " \"asDouble\": 4.0"
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import static io.opentelemetry.proto.metrics.v1.AggregationTemporality.AGGREGATI
|
||||||
import static io.opentelemetry.proto.metrics.v1.AggregationTemporality.AGGREGATION_TEMPORALITY_DELTA;
|
import static io.opentelemetry.proto.metrics.v1.AggregationTemporality.AGGREGATION_TEMPORALITY_DELTA;
|
||||||
import static io.opentelemetry.proto.metrics.v1.AggregationTemporality.AGGREGATION_TEMPORALITY_UNSPECIFIED;
|
import static io.opentelemetry.proto.metrics.v1.AggregationTemporality.AGGREGATION_TEMPORALITY_UNSPECIFIED;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
import io.opentelemetry.proto.common.v1.KeyValue;
|
||||||
import io.opentelemetry.proto.metrics.v1.AggregationTemporality;
|
import io.opentelemetry.proto.metrics.v1.AggregationTemporality;
|
||||||
import io.opentelemetry.proto.metrics.v1.Gauge;
|
import io.opentelemetry.proto.metrics.v1.Gauge;
|
||||||
import io.opentelemetry.proto.metrics.v1.Histogram;
|
import io.opentelemetry.proto.metrics.v1.Histogram;
|
||||||
|
|
@ -39,6 +41,7 @@ import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/** Converter from SDK {@link MetricData} to OTLP {@link ResourceMetrics}. */
|
/** Converter from SDK {@link MetricData} to OTLP {@link ResourceMetrics}. */
|
||||||
public final class MetricAdapter {
|
public final class MetricAdapter {
|
||||||
|
|
@ -187,6 +190,8 @@ public final class MetricAdapter {
|
||||||
return AGGREGATION_TEMPORALITY_UNSPECIFIED;
|
return AGGREGATION_TEMPORALITY_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fill labels too until Collector supports attributes and users have had a chance to update.
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
static List<NumberDataPoint> toIntDataPoints(Collection<LongPointData> points) {
|
static List<NumberDataPoint> toIntDataPoints(Collection<LongPointData> points) {
|
||||||
List<NumberDataPoint> result = new ArrayList<>(points.size());
|
List<NumberDataPoint> result = new ArrayList<>(points.size());
|
||||||
for (LongPointData longPoint : points) {
|
for (LongPointData longPoint : points) {
|
||||||
|
|
@ -195,15 +200,14 @@ public final class MetricAdapter {
|
||||||
.setStartTimeUnixNano(longPoint.getStartEpochNanos())
|
.setStartTimeUnixNano(longPoint.getStartEpochNanos())
|
||||||
.setTimeUnixNano(longPoint.getEpochNanos())
|
.setTimeUnixNano(longPoint.getEpochNanos())
|
||||||
.setAsInt(longPoint.getValue());
|
.setAsInt(longPoint.getValue());
|
||||||
longPoint
|
fillAttributes(longPoint.getAttributes(), builder::addAttributes, builder::addLabels);
|
||||||
.getAttributes()
|
|
||||||
.forEach(
|
|
||||||
(key, value) -> builder.addAttributes(CommonAdapter.toProtoAttribute(key, value)));
|
|
||||||
result.add(builder.build());
|
result.add(builder.build());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fill labels too until Collector supports attributes and users have had a chance to update.
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
static Collection<NumberDataPoint> toDoubleDataPoints(Collection<DoublePointData> points) {
|
static Collection<NumberDataPoint> toDoubleDataPoints(Collection<DoublePointData> points) {
|
||||||
List<NumberDataPoint> result = new ArrayList<>(points.size());
|
List<NumberDataPoint> result = new ArrayList<>(points.size());
|
||||||
for (DoublePointData doublePoint : points) {
|
for (DoublePointData doublePoint : points) {
|
||||||
|
|
@ -212,15 +216,14 @@ public final class MetricAdapter {
|
||||||
.setStartTimeUnixNano(doublePoint.getStartEpochNanos())
|
.setStartTimeUnixNano(doublePoint.getStartEpochNanos())
|
||||||
.setTimeUnixNano(doublePoint.getEpochNanos())
|
.setTimeUnixNano(doublePoint.getEpochNanos())
|
||||||
.setAsDouble(doublePoint.getValue());
|
.setAsDouble(doublePoint.getValue());
|
||||||
doublePoint
|
fillAttributes(doublePoint.getAttributes(), builder::addAttributes, builder::addLabels);
|
||||||
.getAttributes()
|
|
||||||
.forEach(
|
|
||||||
(key, value) -> builder.addAttributes(CommonAdapter.toProtoAttribute(key, value)));
|
|
||||||
result.add(builder.build());
|
result.add(builder.build());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fill labels too until Collector supports attributes and users have had a chance to update.
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
static List<SummaryDataPoint> toSummaryDataPoints(Collection<DoubleSummaryPointData> points) {
|
static List<SummaryDataPoint> toSummaryDataPoints(Collection<DoubleSummaryPointData> points) {
|
||||||
List<SummaryDataPoint> result = new ArrayList<>(points.size());
|
List<SummaryDataPoint> result = new ArrayList<>(points.size());
|
||||||
for (DoubleSummaryPointData doubleSummaryPoint : points) {
|
for (DoubleSummaryPointData doubleSummaryPoint : points) {
|
||||||
|
|
@ -230,10 +233,8 @@ public final class MetricAdapter {
|
||||||
.setTimeUnixNano(doubleSummaryPoint.getEpochNanos())
|
.setTimeUnixNano(doubleSummaryPoint.getEpochNanos())
|
||||||
.setCount(doubleSummaryPoint.getCount())
|
.setCount(doubleSummaryPoint.getCount())
|
||||||
.setSum(doubleSummaryPoint.getSum());
|
.setSum(doubleSummaryPoint.getSum());
|
||||||
doubleSummaryPoint
|
fillAttributes(
|
||||||
.getAttributes()
|
doubleSummaryPoint.getAttributes(), builder::addAttributes, builder::addLabels);
|
||||||
.forEach(
|
|
||||||
(key, value) -> builder.addAttributes(CommonAdapter.toProtoAttribute(key, value)));
|
|
||||||
// Not calling directly addAllQuantileValues because that generates couple of unnecessary
|
// Not calling directly addAllQuantileValues because that generates couple of unnecessary
|
||||||
// allocations if empty list.
|
// allocations if empty list.
|
||||||
if (!doubleSummaryPoint.getPercentileValues().isEmpty()) {
|
if (!doubleSummaryPoint.getPercentileValues().isEmpty()) {
|
||||||
|
|
@ -250,6 +251,8 @@ public final class MetricAdapter {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fill labels too until Collector supports attributes and users have had a chance to update.
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
static Collection<HistogramDataPoint> toHistogramDataPoints(
|
static Collection<HistogramDataPoint> toHistogramDataPoints(
|
||||||
Collection<DoubleHistogramPointData> points) {
|
Collection<DoubleHistogramPointData> points) {
|
||||||
List<HistogramDataPoint> result = new ArrayList<>(points.size());
|
List<HistogramDataPoint> result = new ArrayList<>(points.size());
|
||||||
|
|
@ -265,14 +268,29 @@ public final class MetricAdapter {
|
||||||
if (!boundaries.isEmpty()) {
|
if (!boundaries.isEmpty()) {
|
||||||
builder.addAllExplicitBounds(boundaries);
|
builder.addAllExplicitBounds(boundaries);
|
||||||
}
|
}
|
||||||
doubleHistogramPoint
|
fillAttributes(
|
||||||
.getAttributes()
|
doubleHistogramPoint.getAttributes(), builder::addAttributes, builder::addLabels);
|
||||||
.forEach(
|
|
||||||
(key, value) -> builder.addAttributes(CommonAdapter.toProtoAttribute(key, value)));
|
|
||||||
result.add(builder.build());
|
result.add(builder.build());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fill labels too until Collector supports attributes and users have had a chance to update.
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private static void fillAttributes(
|
||||||
|
Attributes attributes,
|
||||||
|
Consumer<KeyValue> attributeSetter,
|
||||||
|
Consumer<io.opentelemetry.proto.common.v1.StringKeyValue> labelSetter) {
|
||||||
|
attributes.forEach(
|
||||||
|
(key, value) -> {
|
||||||
|
attributeSetter.accept(CommonAdapter.toProtoAttribute(key, value));
|
||||||
|
labelSetter.accept(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey(key.getKey())
|
||||||
|
.setValue(value.toString())
|
||||||
|
.build());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private MetricAdapter() {}
|
private MetricAdapter() {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ import io.opentelemetry.sdk.resources.Resource;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
// Fill deprecated APIs before removing them after users get a chance to migrate.
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
class MetricAdapterTest {
|
class MetricAdapterTest {
|
||||||
|
|
||||||
private static final Attributes KV_ATTR = Attributes.of(stringKey("k"), "v");
|
private static final Attributes KV_ATTR = Attributes.of(stringKey("k"), "v");
|
||||||
|
|
@ -65,6 +67,11 @@ class MetricAdapterTest {
|
||||||
.addAllAttributes(
|
.addAllAttributes(
|
||||||
singletonList(
|
singletonList(
|
||||||
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsInt(5)
|
.setAsInt(5)
|
||||||
.build());
|
.build());
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
@ -84,6 +91,11 @@ class MetricAdapterTest {
|
||||||
.addAllAttributes(
|
.addAllAttributes(
|
||||||
singletonList(
|
singletonList(
|
||||||
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsInt(7)
|
.setAsInt(7)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
@ -101,6 +113,11 @@ class MetricAdapterTest {
|
||||||
.addAllAttributes(
|
.addAllAttributes(
|
||||||
singletonList(
|
singletonList(
|
||||||
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsDouble(5.1)
|
.setAsDouble(5.1)
|
||||||
.build());
|
.build());
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
@ -120,6 +137,11 @@ class MetricAdapterTest {
|
||||||
.addAllAttributes(
|
.addAllAttributes(
|
||||||
singletonList(
|
singletonList(
|
||||||
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsDouble(7.1)
|
.setAsDouble(7.1)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
@ -143,6 +165,11 @@ class MetricAdapterTest {
|
||||||
.addAllAttributes(
|
.addAllAttributes(
|
||||||
singletonList(
|
singletonList(
|
||||||
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setCount(5)
|
.setCount(5)
|
||||||
.setSum(14.2)
|
.setSum(14.2)
|
||||||
.addQuantileValues(
|
.addQuantileValues(
|
||||||
|
|
@ -178,6 +205,11 @@ class MetricAdapterTest {
|
||||||
.addAllAttributes(
|
.addAllAttributes(
|
||||||
singletonList(
|
singletonList(
|
||||||
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setCount(9)
|
.setCount(9)
|
||||||
.setSum(18.3)
|
.setSum(18.3)
|
||||||
.addQuantileValues(
|
.addQuantileValues(
|
||||||
|
|
@ -214,6 +246,11 @@ class MetricAdapterTest {
|
||||||
.addAllAttributes(
|
.addAllAttributes(
|
||||||
singletonList(
|
singletonList(
|
||||||
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
KeyValue.newBuilder().setKey("k").setValue(stringValue("v")).build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setCount(6)
|
.setCount(6)
|
||||||
.setSum(14.2)
|
.setSum(14.2)
|
||||||
.addBucketCounts(1)
|
.addBucketCounts(1)
|
||||||
|
|
@ -262,6 +299,11 @@ class MetricAdapterTest {
|
||||||
.setKey("k")
|
.setKey("k")
|
||||||
.setValue(stringValue("v"))
|
.setValue(stringValue("v"))
|
||||||
.build()))
|
.build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsInt(5)
|
.setAsInt(5)
|
||||||
.build())
|
.build())
|
||||||
.build())
|
.build())
|
||||||
|
|
@ -297,6 +339,11 @@ class MetricAdapterTest {
|
||||||
.setKey("k")
|
.setKey("k")
|
||||||
.setValue(stringValue("v"))
|
.setValue(stringValue("v"))
|
||||||
.build()))
|
.build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsDouble(5.1)
|
.setAsDouble(5.1)
|
||||||
.build())
|
.build())
|
||||||
.build())
|
.build())
|
||||||
|
|
@ -336,6 +383,11 @@ class MetricAdapterTest {
|
||||||
.setKey("k")
|
.setKey("k")
|
||||||
.setValue(stringValue("v"))
|
.setValue(stringValue("v"))
|
||||||
.build()))
|
.build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsInt(5)
|
.setAsInt(5)
|
||||||
.build())
|
.build())
|
||||||
.build())
|
.build())
|
||||||
|
|
@ -371,6 +423,11 @@ class MetricAdapterTest {
|
||||||
.setKey("k")
|
.setKey("k")
|
||||||
.setValue(stringValue("v"))
|
.setValue(stringValue("v"))
|
||||||
.build()))
|
.build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsDouble(5.1)
|
.setAsDouble(5.1)
|
||||||
.build())
|
.build())
|
||||||
.build())
|
.build())
|
||||||
|
|
@ -406,6 +463,11 @@ class MetricAdapterTest {
|
||||||
.setKey("k")
|
.setKey("k")
|
||||||
.setValue(stringValue("v"))
|
.setValue(stringValue("v"))
|
||||||
.build()))
|
.build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsInt(5)
|
.setAsInt(5)
|
||||||
.build())
|
.build())
|
||||||
.build())
|
.build())
|
||||||
|
|
@ -437,6 +499,11 @@ class MetricAdapterTest {
|
||||||
.setKey("k")
|
.setKey("k")
|
||||||
.setValue(stringValue("v"))
|
.setValue(stringValue("v"))
|
||||||
.build()))
|
.build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsDouble(5.1)
|
.setAsDouble(5.1)
|
||||||
.build())
|
.build())
|
||||||
.build())
|
.build())
|
||||||
|
|
@ -481,6 +548,11 @@ class MetricAdapterTest {
|
||||||
.setKey("k")
|
.setKey("k")
|
||||||
.setValue(stringValue("v"))
|
.setValue(stringValue("v"))
|
||||||
.build()))
|
.build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setCount(5)
|
.setCount(5)
|
||||||
.setSum(33d)
|
.setSum(33d)
|
||||||
.addQuantileValues(
|
.addQuantileValues(
|
||||||
|
|
@ -536,6 +608,11 @@ class MetricAdapterTest {
|
||||||
.setKey("k")
|
.setKey("k")
|
||||||
.setValue(stringValue("v"))
|
.setValue(stringValue("v"))
|
||||||
.build()))
|
.build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setCount(33)
|
.setCount(33)
|
||||||
.setSum(4.0)
|
.setSum(4.0)
|
||||||
.addBucketCounts(33)
|
.addBucketCounts(33)
|
||||||
|
|
@ -581,6 +658,11 @@ class MetricAdapterTest {
|
||||||
.setKey("k")
|
.setKey("k")
|
||||||
.setValue(stringValue("v"))
|
.setValue(stringValue("v"))
|
||||||
.build()))
|
.build()))
|
||||||
|
.addLabels(
|
||||||
|
io.opentelemetry.proto.common.v1.StringKeyValue.newBuilder()
|
||||||
|
.setKey("k")
|
||||||
|
.setValue("v")
|
||||||
|
.build())
|
||||||
.setAsDouble(5.0)
|
.setAsDouble(5.0)
|
||||||
.build())
|
.build())
|
||||||
.build())
|
.build())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue