Skip to content

Commit

Permalink
Update to OTel SDK 1.3.0 (open-telemetry#3253)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuraag Agrawal authored and robododge committed Jun 17, 2021
1 parent da20712 commit 5b985ea
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 42 deletions.
4 changes: 2 additions & 2 deletions dependencyManagement/dependencyManagement.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ val DEPENDENCY_BOMS = listOf(
"com.fasterxml.jackson:jackson-bom:2.12.3",
"com.google.guava:guava-bom:30.1.1-jre",
"org.codehaus.groovy:groovy-bom:${groovyVersion}",
"io.opentelemetry:opentelemetry-bom:1.2.0",
"io.opentelemetry:opentelemetry-bom-alpha:1.2.0-alpha",
"io.opentelemetry:opentelemetry-bom:1.3.0",
"io.opentelemetry:opentelemetry-bom-alpha:1.3.0-alpha",
"org.junit:junit-bom:5.7.1"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import static io.opentelemetry.sdk.metrics.data.MetricDataType.DOUBLE_GAUGE
import static io.opentelemetry.sdk.metrics.data.MetricDataType.DOUBLE_SUM
import static io.opentelemetry.sdk.metrics.data.MetricDataType.LONG_GAUGE
import static io.opentelemetry.sdk.metrics.data.MetricDataType.LONG_SUM
import static io.opentelemetry.sdk.metrics.data.MetricDataType.SUMMARY
import static java.util.concurrent.TimeUnit.SECONDS

Expand Down Expand Up @@ -62,10 +60,10 @@ class MeterTest extends AgentInstrumentationSpecification {

where:
builderMethod | bind | value1 | value2 | expectedValue | expectedType
"longCounterBuilder" | false | 5 | 6 | 11 | LONG_SUM
"longCounterBuilder" | true | 5 | 6 | 11 | LONG_SUM
"longUpDownCounterBuilder" | false | 5 | 6 | 11 | LONG_SUM
"longUpDownCounterBuilder" | true | 5 | 6 | 11 | LONG_SUM
"longCounterBuilder" | false | 5 | 6 | 11 | DOUBLE_SUM
"longCounterBuilder" | true | 5 | 6 | 11 | DOUBLE_SUM
"longUpDownCounterBuilder" | false | 5 | 6 | 11 | DOUBLE_SUM
"longUpDownCounterBuilder" | true | 5 | 6 | 11 | DOUBLE_SUM
"doubleCounterBuilder" | false | 5.5 | 6.6 | 12.1 | DOUBLE_SUM
"doubleCounterBuilder" | true | 5.5 | 6.6 | 12.1 | DOUBLE_SUM
"doubleUpDownCounterBuilder" | false | 5.5 | 6.6 | 12.1 | DOUBLE_SUM
Expand Down Expand Up @@ -183,7 +181,6 @@ class MeterTest extends AgentInstrumentationSpecification {
metricData.instrumentationLibraryInfo.version == "1.2.3"
points(metricData).size() == 1
def point = points(metricData).iterator().next()
point.labels == Labels.of("q", "r")
if (builderMethod.startsWith("long")) {
point.value == 123
} else {
Expand All @@ -192,9 +189,9 @@ class MeterTest extends AgentInstrumentationSpecification {

where:
builderMethod | valueMethod | expectedType
"longSumObserverBuilder" | "value" | LONG_SUM
"longUpDownSumObserverBuilder" | "value" | LONG_SUM
"longValueObserverBuilder" | "sum" | LONG_GAUGE
"longSumObserverBuilder" | "value" | DOUBLE_SUM
"longUpDownSumObserverBuilder" | "value" | DOUBLE_SUM
"longValueObserverBuilder" | "sum" | DOUBLE_GAUGE
"doubleSumObserverBuilder" | "value" | DOUBLE_SUM
"doubleUpDownSumObserverBuilder" | "value" | DOUBLE_SUM
"doubleValueObserverBuilder" | "sum" | DOUBLE_GAUGE
Expand Down Expand Up @@ -228,12 +225,11 @@ class MeterTest extends AgentInstrumentationSpecification {
metricData != null
metricData.description == "d"
metricData.unit == "u"
metricData.type == LONG_SUM
metricData.type == DOUBLE_SUM
metricData.instrumentationLibraryInfo.name == instrumentationName
metricData.instrumentationLibraryInfo.version == "1.2.3"
points(metricData).size() == 1
def point = points(metricData).iterator().next()
point.labels == Labels.of("q", "r")
point.value == 11

def metricData2 = findMetric(instrumentationName, "test2")
Expand All @@ -245,7 +241,6 @@ class MeterTest extends AgentInstrumentationSpecification {
metricData2.instrumentationLibraryInfo.version == "1.2.3"
points(metricData2).size() == 1
def point2 = points(metricData2).iterator().next()
point2.labels == Labels.of("q", "r")
point2.count == 2
point2.sum == 12.1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected void startEnvironment() {
backend =
new GenericContainer<>(
DockerImageName.parse(
"ghcr.io/open-telemetry/java-test-containers:smoke-fake-backend-20210324.684269693"))
"ghcr.io/open-telemetry/java-test-containers:smoke-fake-backend-20210611.927888723"))
.withExposedPorts(BACKEND_PORT)
.waitingFor(Wait.forHttp("/health").forPort(BACKEND_PORT))
.withNetwork(network)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void startEnvironment() {
.exec()
.getId();

String backendSuffix = "-windows-20210427.788400024";
String backendSuffix = "-windows-20210611.927888723";

String backendImageName =
"ghcr.io/open-telemetry/java-test-containers:smoke-fake-backend" + backendSuffix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
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.DoubleHistogramDataPoint;
import io.opentelemetry.proto.metrics.v1.DoubleSum;
import io.opentelemetry.proto.metrics.v1.DoubleSummaryDataPoint;
import io.opentelemetry.proto.metrics.v1.HistogramDataPoint;
import io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics;
import io.opentelemetry.proto.metrics.v1.IntDataPoint;
import io.opentelemetry.proto.metrics.v1.IntSum;
import io.opentelemetry.proto.metrics.v1.Metric;
import io.opentelemetry.proto.metrics.v1.NumberDataPoint;
import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
import io.opentelemetry.proto.metrics.v1.Sum;
import io.opentelemetry.proto.metrics.v1.SummaryDataPoint;
import io.opentelemetry.proto.resource.v1.Resource;
import io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans;
import io.opentelemetry.proto.trace.v1.ResourceSpans;
Expand Down Expand Up @@ -274,15 +274,14 @@ private static MetricData createMetricData(
metric.getDescription(),
metric.getUnit(),
LongGaugeData.create(getIntPoints(metric.getIntGauge().getDataPointsList())));
case DOUBLE_GAUGE:
case GAUGE:
return MetricData.createDoubleGauge(
resource,
instrumentationLibraryInfo,
metric.getName(),
metric.getDescription(),
metric.getUnit(),
DoubleGaugeData.create(
getDoublePointDatas(metric.getDoubleGauge().getDataPointsList())));
DoubleGaugeData.create(getDoublePointDatas(metric.getGauge().getDataPointsList())));
case INT_SUM:
IntSum intSum = metric.getIntSum();
return MetricData.createLongSum(
Expand All @@ -295,8 +294,8 @@ private static MetricData createMetricData(
intSum.getIsMonotonic(),
getTemporality(intSum.getAggregationTemporality()),
getIntPoints(metric.getIntSum().getDataPointsList())));
case DOUBLE_SUM:
DoubleSum doubleSum = metric.getDoubleSum();
case SUM:
Sum doubleSum = metric.getSum();
return MetricData.createDoubleSum(
resource,
instrumentationLibraryInfo,
Expand All @@ -306,26 +305,26 @@ private static MetricData createMetricData(
DoubleSumData.create(
doubleSum.getIsMonotonic(),
getTemporality(doubleSum.getAggregationTemporality()),
getDoublePointDatas(metric.getDoubleSum().getDataPointsList())));
case DOUBLE_HISTOGRAM:
getDoublePointDatas(metric.getSum().getDataPointsList())));
case HISTOGRAM:
return MetricData.createDoubleHistogram(
resource,
instrumentationLibraryInfo,
metric.getName(),
metric.getDescription(),
metric.getUnit(),
DoubleHistogramData.create(
getTemporality(metric.getDoubleHistogram().getAggregationTemporality()),
getDoubleHistogramDataPoints(metric.getDoubleHistogram().getDataPointsList())));
case DOUBLE_SUMMARY:
getTemporality(metric.getHistogram().getAggregationTemporality()),
getDoubleHistogramDataPoints(metric.getHistogram().getDataPointsList())));
case SUMMARY:
return MetricData.createDoubleSummary(
resource,
instrumentationLibraryInfo,
metric.getName(),
metric.getDescription(),
metric.getUnit(),
DoubleSummaryData.create(
getDoubleSummaryDataPoints(metric.getDoubleSummary().getDataPointsList())));
getDoubleSummaryDataPoints(metric.getSummary().getDataPointsList())));
default:
throw new AssertionError("Unexpected metric data: " + metric.getDataCase());
}
Expand All @@ -351,20 +350,31 @@ private static List<LongPointData> getIntPoints(List<IntDataPoint> points) {
.collect(toList());
}

private static List<DoublePointData> getDoublePointDatas(List<DoubleDataPoint> points) {
private static List<DoublePointData> getDoublePointDatas(List<NumberDataPoint> points) {
return points.stream()
.map(
point ->
DoublePointData.create(
point.getStartTimeUnixNano(),
point.getTimeUnixNano(),
createLabels(point.getLabelsList()),
point.getValue()))
point -> {
final double value;
switch (point.getValueCase()) {
case AS_INT:
value = point.getAsInt();
break;
case AS_DOUBLE:
default:
value = point.getAsDouble();
break;
}
return DoublePointData.create(
point.getStartTimeUnixNano(),
point.getTimeUnixNano(),
createLabels(point.getLabelsList()),
value);
})
.collect(toList());
}

private static Collection<DoubleHistogramPointData> getDoubleHistogramDataPoints(
List<DoubleHistogramDataPoint> dataPointsList) {
List<HistogramDataPoint> dataPointsList) {
return dataPointsList.stream()
.map(
point ->
Expand All @@ -379,7 +389,7 @@ private static Collection<DoubleHistogramPointData> getDoubleHistogramDataPoints
}

private static Collection<DoubleSummaryPointData> getDoubleSummaryDataPoints(
List<DoubleSummaryDataPoint> dataPointsList) {
List<SummaryDataPoint> dataPointsList) {
return dataPointsList.stream()
.map(
point ->
Expand All @@ -393,7 +403,7 @@ private static Collection<DoubleSummaryPointData> getDoubleSummaryDataPoints(
.collect(toList());
}

private static List<ValueAtPercentile> getValues(DoubleSummaryDataPoint point) {
private static List<ValueAtPercentile> getValues(SummaryDataPoint point) {
return point.getQuantileValuesList().stream()
.map(v -> ValueAtPercentile.create(v.getQuantile(), v.getValue()))
.collect(Collectors.toList());
Expand Down

0 comments on commit 5b985ea

Please sign in to comment.