Skip to content

Commit

Permalink
Update profiling exporters for proto 1.5 (#6999)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhalliday authored Jan 10, 2025
1 parent 330881a commit 43b38e2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public static ProfileData create(
long durationNanos,
ValueTypeData periodType,
long period,
List<Integer> commentStrindices,
List<Integer> commentStrIndices,
int defaultSampleTypeStringIndex,
String profileId,
Attributes attributes,
List<Integer> attributeIndices,
int droppedAttributesCount,
String originalPayloadFormat,
ByteBuffer originalPayload) {
Expand All @@ -80,10 +80,10 @@ public static ProfileData create(
durationNanos,
periodType,
period,
commentStrindices,
commentStrIndices,
defaultSampleTypeStringIndex,
profileId,
attributes,
attributeIndices,
droppedAttributesCount,
originalPayloadFormat,
originalPayload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> getAttributeIndices();

/**
* Returns the total number of attributes that were recorded on this profile.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class ProfileMarshaler extends MarshalerWithSize {
private final List<Integer> comment;
private final int defaultSampleType;
private final byte[] profileId;
private final KeyValueMarshaler[] attributeMarshalers;
private final List<Integer> attributeIndices;
private final int droppedAttributesCount;
private final byte[] originalPayloadFormatUtf8;
private final ByteBuffer originalPayload;
Expand All @@ -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());
Expand All @@ -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,
Expand All @@ -72,7 +72,7 @@ static ProfileMarshaler create(ProfileData profileData) {
locationMarshalers,
profileData.getLocationIndices(),
functionMarshalers,
attributeMarshalers,
attributeTableMarshalers,
attributeUnitsMarshalers,
linkMarshalers,
convertedStrings,
Expand All @@ -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());
Expand All @@ -107,7 +107,7 @@ private ProfileMarshaler(
List<Integer> comment,
int defaultSampleType,
byte[] profileId,
KeyValueMarshaler[] attributeMarshalers,
List<Integer> attributeIndices,
int droppedAttributesCount,
byte[] originalPayloadFormat,
ByteBuffer originalPayload) {
Expand All @@ -130,7 +130,7 @@ private ProfileMarshaler(
comment,
defaultSampleType,
profileId,
attributeMarshalers,
attributeIndices,
droppedAttributesCount,
originalPayloadFormat,
originalPayload));
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -201,7 +201,7 @@ private static int calculateSize(
List<Integer> comment,
int defaultSampleType,
byte[] profileId,
KeyValueMarshaler[] attributeMarshalers,
List<Integer> attributeIndices,
int droppedAttributesCount,
byte[] originalPayloadFormat,
ByteBuffer originalPayload) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class SampleMarshaler extends MarshalerWithSize {
private final int locationsStartIndex;
private final int locationsLength;
private final List<Long> values;
private final List<Integer> attributesIndices;
private final List<Integer> attributeIndices;
@Nullable private final Integer linkIndex;
private final List<Long> timestamps;

Expand Down Expand Up @@ -59,21 +59,16 @@ private SampleMarshaler(
int locationsStartIndex,
int locationsLength,
List<Long> values,
List<Integer> attributesIndices,
List<Integer> attributeIndices,
@Nullable Integer linkIndex,
List<Long> 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;
}
Expand All @@ -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);
}
Expand All @@ -92,15 +87,15 @@ private static int calculateSize(
int locationsStartIndex,
int locationsLength,
List<Long> values,
List<Integer> attributesIndices,
List<Integer> attributeIndices,
@Nullable Integer linkIndex,
List<Long> timestamps) {
int size;
size = 0;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void compareResourceProfilesMarshaling() {
listOf(8, 9),
0,
profileId,
Attributes.empty(),
Collections.emptyList(),
3,
"format",
ByteBuffer.wrap(new byte[] {4, 5}));
Expand Down

0 comments on commit 43b38e2

Please sign in to comment.