-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for 'auto' value in DD_PROFILING_ENABLED (#7264)
- Loading branch information
Showing
6 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
internal-api/src/main/java/datadog/trace/api/profiling/ProfilingEnablement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package datadog.trace.api.profiling; | ||
|
||
public enum ProfilingEnablement { | ||
ENABLED(true), | ||
DISABLED(false), | ||
AUTO(true); | ||
|
||
private final boolean active; | ||
|
||
ProfilingEnablement(boolean active) { | ||
this.active = active; | ||
} | ||
|
||
public boolean isActive() { | ||
return active; | ||
} | ||
|
||
public static ProfilingEnablement of(String value) { | ||
if (value == null) { | ||
return DISABLED; | ||
} | ||
switch (value.toLowerCase()) { | ||
case "true": | ||
case "1": | ||
return ENABLED; | ||
case "auto": | ||
return AUTO; | ||
default: | ||
return DISABLED; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
internal-api/src/test/java/datadog/trace/api/profiling/ProfilingEnablementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package datadog.trace.api.profiling; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
class ProfilingEnablementTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideValues") | ||
void of(String value, ProfilingEnablement expected) { | ||
assertEquals(expected, ProfilingEnablement.of(value)); | ||
} | ||
|
||
private static Stream<Arguments> provideValues() { | ||
return Stream.of( | ||
Arguments.of("true", ProfilingEnablement.ENABLED), | ||
Arguments.of("TRUE", ProfilingEnablement.ENABLED), | ||
Arguments.of("tRuE", ProfilingEnablement.ENABLED), | ||
Arguments.of("1", ProfilingEnablement.ENABLED), | ||
Arguments.of("auto", ProfilingEnablement.AUTO), | ||
Arguments.of("AUTO", ProfilingEnablement.AUTO), | ||
Arguments.of("aUtO", ProfilingEnablement.AUTO), | ||
Arguments.of("false", ProfilingEnablement.DISABLED), | ||
Arguments.of("FALSE", ProfilingEnablement.DISABLED), | ||
Arguments.of("fAlSe", ProfilingEnablement.DISABLED), | ||
Arguments.of("0", ProfilingEnablement.DISABLED), | ||
Arguments.of("anything", ProfilingEnablement.DISABLED), | ||
Arguments.of(null, ProfilingEnablement.DISABLED)); | ||
} | ||
} |