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

Reduce allocation cost reporting spans #35183

Merged
merged 1 commit into from
Aug 4, 2023
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 @@ -20,6 +20,7 @@
import io.opentelemetry.sdk.internal.ThrottlingLogger;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.quarkus.vertx.core.runtime.BufferOutputStream;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
Expand Down Expand Up @@ -194,10 +195,9 @@ public void handle(GrpcClientRequest<Buffer, Buffer> request) {

try {
int messageSize = marshaler.getBinarySerializedSize();
var baos = new NonCopyingByteArrayOutputStream(messageSize); // TODO: we can probably use Vert.x / Netty buffering here
marshaler.writeBinaryTo(baos);
Buffer buffer = Buffer.buffer(messageSize);
buffer.appendBytes(baos.toByteArray());
var os = new BufferOutputStream(buffer);
marshaler.writeBinaryTo(os);
request.send(buffer).onSuccess(new Handler<>() {
@Override
public void handle(GrpcClientResponse<Buffer, Buffer> response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static io.quarkus.opentelemetry.runtime.exporter.otlp.OtlpExporterUtil.getPort;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
Expand All @@ -18,6 +17,7 @@
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.quarkus.vertx.core.runtime.BufferOutputStream;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
Expand Down Expand Up @@ -129,17 +129,16 @@ public byte[] responseBody() {
})
.putHeader("Content-Type", contentType);

ByteArrayOutputStream os; // TODO: we can probably use Vert.x / Netty buffering here
Buffer buffer = Buffer.buffer(contentLength);
OutputStream os = new BufferOutputStream(buffer);
if (compressionEnabled) {
os = new ByteArrayOutputStream(contentLength);
clientRequest.putHeader("Content-Encoding", "gzip");
try (var gzos = new GZIPOutputStream(os)) {
marshaler.accept(gzos);
} catch (IOException e) {
throw new IllegalStateException(e);
}
} else {
os = new NonCopyingByteArrayOutputStream(contentLength);
marshaler.accept(os);
}

Expand All @@ -149,7 +148,7 @@ public byte[] responseBody() {
}
}

clientRequest.send(Buffer.buffer(os.toByteArray()));
clientRequest.send(buffer);

}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.quarkus.smallrye.health.runtime;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;

import io.quarkus.arc.Arc;
import io.quarkus.arc.ManagedContext;
import io.quarkus.security.identity.CurrentIdentityAssociation;
import io.quarkus.vertx.core.runtime.BufferOutputStream;
import io.quarkus.vertx.http.runtime.security.QuarkusHttpUser;
import io.smallrye.health.SmallRyeHealth;
import io.smallrye.health.SmallRyeHealthReporter;
Expand Down Expand Up @@ -56,22 +56,4 @@ private void doHandle(RoutingContext ctx) {
}
}

private static class BufferOutputStream extends OutputStream {

private final Buffer buffer;

private BufferOutputStream(Buffer buffer) {
this.buffer = buffer;
}

@Override
public void write(byte[] b, int off, int len) throws IOException {
buffer.appendBytes(b, off, len);
}

@Override
public void write(int b) throws IOException {
buffer.appendInt(b);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.vertx.core.runtime;

import java.io.IOException;
import java.io.OutputStream;

import io.vertx.core.buffer.Buffer;

/**
* Simple {@link OutputStream} implementation that appends content
* written in given {@link Buffer} instance.
*/
public class BufferOutputStream extends OutputStream {

private final Buffer buffer;

public BufferOutputStream(Buffer buffer) {
this.buffer = buffer;
}

@Override
public void write(byte[] b, int off, int len) throws IOException {
buffer.appendBytes(b, off, len);
}

@Override
public void write(int b) throws IOException {
buffer.appendInt(b);
}
}