Skip to content

Add zstd scenario to profile uploading tests #8869

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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 @@ -52,6 +52,7 @@
import datadog.trace.relocate.api.IOLogger;
import datadog.trace.util.PidHelper;
import delight.fileupload.FileUpload;
import io.airlift.compress.zstd.ZstdInputStream;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -337,7 +338,7 @@ public void testZippedInput() throws Exception {
}

@ParameterizedTest
@ValueSource(strings = {"on", "lz4", "gzip", "off", "invalid"})
@ValueSource(strings = {"on", "lz4", "gzip", "zstd", "off", "invalid"})
public void testCompression(final String compression) throws Exception {
when(config.getApiKey()).thenReturn(null);
when(config.getProfilingUploadCompression()).thenReturn(compression);
Expand Down Expand Up @@ -372,6 +373,8 @@ public void testCompression(final String compression) throws Exception {
byte[] uploadedBytes = rawJfr.get();
if (compression.equals("gzip")) {
uploadedBytes = unGzip(uploadedBytes);
} else if (compression.equals("zstd")) {
uploadedBytes = unZstd(uploadedBytes);
} else if (compression.equals("on")
|| compression.equals("lz4")
|| compression.equals("invalid")) {
Expand Down Expand Up @@ -895,6 +898,13 @@ private static byte[] unLz4(final byte[] compressed) throws IOException {
return result.toByteArray();
}

private static byte[] unZstd(final byte[] compressed) throws IOException {
final InputStream stream = new ZstdInputStream(new ByteArrayInputStream(compressed));
final ByteArrayOutputStream result = new ByteArrayOutputStream();
ByteStreams.copy(stream, result);
return result.toByteArray();
}

private void uploadAndWait(final RecordingType recordingType, final RecordingData data)
throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
Expand Down