Simplify unknown compression handling
MODIFY
dd-java-agent/agent-profiling/profiling-uploader/src/main/java/com/datadog/profiling/uploader/CompressionType.java
dd-java-agent/agent-profiling/profiling-uploader/src/main/java/com/datadog/profiling/uploader/CompressionType.java
package com.datadog.profiling.uploader;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
enum CompressionType {
/** No compression */
OFF,
@@ -8,13 +11,11 @@ enum CompressionType {
/** Lower compression ratio with less CPU overhead * */
LOW,
/** Better compression ratio for the price of higher CPU usage * */
- MEDIUM,
- /** Unknown compression config value */
- UNKNOWN;
+ MEDIUM;
- static CompressionType of(final String type) {
+ static CompressionType of(String type) {
if (type == null) {
- return UNKNOWN;
+ type = "";
}
switch (type.toLowerCase()) {
@@ -27,7 +28,8 @@ enum CompressionType {
case "medium":
return MEDIUM;
default:
- return UNKNOWN;
+ log.warn("Unrecognizable compression type: {}. Defaulting to 'on'.", type);
+ return ON;
}
}
}

MODIFY
dd-java-agent/agent-profiling/profiling-uploader/src/main/java/com/datadog/profiling/uploader/RecordingUploader.java
dd-java-agent/agent-profiling/profiling-uploader/src/main/java/com/datadog/profiling/uploader/RecordingUploader.java
@@ -244,26 +244,22 @@ public final class RecordingUploader {
// currently only gzip and off are supported
// this needs to be updated once more compression types are added
switch (type) {
- case LOW:
- {
- compression = (is, expectedSize) -> StreamUtils.lz4Stream(is, expectedSize, consumer);
- break;
- }
case ON:
case MEDIUM:
+ default:
{
compression = (is, expectedSize) -> StreamUtils.gzipStream(is, expectedSize, consumer);
break;
}
- case OFF:
+ case LOW:
{
- compression = (is, expectedSize) -> StreamUtils.readStream(is, expectedSize, consumer);
+ compression = (is, expectedSize) -> StreamUtils.lz4Stream(is, expectedSize, consumer);
break;
}
- default:
+ case OFF:
{
- log.warn("Unrecognizable compression type: {}. Defaulting to 'on'.", type);
- compression = (is, expectedSize) -> StreamUtils.gzipStream(is, expectedSize, consumer);
+ compression = (is, expectedSize) -> StreamUtils.readStream(is, expectedSize, consumer);
+ break;
}
}
return compression;

MODIFY
dd-java-agent/agent-profiling/profiling-uploader/src/test/java/com/datadog/profiling/uploader/CompressionTypeTest.java
dd-java-agent/agent-profiling/profiling-uploader/src/test/java/com/datadog/profiling/uploader/CompressionTypeTest.java
@@ -9,10 +9,15 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
class CompressionTypeTest {
+
+ @Test
+ void testEmpty() {
+ assertEquals(CompressionType.ON, CompressionType.of(""));
+ }
+
@Test
- void testDefault() {
- assertEquals(CompressionType.UNKNOWN, CompressionType.of(""));
- assertEquals(CompressionType.UNKNOWN, CompressionType.of(null));
+ void testNull() {
+ assertEquals(CompressionType.ON, CompressionType.of(null));
}
@ParameterizedTest

Simplify unknown compression handling