diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/AttributeUnitMarshaler.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/AttributeUnitMarshaler.java index 311a0d1c33d..6e466a79dd3 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/AttributeUnitMarshaler.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/AttributeUnitMarshaler.java @@ -33,15 +33,14 @@ static AttributeUnitMarshaler[] createRepeated(List items) { AttributeUnitMarshaler[] attributeUnitMarshalers = new AttributeUnitMarshaler[items.size()]; items.forEach( - item -> - new Consumer() { - int index = 0; + new Consumer() { + int index = 0; - @Override - public void accept(AttributeUnitData attributeUnitData) { - attributeUnitMarshalers[index++] = AttributeUnitMarshaler.create(attributeUnitData); - } - }); + @Override + public void accept(AttributeUnitData attributeUnitData) { + attributeUnitMarshalers[index++] = AttributeUnitMarshaler.create(attributeUnitData); + } + }); return attributeUnitMarshalers; } diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/FunctionMarshaler.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/FunctionMarshaler.java index aea4071d380..d5b391702ce 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/FunctionMarshaler.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/FunctionMarshaler.java @@ -37,15 +37,14 @@ static FunctionMarshaler[] createRepeated(List items) { FunctionMarshaler[] functionMarshalers = new FunctionMarshaler[items.size()]; items.forEach( - item -> - new Consumer() { - int index = 0; + new Consumer() { + int index = 0; - @Override - public void accept(FunctionData functionData) { - functionMarshalers[index++] = FunctionMarshaler.create(functionData); - } - }); + @Override + public void accept(FunctionData functionData) { + functionMarshalers[index++] = FunctionMarshaler.create(functionData); + } + }); return functionMarshalers; } diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LineMarshaler.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LineMarshaler.java index 2d3bf83a6c2..ec7a780b9d7 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LineMarshaler.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LineMarshaler.java @@ -32,15 +32,14 @@ static LineMarshaler[] createRepeated(List items) { LineMarshaler[] lineMarshalers = new LineMarshaler[items.size()]; items.forEach( - item -> - new Consumer() { - int index = 0; + new Consumer() { + int index = 0; - @Override - public void accept(LineData lineData) { - lineMarshalers[index++] = LineMarshaler.create(lineData); - } - }); + @Override + public void accept(LineData lineData) { + lineMarshalers[index++] = LineMarshaler.create(lineData); + } + }); return lineMarshalers; } diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LinkMarshaler.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LinkMarshaler.java index ae41176a820..eb5673c8cae 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LinkMarshaler.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LinkMarshaler.java @@ -39,15 +39,14 @@ static LinkMarshaler[] createRepeated(List items) { LinkMarshaler[] linkMarshalers = new LinkMarshaler[items.size()]; items.forEach( - item -> - new Consumer() { - int index = 0; + new Consumer() { + int index = 0; - @Override - public void accept(LinkData linkData) { - linkMarshalers[index++] = LinkMarshaler.create(linkData); - } - }); + @Override + public void accept(LinkData linkData) { + linkMarshalers[index++] = LinkMarshaler.create(linkData); + } + }); return linkMarshalers; } diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LocationMarshaler.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LocationMarshaler.java index 40360c0eafc..afe95205f17 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LocationMarshaler.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/LocationMarshaler.java @@ -40,15 +40,14 @@ static LocationMarshaler[] createRepeated(List items) { LocationMarshaler[] locationMarshalers = new LocationMarshaler[items.size()]; items.forEach( - item -> - new Consumer() { - int index = 0; + new Consumer() { + int index = 0; - @Override - public void accept(LocationData locationData) { - locationMarshalers[index++] = LocationMarshaler.create(locationData); - } - }); + @Override + public void accept(LocationData locationData) { + locationMarshalers[index++] = LocationMarshaler.create(locationData); + } + }); return locationMarshalers; } diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/MappingMarshaler.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/MappingMarshaler.java index 6e39551540f..5d9f751e4dc 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/MappingMarshaler.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/MappingMarshaler.java @@ -47,15 +47,14 @@ static MappingMarshaler[] createRepeated(List items) { MappingMarshaler[] mappingMarshalers = new MappingMarshaler[items.size()]; items.forEach( - item -> - new Consumer() { - int index = 0; + new Consumer() { + int index = 0; - @Override - public void accept(MappingData mappingData) { - mappingMarshalers[index++] = MappingMarshaler.create(mappingData); - } - }); + @Override + public void accept(MappingData mappingData) { + mappingMarshalers[index++] = MappingMarshaler.create(mappingData); + } + }); return mappingMarshalers; } diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/SampleMarshaler.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/SampleMarshaler.java index 5a1517ccf06..c03fbce51dc 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/SampleMarshaler.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/SampleMarshaler.java @@ -43,15 +43,14 @@ static SampleMarshaler[] createRepeated(List items) { SampleMarshaler[] sampleMarshalers = new SampleMarshaler[items.size()]; items.forEach( - item -> - new Consumer() { - int index = 0; + new Consumer() { + int index = 0; - @Override - public void accept(SampleData sampleData) { - sampleMarshalers[index++] = SampleMarshaler.create(sampleData); - } - }); + @Override + public void accept(SampleData sampleData) { + sampleMarshalers[index++] = SampleMarshaler.create(sampleData); + } + }); return sampleMarshalers; } diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ValueTypeMarshaler.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ValueTypeMarshaler.java index a52621b119c..3822bb25a25 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ValueTypeMarshaler.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ValueTypeMarshaler.java @@ -49,15 +49,14 @@ static ValueTypeMarshaler[] createRepeated(List items) { ValueTypeMarshaler[] valueTypeMarshalers = new ValueTypeMarshaler[items.size()]; items.forEach( - item -> - new Consumer() { - int index = 0; + new Consumer() { + int index = 0; - @Override - public void accept(ValueTypeData valueTypeData) { - valueTypeMarshalers[index++] = ValueTypeMarshaler.create(valueTypeData); - } - }); + @Override + public void accept(ValueTypeData valueTypeData) { + valueTypeMarshalers[index++] = ValueTypeMarshaler.create(valueTypeData); + } + }); return valueTypeMarshalers; } diff --git a/exporters/otlp/profiles/src/test/java/io/opentelemetry/exporter/otlp/profiles/ProfilesRequestMarshalerTest.java b/exporters/otlp/profiles/src/test/java/io/opentelemetry/exporter/otlp/profiles/ProfilesRequestMarshalerTest.java index 33ddc1c0f47..fec2ff9f85e 100644 --- a/exporters/otlp/profiles/src/test/java/io/opentelemetry/exporter/otlp/profiles/ProfilesRequestMarshalerTest.java +++ b/exporters/otlp/profiles/src/test/java/io/opentelemetry/exporter/otlp/profiles/ProfilesRequestMarshalerTest.java @@ -60,6 +60,26 @@ void compareAttributeUnitMarshaling() { assertThat(roundTripResult).isEqualTo(builderResult); } + @Test + void compareRepeatedAttributeUnitMarshaling() { + List inputs = new ArrayList<>(); + inputs.add(ImmutableAttributeUnitData.create(1, 2)); + inputs.add(ImmutableAttributeUnitData.create(3, 4)); + + List builderResults = new ArrayList<>(); + builderResults.add( + AttributeUnit.newBuilder().setAttributeKeyStrindex(1).setUnitStrindex(2).build()); + builderResults.add( + AttributeUnit.newBuilder().setAttributeKeyStrindex(3).setUnitStrindex(4).build()); + + AttributeUnitMarshaler[] marshalers = AttributeUnitMarshaler.createRepeated(inputs); + + for (int i = 0; i < marshalers.length; i++) { + AttributeUnit roundTripResult = parse(AttributeUnit.getDefaultInstance(), marshalers[i]); + assertThat(roundTripResult).isEqualTo(builderResults.get(i)); + } + } + @Test void compareFunctionMarshaling() { FunctionData input = ImmutableFunctionData.create(1, 2, 3, 4); @@ -76,6 +96,36 @@ void compareFunctionMarshaling() { assertThat(roundTripResult).isEqualTo(builderResult); } + @Test + void compareRepeatedFunctionMarshaling() { + List inputs = new ArrayList<>(); + inputs.add(ImmutableFunctionData.create(1, 2, 3, 4)); + inputs.add(ImmutableFunctionData.create(5, 6, 7, 8)); + + List builderResults = new ArrayList<>(); + builderResults.add( + Function.newBuilder() + .setNameStrindex(1) + .setSystemNameStrindex(2) + .setFilenameStrindex(3) + .setStartLine(4) + .build()); + builderResults.add( + Function.newBuilder() + .setNameStrindex(5) + .setSystemNameStrindex(6) + .setFilenameStrindex(7) + .setStartLine(8) + .build()); + + FunctionMarshaler[] marshalers = FunctionMarshaler.createRepeated(inputs); + + for (int i = 0; i < marshalers.length; i++) { + Function roundTripResult = parse(Function.getDefaultInstance(), marshalers[i]); + assertThat(roundTripResult).isEqualTo(builderResults.get(i)); + } + } + @Test void compareLineMarshaling() { LineData input = ImmutableLineData.create(1, 2, 3); @@ -85,6 +135,24 @@ void compareLineMarshaling() { assertThat(roundTripResult).isEqualTo(builderResult); } + @Test + void compareRepeatedLineMarshaling() { + List inputs = new ArrayList<>(); + inputs.add(ImmutableLineData.create(1, 2, 3)); + inputs.add(ImmutableLineData.create(4, 5, 6)); + + List builderResults = new ArrayList<>(); + builderResults.add(Line.newBuilder().setFunctionIndex(1).setLine(2).setColumn(3).build()); + builderResults.add(Line.newBuilder().setFunctionIndex(4).setLine(5).setColumn(6).build()); + + LineMarshaler[] marshalers = LineMarshaler.createRepeated(inputs); + + for (int i = 0; i < marshalers.length; i++) { + Line roundTripResult = parse(Line.getDefaultInstance(), marshalers[i]); + assertThat(roundTripResult).isEqualTo(builderResults.get(i)); + } + } + @Test void compareLinkMarshaling() { String traceId = "0123456789abcdef0123456789abcdef"; @@ -100,6 +168,32 @@ void compareLinkMarshaling() { assertThat(roundTripResult).isEqualTo(builderResult); } + @Test + void compareRepeatedLinkMarshaling() { + List inputs = new ArrayList<>(); + inputs.add(ImmutableLinkData.create("0123456789abcdef0123456789abcdef", "fedcba9876543210")); + inputs.add(ImmutableLinkData.create("123456789abcdef0123456789abcdef0", "edcba9876543210f")); + + List builderResults = new ArrayList<>(); + builderResults.add( + Link.newBuilder() + .setTraceId(ByteString.fromHex("0123456789abcdef0123456789abcdef")) + .setSpanId(ByteString.fromHex("fedcba9876543210")) + .build()); + builderResults.add( + Link.newBuilder() + .setTraceId(ByteString.fromHex("123456789abcdef0123456789abcdef0")) + .setSpanId(ByteString.fromHex("edcba9876543210f")) + .build()); + + LinkMarshaler[] marshalers = LinkMarshaler.createRepeated(inputs); + + for (int i = 0; i < marshalers.length; i++) { + Link roundTripResult = parse(Link.getDefaultInstance(), marshalers[i]); + assertThat(roundTripResult).isEqualTo(builderResults.get(i)); + } + } + @Test void compareLocationMarshaling() { LocationData input = @@ -117,6 +211,36 @@ void compareLocationMarshaling() { assertThat(roundTripResult).isEqualTo(builderResult); } + @Test + void compareRepeatedLocationMarshaling() { + List inputs = new ArrayList<>(); + inputs.add(ImmutableLocationData.create(1, 2, Collections.emptyList(), true, listOf(3, 4))); + inputs.add(ImmutableLocationData.create(5, 6, Collections.emptyList(), true, listOf(7, 8))); + + List builderResults = new ArrayList<>(); + builderResults.add( + Location.newBuilder() + .setMappingIndex(1) + .setAddress(2) + .setIsFolded(true) + .addAllAttributeIndices(listOf(3, 4)) + .build()); + builderResults.add( + Location.newBuilder() + .setMappingIndex(5) + .setAddress(6) + .setIsFolded(true) + .addAllAttributeIndices(listOf(7, 8)) + .build()); + + LocationMarshaler[] marshalers = LocationMarshaler.createRepeated(inputs); + + for (int i = 0; i < marshalers.length; i++) { + Location roundTripResult = parse(Location.getDefaultInstance(), marshalers[i]); + assertThat(roundTripResult).isEqualTo(builderResults.get(i)); + } + } + @Test void compareMappingMarshaling() { MappingData input = @@ -138,6 +262,46 @@ void compareMappingMarshaling() { assertThat(roundTripResult).isEqualTo(builderResult); } + @Test + void compareRepeatedMappingMarshaling() { + List inputs = new ArrayList<>(); + inputs.add(ImmutableMappingData.create(1, 2, 3, 4, listOf(5, 6), true, true, true, true)); + inputs.add(ImmutableMappingData.create(7, 8, 9, 10, listOf(11, 12), true, true, true, true)); + + List builderResults = new ArrayList<>(); + builderResults.add( + Mapping.newBuilder() + .setMemoryStart(1) + .setMemoryLimit(2) + .setFileOffset(3) + .setFilenameStrindex(4) + .addAllAttributeIndices(listOf(5, 6)) + .setHasFunctions(true) + .setHasFilenames(true) + .setHasLineNumbers(true) + .setHasInlineFrames(true) + .build()); + builderResults.add( + Mapping.newBuilder() + .setMemoryStart(7) + .setMemoryLimit(8) + .setFileOffset(9) + .setFilenameStrindex(10) + .addAllAttributeIndices(listOf(11, 12)) + .setHasFunctions(true) + .setHasFilenames(true) + .setHasLineNumbers(true) + .setHasInlineFrames(true) + .build()); + + MappingMarshaler[] marshalers = MappingMarshaler.createRepeated(inputs); + + for (int i = 0; i < marshalers.length; i++) { + Mapping roundTripResult = parse(Mapping.getDefaultInstance(), marshalers[i]); + assertThat(roundTripResult).isEqualTo(builderResults.get(i)); + } + } + @Test void compareResourceProfilesMarshaling() { @@ -227,6 +391,41 @@ void compareSampleMarshaling() { assertThat(roundTripResult).isEqualTo(builderResult); } + @Test + void compareRepeatedSampleMarshaling() { + List inputs = new ArrayList<>(); + inputs.add(ImmutableSampleData.create(1, 2, listOf(3L, 4L), listOf(5, 6), 7, listOf(8L, 9L))); + inputs.add( + ImmutableSampleData.create(10, 11, listOf(12L, 13L), listOf(14, 15), 16, listOf(17L, 18L))); + + List builderResults = new ArrayList<>(); + builderResults.add( + Sample.newBuilder() + .setLocationsStartIndex(1) + .setLocationsLength(2) + .addAllValue(listOf(3L, 4L)) + .addAllAttributeIndices(listOf(5, 6)) + .setLinkIndex(7) + .addAllTimestampsUnixNano(listOf(8L, 9L)) + .build()); + builderResults.add( + Sample.newBuilder() + .setLocationsStartIndex(10) + .setLocationsLength(11) + .addAllValue(listOf(12L, 13L)) + .addAllAttributeIndices(listOf(14, 15)) + .setLinkIndex(16) + .addAllTimestampsUnixNano(listOf(17L, 18L)) + .build()); + + SampleMarshaler[] marshalers = SampleMarshaler.createRepeated(inputs); + + for (int i = 0; i < marshalers.length; i++) { + Sample roundTripResult = parse(Sample.getDefaultInstance(), marshalers[i]); + assertThat(roundTripResult).isEqualTo(builderResults.get(i)); + } + } + @Test void compareValueTypeMarshaling() { ValueTypeData input = ImmutableValueTypeData.create(1, 2, AggregationTemporality.CUMULATIVE); @@ -244,6 +443,38 @@ void compareValueTypeMarshaling() { assertThat(roundTripResult).isEqualTo(builderResult); } + @Test + void compareRepeatedValueTypeMarshaling() { + List inputs = new ArrayList<>(); + inputs.add(ImmutableValueTypeData.create(1, 2, AggregationTemporality.CUMULATIVE)); + inputs.add(ImmutableValueTypeData.create(3, 4, AggregationTemporality.CUMULATIVE)); + + List builderResults = new ArrayList<>(); + builderResults.add( + ValueType.newBuilder() + .setTypeStrindex(1) + .setUnitStrindex(2) + .setAggregationTemporality( + io.opentelemetry.proto.profiles.v1development.AggregationTemporality + .AGGREGATION_TEMPORALITY_CUMULATIVE) + .build()); + builderResults.add( + ValueType.newBuilder() + .setTypeStrindex(3) + .setUnitStrindex(4) + .setAggregationTemporality( + io.opentelemetry.proto.profiles.v1development.AggregationTemporality + .AGGREGATION_TEMPORALITY_CUMULATIVE) + .build()); + + ValueTypeMarshaler[] marshalers = ValueTypeMarshaler.createRepeated(inputs); + + for (int i = 0; i < marshalers.length; i++) { + ValueType roundTripResult = parse(ValueType.getDefaultInstance(), marshalers[i]); + assertThat(roundTripResult).isEqualTo(builderResults.get(i)); + } + } + private static List listOf(T a, T b) { ArrayList list = new ArrayList<>(); list.add(a);