Simplify unknown compression handling
This commit is contained in:
parent
ca9f623d05
commit
ef9ebffc54
|
@ -1,5 +1,8 @@
|
||||||
package com.datadog.profiling.uploader;
|
package com.datadog.profiling.uploader;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
enum CompressionType {
|
enum CompressionType {
|
||||||
/** No compression */
|
/** No compression */
|
||||||
OFF,
|
OFF,
|
||||||
|
@ -8,13 +11,11 @@ enum CompressionType {
|
||||||
/** Lower compression ratio with less CPU overhead * */
|
/** Lower compression ratio with less CPU overhead * */
|
||||||
LOW,
|
LOW,
|
||||||
/** Better compression ratio for the price of higher CPU usage * */
|
/** Better compression ratio for the price of higher CPU usage * */
|
||||||
MEDIUM,
|
MEDIUM;
|
||||||
/** Unknown compression config value */
|
|
||||||
UNKNOWN;
|
|
||||||
|
|
||||||
static CompressionType of(final String type) {
|
static CompressionType of(String type) {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return UNKNOWN;
|
type = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type.toLowerCase()) {
|
switch (type.toLowerCase()) {
|
||||||
|
@ -27,7 +28,8 @@ enum CompressionType {
|
||||||
case "medium":
|
case "medium":
|
||||||
return MEDIUM;
|
return MEDIUM;
|
||||||
default:
|
default:
|
||||||
return UNKNOWN;
|
log.warn("Unrecognizable compression type: {}. Defaulting to 'on'.", type);
|
||||||
|
return ON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,27 +244,23 @@ public final class RecordingUploader {
|
||||||
// currently only gzip and off are supported
|
// currently only gzip and off are supported
|
||||||
// this needs to be updated once more compression types are added
|
// this needs to be updated once more compression types are added
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case ON:
|
||||||
|
case MEDIUM:
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
compression = (is, expectedSize) -> StreamUtils.gzipStream(is, expectedSize, consumer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case LOW:
|
case LOW:
|
||||||
{
|
{
|
||||||
compression = (is, expectedSize) -> StreamUtils.lz4Stream(is, expectedSize, consumer);
|
compression = (is, expectedSize) -> StreamUtils.lz4Stream(is, expectedSize, consumer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ON:
|
|
||||||
case MEDIUM:
|
|
||||||
{
|
|
||||||
compression = (is, expectedSize) -> StreamUtils.gzipStream(is, expectedSize, consumer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case OFF:
|
case OFF:
|
||||||
{
|
{
|
||||||
compression = (is, expectedSize) -> StreamUtils.readStream(is, expectedSize, consumer);
|
compression = (is, expectedSize) -> StreamUtils.readStream(is, expectedSize, consumer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
{
|
|
||||||
log.warn("Unrecognizable compression type: {}. Defaulting to 'on'.", type);
|
|
||||||
compression = (is, expectedSize) -> StreamUtils.gzipStream(is, expectedSize, consumer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return compression;
|
return compression;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,15 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.EnumSource;
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
|
||||||
class CompressionTypeTest {
|
class CompressionTypeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDefault() {
|
void testEmpty() {
|
||||||
assertEquals(CompressionType.UNKNOWN, CompressionType.of(""));
|
assertEquals(CompressionType.ON, CompressionType.of(""));
|
||||||
assertEquals(CompressionType.UNKNOWN, CompressionType.of(null));
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNull() {
|
||||||
|
assertEquals(CompressionType.ON, CompressionType.of(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
|
Loading…
Reference in New Issue