Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Marshalers for profiling signal type #6565

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
generator.writeString(Long.toString(value));
}

@Override
public void writeUInt64(ProtoFieldInfo field, long value) throws IOException {
generator.writeStringField(field.getJsonName(), Long.toString(value));
}

Check warning on line 87 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/JsonSerializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/JsonSerializer.java#L86-L87

Added lines #L86 - L87 were not covered by tests

@Override
protected void writeFixed32(ProtoFieldInfo field, int value) throws IOException {
generator.writeNumberField(field.getJsonName(), value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@
return field.getTagSize() + CodedOutputStream.computeUInt32SizeNoTag(payloadSize) + payloadSize;
}

/**
* Returns the size of a repeated uint64 field.
*
* <p>Packed repeated fields contain the tag, an integer representing the incoming payload size,
* and an actual payload of repeated varints.
*/
public static int sizeRepeatedUInt64(ProtoFieldInfo field, List<Long> values) {
if (values.isEmpty()) {
return 0;

Check warning on line 140 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L140

Added line #L140 was not covered by tests
}

int payloadSize = 0;

Check warning on line 143 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L143

Added line #L143 was not covered by tests
for (long v : values) {
payloadSize += CodedOutputStream.computeUInt64SizeNoTag(v);
}

Check warning on line 146 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L145-L146

Added lines #L145 - L146 were not covered by tests

// tag size + payload indicator size + actual payload size
return field.getTagSize() + CodedOutputStream.computeUInt32SizeNoTag(payloadSize) + payloadSize;

Check warning on line 149 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L149

Added line #L149 was not covered by tests
}

/**
* Returns the size of a repeated uint64 field.
*
Expand All @@ -154,6 +174,46 @@
return field.getTagSize() + CodedOutputStream.computeUInt32SizeNoTag(payloadSize) + payloadSize;
}

/**
* Returns the size of a repeated int64 field.
*
* <p>Packed repeated fields contain the tag, an integer representing the incoming payload size,
* and an actual payload of repeated varints.
*/
public static int sizeRepeatedInt64(ProtoFieldInfo field, long[] values) {
if (values.length == 0) {
return 0;

Check warning on line 185 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L185

Added line #L185 was not covered by tests
}

int payloadSize = 0;

Check warning on line 188 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L188

Added line #L188 was not covered by tests
for (long v : values) {
payloadSize += CodedOutputStream.computeInt64SizeNoTag(v);

Check warning on line 190 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L190

Added line #L190 was not covered by tests
}

// tag size + payload indicator size + actual payload size
return field.getTagSize() + CodedOutputStream.computeUInt32SizeNoTag(payloadSize) + payloadSize;

Check warning on line 194 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L194

Added line #L194 was not covered by tests
}

/**
* Returns the size of a repeated int64 field.
*
* <p>Packed repeated fields contain the tag, an integer representing the incoming payload size,
* and an actual payload of repeated varints.
*/
public static int sizeRepeatedInt64(ProtoFieldInfo field, List<Long> values) {
if (values.isEmpty()) {
return 0;

Check warning on line 205 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L205

Added line #L205 was not covered by tests
}

int payloadSize = 0;

Check warning on line 208 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L208

Added line #L208 was not covered by tests
for (long v : values) {
payloadSize += CodedOutputStream.computeInt64SizeNoTag(v);
}

Check warning on line 211 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L210-L211

Added lines #L210 - L211 were not covered by tests

// tag size + payload indicator size + actual payload size
return field.getTagSize() + CodedOutputStream.computeUInt32SizeNoTag(payloadSize) + payloadSize;

Check warning on line 214 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L214

Added line #L214 was not covered by tests
}

/** Returns the size of a repeated double field. */
public static int sizeRepeatedDouble(ProtoFieldInfo field, List<Double> values) {
// Same as fixed64.
Expand Down Expand Up @@ -207,6 +267,14 @@
return field.getTagSize() + CodedOutputStream.computeInt64SizeNoTag(message);
}

/** Returns the size of a uint64 field. */
public static int sizeUInt64(ProtoFieldInfo field, long message) {
if (message == 0) {
return 0;

Check warning on line 273 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L273

Added line #L273 was not covered by tests
}
return field.getTagSize() + CodedOutputStream.computeUInt64SizeNoTag(message);

Check warning on line 275 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/MarshalerUtil.java#L275

Added line #L275 was not covered by tests
}

/** Returns the size of a uint32 field. */
public static int sizeUInt32(ProtoFieldInfo field, int message) {
if (message == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
output.writeInt64NoTag(value);
}

@Override
public void writeUInt64(ProtoFieldInfo field, long value) throws IOException {
output.writeUInt32NoTag(field.getTag());
output.writeUInt64NoTag(value);
}

Check warning on line 115 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/ProtoSerializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/ProtoSerializer.java#L113-L115

Added lines #L113 - L115 were not covered by tests

@Override
protected void writeFixed64(ProtoFieldInfo field, long value) throws IOException {
output.writeUInt32NoTag(field.getTag());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,20 @@
writeInt64(field, value);
}

/** Serializes a protobuf {@code uint64} field. */
public void serializeUInt64(ProtoFieldInfo field, long value) throws IOException {
if (value == 0) {
return;

Check warning on line 145 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L145

Added line #L145 was not covered by tests
}
writeUInt64(field, value);
}

Check warning on line 148 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L147-L148

Added lines #L147 - L148 were not covered by tests

/** Writes a protobuf {@code int64} field, even if it matches the default value. */
public abstract void writeInt64(ProtoFieldInfo field, long value) throws IOException;

/** Writes a protobuf {@code uint64} field, even if it matches the default value. */
public abstract void writeUInt64(ProtoFieldInfo field, long value) throws IOException;

/** Serializes a protobuf {@code fixed64} field. */
public void serializeFixed64(ProtoFieldInfo field, long value) throws IOException {
if (value == 0) {
Expand Down Expand Up @@ -340,6 +351,24 @@
writeEndRepeatedVarint();
}

/** Serializes a {@code repeated uint64} field. */
public void serializeRepeatedUInt64(ProtoFieldInfo field, List<Long> values) throws IOException {
if (values.isEmpty()) {
return;

Check warning on line 357 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L357

Added line #L357 was not covered by tests
}

int payloadSize = 0;

Check warning on line 360 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L360

Added line #L360 was not covered by tests
for (long v : values) {
payloadSize += CodedOutputStream.computeUInt64SizeNoTag(v);
}

Check warning on line 363 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L362-L363

Added lines #L362 - L363 were not covered by tests

writeStartRepeatedVarint(field, payloadSize);

Check warning on line 365 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L365

Added line #L365 was not covered by tests
for (long value : values) {
writeUInt64Value(value);
}
writeEndRepeatedVarint();
}

Check warning on line 370 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L367-L370

Added lines #L367 - L370 were not covered by tests

/**
* Serializes a {@code repeated uint64} field.
*
Expand All @@ -366,6 +395,24 @@
writeEndRepeatedVarint();
}

/** Serializes a {@code repeated int64} field. */
public void serializeRepeatedInt64(ProtoFieldInfo field, List<Long> values) throws IOException {
if (values.isEmpty()) {
return;

Check warning on line 401 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L401

Added line #L401 was not covered by tests
}

int payloadSize = 0;

Check warning on line 404 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L404

Added line #L404 was not covered by tests
for (long v : values) {
payloadSize += CodedOutputStream.computeInt64SizeNoTag(v);
}

Check warning on line 407 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L406-L407

Added lines #L406 - L407 were not covered by tests

writeStartRepeatedVarint(field, payloadSize);

Check warning on line 409 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L409

Added line #L409 was not covered by tests
for (long value : values) {
writeUInt64Value(value);
}
writeEndRepeatedVarint();
}

Check warning on line 414 in exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java

View check run for this annotation

Codecov / codecov/patch

exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/Serializer.java#L411-L414

Added lines #L411 - L414 were not covered by tests

/** Serializes a {@code repeated double} field. */
public void serializeRepeatedDouble(ProtoFieldInfo field, List<Double> values)
throws IOException {
Expand Down
1 change: 1 addition & 0 deletions exporters/otlp/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ wire {
"opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest",
"opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest",
"opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest",
"opentelemetry.proto.collector.profiles.v1experimental.ExportProfilesServiceRequest"
)

custom {
Expand Down
7 changes: 7 additions & 0 deletions exporters/otlp/profiles/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ plugins {
description = "OpenTelemetry - Profiles Exporter"
otelJava.moduleName.set("io.opentelemetry.exporter.otlp.profiles")

val versions: Map<String, String> by project
dependencies {
api(project(":sdk:common"))
api(project(":exporters:common"))
implementation(project(":exporters:otlp:common"))

annotationProcessor("com.google.auto.value:auto-value")

testImplementation("com.fasterxml.jackson.core:jackson-databind")
testImplementation("com.google.protobuf:protobuf-java-util")
testImplementation("io.opentelemetry.proto:opentelemetry-proto")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.otlp.profiles;

import io.opentelemetry.exporter.internal.marshal.MarshalerUtil;
import io.opentelemetry.exporter.internal.marshal.MarshalerWithSize;
import io.opentelemetry.exporter.internal.marshal.Serializer;
import io.opentelemetry.proto.profiles.v1experimental.internal.AttributeUnit;
import java.io.IOException;
import java.util.List;
import java.util.function.Consumer;

final class AttributeUnitMarshaler extends MarshalerWithSize {

private static final AttributeUnitMarshaler[] EMPTY_REPEATED = new AttributeUnitMarshaler[0];

private final long attributeKey;
private final long unitIndex;

static AttributeUnitMarshaler create(AttributeUnitData attributeUnitData) {
return new AttributeUnitMarshaler(
attributeUnitData.getAttributeKey(), attributeUnitData.getUnitIndex());
}

static AttributeUnitMarshaler[] createRepeated(List<AttributeUnitData> items) {
if (items.isEmpty()) {
return EMPTY_REPEATED;
}

AttributeUnitMarshaler[] attributeUnitMarshalers = new AttributeUnitMarshaler[items.size()];
items.forEach(
item ->
new Consumer<AttributeUnitData>() {
int index = 0;

@Override
public void accept(AttributeUnitData attributeUnitData) {
attributeUnitMarshalers[index++] = AttributeUnitMarshaler.create(attributeUnitData);
}
});
return attributeUnitMarshalers;
}

private AttributeUnitMarshaler(long attributeKey, long unitIndex) {
super(calculateSize(attributeKey, unitIndex));
this.attributeKey = attributeKey;
this.unitIndex = unitIndex;
}

@Override
protected void writeTo(Serializer output) throws IOException {
output.serializeInt64(AttributeUnit.ATTRIBUTE_KEY, attributeKey);
output.serializeInt64(AttributeUnit.UNIT, unitIndex);
}

private static int calculateSize(long attributeKey, long unitIndex) {
int size;
size = 0;
size += MarshalerUtil.sizeInt64(AttributeUnit.ATTRIBUTE_KEY, attributeKey);
size += MarshalerUtil.sizeInt64(AttributeUnit.UNIT, unitIndex);
return size;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.otlp.profiles;

import io.opentelemetry.exporter.internal.marshal.MarshalerUtil;
import io.opentelemetry.exporter.internal.marshal.MarshalerWithSize;
import io.opentelemetry.exporter.internal.marshal.Serializer;
import io.opentelemetry.proto.profiles.v1experimental.internal.Function;
import java.io.IOException;
import java.util.List;
import java.util.function.Consumer;

final class FunctionMarshaler extends MarshalerWithSize {

private static final FunctionMarshaler[] EMPTY_REPEATED = new FunctionMarshaler[0];

private final long nameIndex;
private final long systemNameIndex;
private final long filenameIndex;
private final long startLine;

static FunctionMarshaler create(FunctionData functionData) {
return new FunctionMarshaler(
functionData.getNameIndex(),
functionData.getSystemNameIndex(),
functionData.getFilenameIndex(),
functionData.getStartLine());
}

static FunctionMarshaler[] createRepeated(List<FunctionData> items) {
if (items.isEmpty()) {
return EMPTY_REPEATED;
}

FunctionMarshaler[] functionMarshalers = new FunctionMarshaler[items.size()];
items.forEach(
item ->
new Consumer<FunctionData>() {
int index = 0;

@Override
public void accept(FunctionData functionData) {
functionMarshalers[index++] = FunctionMarshaler.create(functionData);
}
});
return functionMarshalers;
}

private FunctionMarshaler(
long nameIndex, long systemNameIndex, long filenameIndex, long startLine) {
super(calculateSize(nameIndex, systemNameIndex, filenameIndex, startLine));
this.nameIndex = nameIndex;
this.systemNameIndex = systemNameIndex;
this.filenameIndex = filenameIndex;
this.startLine = startLine;
}

@Override
protected void writeTo(Serializer output) throws IOException {
output.serializeInt64(Function.NAME, nameIndex);
output.serializeInt64(Function.SYSTEM_NAME, systemNameIndex);
output.serializeInt64(Function.FILENAME, filenameIndex);
output.serializeInt64(Function.START_LINE, startLine);
}

private static int calculateSize(
long nameIndex, long systemNameIndex, long filenameIndex, long startLine) {
int size = 0;
size += MarshalerUtil.sizeInt64(Function.NAME, nameIndex);
size += MarshalerUtil.sizeInt64(Function.SYSTEM_NAME, systemNameIndex);
size += MarshalerUtil.sizeInt64(Function.FILENAME, filenameIndex);
size += MarshalerUtil.sizeInt64(Function.START_LINE, startLine);
return size;
}
}
Loading
Loading