Attempt to load config files with both `yaml` and `yml` suffix
MODIFY
dd-java-agent/src/main/java/com/datadoghq/trace/agent/InstrumentationChecker.java
dd-java-agent/src/main/java/com/datadoghq/trace/agent/InstrumentationChecker.java
@@ -17,7 +17,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class InstrumentationChecker {
- private static final String CONFIG_FILE = "dd-trace-supported-framework.yaml";
+ private static final String CONFIG_FILE = "dd-trace-supported-framework";
private final Map<String, List<Map<String, String>>> rules;
private final Map<String, String> frameworks;

MODIFY
dd-java-agent/src/test/java/com/datadoghq/trace/agent/InstrumentationCheckerTest.java
dd-java-agent/src/test/java/com/datadoghq/trace/agent/InstrumentationCheckerTest.java
@@ -13,9 +13,9 @@ public class InstrumentationCheckerTest {
@Before
public void setup() {
- Map<String, List<Map<String, String>>> rules =
- FactoryUtils.loadConfigFromResource("supported-version-test.yaml", Map.class);
- Map<String, String> frameworks =
+ final Map<String, List<Map<String, String>>> rules =
+ FactoryUtils.loadConfigFromResource("supported-version-test", Map.class);
+ final Map<String, String> frameworks =
new HashMap<String, String>() {
{
put("artifact-1", "1.2.3.1232");
@@ -30,7 +30,7 @@ public class InstrumentationCheckerTest {
@Test
public void testRules() throws Exception {
- List<String> rules = InstrumentationChecker.getUnsupportedRules();
+ final List<String> rules = InstrumentationChecker.getUnsupportedRules();
assertThat(rules.size()).isEqualTo(3);
assertThat(rules)
.containsExactlyInAnyOrder(

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/resolver/DDDecoratorsFactory.java
dd-trace/src/main/java/com/datadoghq/trace/resolver/DDDecoratorsFactory.java
@@ -11,7 +11,7 @@ public class DDDecoratorsFactory {
public static String DECORATORS_PACKAGE = "com.datadoghq.trace.integration.";
- public static final String CONFIG_PATH = "dd-trace-decorators.yaml";
+ public static final String CONFIG_PATH = "dd-trace-decorators";
/**
* Create decorators from configuration

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/resolver/DDTracerFactory.java
dd-trace/src/main/java/com/datadoghq/trace/resolver/DDTracerFactory.java
@@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j;
public class DDTracerFactory {
public static final String SYSTEM_PROPERTY_CONFIG_PATH = "dd.trace.configurationFile";
- public static final String CONFIG_PATH = "dd-trace.yaml";
+ public static final String CONFIG_PATH = "dd-trace";
private static final String DD_AGENT_WRITER_TYPE = DDAgentWriter.class.getSimpleName();
private static final String LOGGING_WRITER_TYPE = LoggingWriter.class.getSimpleName();

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/resolver/FactoryUtils.java
dd-trace/src/main/java/com/datadoghq/trace/resolver/FactoryUtils.java
@@ -5,7 +5,6 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.util.Enumeration;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@@ -31,14 +30,25 @@ public class FactoryUtils {
public static <A> A loadConfigFromResource(
final String resourceName, final Class<A> targetClass) {
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
A config = null;
+
+ // Try loading both suffixes
+ if (!resourceName.endsWith(".yaml") && !resourceName.endsWith(".yml")) {
+ config = loadConfigFromResource(resourceName + ".yaml", targetClass);
+ if (config == null) {
+ config = loadConfigFromResource(resourceName + ".yml", targetClass);
+ }
+ if (config != null) {
+ return config;
+ }
+ }
+
try {
- final Enumeration<URL> iter = classLoader.getResources(resourceName);
- if (iter.hasMoreElements()) {
- final URL url = iter.nextElement();
- log.info("Loading config from resource " + url);
- config = objectMapper.readValue(url.openStream(), targetClass);
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ final URL resource = classLoader.getResource(resourceName);
+ if (resource != null) {
+ log.info("Loading config from resource " + resource);
+ config = objectMapper.readValue(resource.openStream(), targetClass);
}
} catch (final IOException e) {
log.warn("Could not load configuration file {}.", resourceName);

MODIFY
dd-trace/src/test/java/com/datadoghq/trace/resolver/DDTracerFactoryTest.java
dd-trace/src/test/java/com/datadoghq/trace/resolver/DDTracerFactoryTest.java
@@ -12,7 +12,7 @@ public class DDTracerFactoryTest {
@Test
public void testDefaults() throws Exception {
final TracerConfig tracerConfig =
- FactoryUtils.loadConfigFromResource("dd-trace-default.yaml", TracerConfig.class);
+ FactoryUtils.loadConfigFromResource("dd-trace-default", TracerConfig.class);
assertThat(tracerConfig.getWriter()).isNotNull();
assertThat(tracerConfig.getSampler()).isNotNull();
@@ -27,7 +27,7 @@ public class DDTracerFactoryTest {
@Test
public void test() throws Exception {
TracerConfig tracerConfig =
- FactoryUtils.loadConfigFromResource("dd-trace-1.yaml", TracerConfig.class);
+ FactoryUtils.loadConfigFromResource("dd-trace-1", TracerConfig.class);
assertThat(tracerConfig.getWriter()).isNotNull();
assertThat(tracerConfig.getSampler()).isNotNull();
@@ -38,7 +38,7 @@ public class DDTracerFactoryTest {
assertThat(tracerConfig.getSampler().getType()).isEqualTo(AllSampler.class.getSimpleName());
assertThat(tracerConfig.getSampler().getRate()).isNull();
- tracerConfig = FactoryUtils.loadConfigFromResource("dd-trace-2.yaml", TracerConfig.class);
+ tracerConfig = FactoryUtils.loadConfigFromResource("dd-trace-2", TracerConfig.class);
assertThat(tracerConfig.getWriter()).isNotNull();
assertThat(tracerConfig.getDefaultServiceName()).isEqualTo("java-app");
assertThat(tracerConfig.getWriter().getHost("localhost")).isEqualTo("localhost");

RENAME
dd-trace/src/test/resources/dd-trace-2.yaml
dd-trace/src/test/resources/dd-trace-2.yml
RENAME
dd-trace/src/test/resources/dd-trace-default.yaml
dd-trace/src/test/resources/dd-trace-default.yml
Attempt to load config files with both `yaml` and `yml` suffix