Skip to content
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,10 @@ private void uploadSnapshot(final Snapshot snapshot) throws InterruptedException

config.httpHeaders.forEach((k, v) -> request.header(k, v));

if (config.format == Format.OTLP && config.compressionLevelJFR != Deflater.NO_COMPRESSION) {
request.header("Content-Encoding", "gzip");
}

addAuthHeader(request, url, config);


Expand Down Expand Up @@ -116,7 +120,11 @@ private void uploadSnapshot(final Snapshot snapshot) throws InterruptedException

private RequestBody requestBody(Snapshot snapshot) {
if (config.format == Format.OTLP) {
return RequestBody.create(snapshot.data, PROTOBUF);
RequestBody body = RequestBody.create(snapshot.data, PROTOBUF);
if (config.compressionLevelJFR != Deflater.NO_COMPRESSION) {
body = GzipSink.gzip(body, config.compressionLevelJFR);
}
return body;
}

byte[] labels = snapshot.labels.toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -110,14 +112,16 @@ void userLabelsOverrideRequiredOtelDefaults() {
}

@Test
void exportsOtlpAsRawProtobufToProfilesEndpoint() throws Exception {
void exportsOtlpAsGzippedProtobufToProfilesEndpoint() throws Exception {
byte[] profile = new byte[] {1, 2, 3, 4};
String[] contentType = new String[1];
String[] contentEncoding = new String[1];
byte[][] requestBody = new byte[1][];
CountDownLatch requestCaptured = new CountDownLatch(1);
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
server.createContext("/v1development/profiles", exchange -> {
contentType[0] = exchange.getRequestHeaders().getFirst("Content-Type");
contentEncoding[0] = exchange.getRequestHeaders().getFirst("Content-Encoding");
requestBody[0] = readAllBytes(exchange.getRequestBody());
requestCaptured.countDown();
exchange.sendResponseHeaders(200, -1);
Expand All @@ -136,7 +140,9 @@ void exportsOtlpAsRawProtobufToProfilesEndpoint() throws Exception {
Format.OTLP, EventType.CPU, Instant.EPOCH, Instant.EPOCH, profile, null));
assertTrue(requestCaptured.await(5, TimeUnit.SECONDS));
assertEquals("application/x-protobuf", contentType[0]);
assertEquals(Arrays.toString(profile), Arrays.toString(requestBody[0]));
assertEquals("gzip", contentEncoding[0]);
assertArrayEquals(profile, readAllBytes(new GZIPInputStream(
new ByteArrayInputStream(requestBody[0]))));
} finally {
exporter.stop();
server.stop(0);
Expand Down
Loading