From 8b4c3a60175356d552035b0ae3c77b95b9564841 Mon Sep 17 00:00:00 2001 From: Jonathan Halliday Date: Wed, 8 Jan 2025 15:02:59 +0000 Subject: [PATCH] Update profiling exporters for proto 1.5 --- dependencyManagement/build.gradle.kts | 2 +- .../internal/data/ImmutableProfileData.java | 8 +++---- .../exporter/otlp/profiles/ProfileData.java | 6 ++--- .../otlp/profiles/ProfileMarshaler.java | 24 +++++++++---------- .../otlp/profiles/SampleMarshaler.java | 19 ++++++--------- .../ProfilesRequestMarshalerTest.java | 2 +- 6 files changed, 28 insertions(+), 33 deletions(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 36073d361f9..1128e6bb539 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -72,7 +72,7 @@ val DEPENDENCIES = listOf( "io.jaegertracing:jaeger-client:1.8.1", "io.opentelemetry.contrib:opentelemetry-aws-xray-propagator:1.39.0-alpha", "io.opentelemetry.semconv:opentelemetry-semconv-incubating:1.29.0-alpha", - "io.opentelemetry.proto:opentelemetry-proto:1.4.0-alpha", + "io.opentelemetry.proto:opentelemetry-proto:1.5.0-alpha", "io.opentracing:opentracing-api:0.33.0", "io.opentracing:opentracing-noop:0.33.0", "junit:junit:4.13.2", diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/internal/data/ImmutableProfileData.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/internal/data/ImmutableProfileData.java index b44b7f67834..c9b4a642ad3 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/internal/data/ImmutableProfileData.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/internal/data/ImmutableProfileData.java @@ -56,10 +56,10 @@ public static ProfileData create( long durationNanos, ValueTypeData periodType, long period, - List commentStrindices, + List commentStrIndices, int defaultSampleTypeStringIndex, String profileId, - Attributes attributes, + List attributeIndices, int droppedAttributesCount, String originalPayloadFormat, ByteBuffer originalPayload) { @@ -80,10 +80,10 @@ public static ProfileData create( durationNanos, periodType, period, - commentStrindices, + commentStrIndices, defaultSampleTypeStringIndex, profileId, - attributes, + attributeIndices, droppedAttributesCount, originalPayloadFormat, originalPayload); diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ProfileData.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ProfileData.java index d6dd8709ed0..d37e901206b 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ProfileData.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ProfileData.java @@ -99,13 +99,13 @@ default byte[] getProfileIdBytes() { } /** - * Returns profile-wide attributes. Attribute keys MUST be unique (it is not allowed to have more - * than one attribute with the same key). + * Returns indexes of profile-wide attributes, referencing to Profile.attribute_table. Attribute + * keys MUST be unique (it is not allowed to have more than one attribute with the same key). * * @see * "https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute" */ - Attributes getAttributes(); + List getAttributeIndices(); /** * Returns the total number of attributes that were recorded on this profile. diff --git a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ProfileMarshaler.java b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ProfileMarshaler.java index 04ea86c3263..be4215c8b9f 100644 --- a/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ProfileMarshaler.java +++ b/exporters/otlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/ProfileMarshaler.java @@ -34,7 +34,7 @@ final class ProfileMarshaler extends MarshalerWithSize { private final List comment; private final int defaultSampleType; private final byte[] profileId; - private final KeyValueMarshaler[] attributeMarshalers; + private final List attributeIndices; private final int droppedAttributesCount; private final byte[] originalPayloadFormatUtf8; private final ByteBuffer originalPayload; @@ -50,8 +50,8 @@ static ProfileMarshaler create(ProfileData profileData) { LocationMarshaler.createRepeated(profileData.getLocationTable()); FunctionMarshaler[] functionMarshalers = FunctionMarshaler.createRepeated(profileData.getFunctionTable()); - KeyValueMarshaler[] attributeMarshalers = - KeyValueMarshaler.createForAttributes(profileData.getAttributes()); + KeyValueMarshaler[] attributeTableMarshalers = + KeyValueMarshaler.createForAttributes(profileData.getAttributeTable()); AttributeUnitMarshaler[] attributeUnitsMarshalers = AttributeUnitMarshaler.createRepeated(profileData.getAttributeUnits()); LinkMarshaler[] linkMarshalers = LinkMarshaler.createRepeated(profileData.getLinkTable()); @@ -63,7 +63,7 @@ static ProfileMarshaler create(ProfileData profileData) { } int droppedAttributesCount = - profileData.getTotalAttributeCount() - profileData.getAttributes().size(); + profileData.getTotalAttributeCount() - profileData.getAttributeIndices().size(); return new ProfileMarshaler( sampleTypeMarshalers, @@ -72,7 +72,7 @@ static ProfileMarshaler create(ProfileData profileData) { locationMarshalers, profileData.getLocationIndices(), functionMarshalers, - attributeMarshalers, + attributeTableMarshalers, attributeUnitsMarshalers, linkMarshalers, convertedStrings, @@ -83,7 +83,7 @@ static ProfileMarshaler create(ProfileData profileData) { profileData.getCommentStrIndices(), profileData.getDefaultSampleTypeStringIndex(), profileData.getProfileIdBytes(), - KeyValueMarshaler.createForAttributes(profileData.getAttributes()), + profileData.getAttributeIndices(), droppedAttributesCount, MarshalerUtil.toBytes(profileData.getOriginalPayloadFormat()), profileData.getOriginalPayload()); @@ -107,7 +107,7 @@ private ProfileMarshaler( List comment, int defaultSampleType, byte[] profileId, - KeyValueMarshaler[] attributeMarshalers, + List attributeIndices, int droppedAttributesCount, byte[] originalPayloadFormat, ByteBuffer originalPayload) { @@ -130,7 +130,7 @@ private ProfileMarshaler( comment, defaultSampleType, profileId, - attributeMarshalers, + attributeIndices, droppedAttributesCount, originalPayloadFormat, originalPayload)); @@ -151,7 +151,7 @@ private ProfileMarshaler( this.comment = comment; this.defaultSampleType = defaultSampleType; this.profileId = profileId; - this.attributeMarshalers = attributeMarshalers; + this.attributeIndices = attributeIndices; this.droppedAttributesCount = droppedAttributesCount; this.originalPayloadFormatUtf8 = originalPayloadFormat; this.originalPayload = originalPayload; @@ -177,7 +177,7 @@ protected void writeTo(Serializer output) throws IOException { output.serializeInt32(Profile.DEFAULT_SAMPLE_TYPE_STRINDEX, defaultSampleType); output.serializeBytes(Profile.PROFILE_ID, profileId); - output.serializeRepeatedMessage(Profile.ATTRIBUTES, attributeMarshalers); + output.serializeRepeatedInt32(Profile.ATTRIBUTE_INDICES, attributeIndices); output.serializeUInt32(Profile.DROPPED_ATTRIBUTES_COUNT, droppedAttributesCount); output.serializeString(Profile.ORIGINAL_PAYLOAD_FORMAT, originalPayloadFormatUtf8); output.serializeByteBuffer(Profile.ORIGINAL_PAYLOAD, originalPayload); @@ -201,7 +201,7 @@ private static int calculateSize( List comment, int defaultSampleType, byte[] profileId, - KeyValueMarshaler[] attributeMarshalers, + List attributeIndices, int droppedAttributesCount, byte[] originalPayloadFormat, ByteBuffer originalPayload) { @@ -225,7 +225,7 @@ private static int calculateSize( size += MarshalerUtil.sizeInt64(Profile.DEFAULT_SAMPLE_TYPE_STRINDEX, defaultSampleType); size += MarshalerUtil.sizeBytes(Profile.PROFILE_ID, profileId); - size += MarshalerUtil.sizeRepeatedMessage(Profile.ATTRIBUTES, attributeMarshalers); + size += MarshalerUtil.sizeRepeatedInt32(Profile.ATTRIBUTE_INDICES, attributeIndices); size += MarshalerUtil.sizeInt32(Profile.DROPPED_ATTRIBUTES_COUNT, droppedAttributesCount); size += MarshalerUtil.sizeBytes(Profile.ORIGINAL_PAYLOAD_FORMAT, originalPayloadFormat); size += MarshalerUtil.sizeByteBuffer(Profile.ORIGINAL_PAYLOAD, originalPayload); 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 d6bb2c31c94..5a1517ccf06 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 @@ -21,7 +21,7 @@ final class SampleMarshaler extends MarshalerWithSize { private final int locationsStartIndex; private final int locationsLength; private final List values; - private final List attributesIndices; + private final List attributeIndices; @Nullable private final Integer linkIndex; private final List timestamps; @@ -59,21 +59,16 @@ private SampleMarshaler( int locationsStartIndex, int locationsLength, List values, - List attributesIndices, + List attributeIndices, @Nullable Integer linkIndex, List timestamps) { super( calculateSize( - locationsStartIndex, - locationsLength, - values, - attributesIndices, - linkIndex, - timestamps)); + locationsStartIndex, locationsLength, values, attributeIndices, linkIndex, timestamps)); this.locationsStartIndex = locationsStartIndex; this.locationsLength = locationsLength; this.values = values; - this.attributesIndices = attributesIndices; + this.attributeIndices = attributeIndices; this.linkIndex = linkIndex; this.timestamps = timestamps; } @@ -83,7 +78,7 @@ protected void writeTo(Serializer output) throws IOException { output.serializeInt32(Sample.LOCATIONS_START_INDEX, locationsStartIndex); output.serializeInt32(Sample.LOCATIONS_LENGTH, locationsLength); output.serializeRepeatedInt64(Sample.VALUE, values); - output.serializeRepeatedInt32(Sample.ATTRIBUTE_INDICES, attributesIndices); + output.serializeRepeatedInt32(Sample.ATTRIBUTE_INDICES, attributeIndices); output.serializeInt32Optional(Sample.LINK_INDEX, linkIndex); output.serializeRepeatedUInt64(Sample.TIMESTAMPS_UNIX_NANO, timestamps); } @@ -92,7 +87,7 @@ private static int calculateSize( int locationsStartIndex, int locationsLength, List values, - List attributesIndices, + List attributeIndices, @Nullable Integer linkIndex, List timestamps) { int size; @@ -100,7 +95,7 @@ private static int calculateSize( size += MarshalerUtil.sizeInt32(Sample.LOCATIONS_START_INDEX, locationsStartIndex); size += MarshalerUtil.sizeInt32(Sample.LOCATIONS_LENGTH, locationsLength); size += MarshalerUtil.sizeRepeatedInt64(Sample.VALUE, values); - size += MarshalerUtil.sizeRepeatedInt32(Sample.ATTRIBUTE_INDICES, attributesIndices); + size += MarshalerUtil.sizeRepeatedInt32(Sample.ATTRIBUTE_INDICES, attributeIndices); size += MarshalerUtil.sizeInt32Optional(Sample.LINK_INDEX, linkIndex); size += MarshalerUtil.sizeRepeatedUInt64(Sample.TIMESTAMPS_UNIX_NANO, timestamps); return size; 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 1046caeb557..c7c2deec381 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 @@ -162,7 +162,7 @@ void compareResourceProfilesMarshaling() { listOf(8, 9), 0, profileId, - Attributes.empty(), + Collections.emptyList(), 3, "format", ByteBuffer.wrap(new byte[] {4, 5}));