Merge pull request #75 from tyler/yaml
Add default config values to the yaml config
This commit is contained in:
commit
b4457148fd
|
@ -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;
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.datadoghq.trace.resolver;
|
||||
|
||||
import com.datadoghq.trace.writer.DDAgentWriter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -12,8 +13,8 @@ import java.util.Map;
|
|||
public class TracerConfig {
|
||||
|
||||
private String defaultServiceName;
|
||||
private WriterConfig writer;
|
||||
private SamplerConfig sampler;
|
||||
private WriterConfig writer = new WriterConfig();
|
||||
private SamplerConfig sampler = new SamplerConfig();
|
||||
private List<DDSpanDecoratorConfig> decorators;
|
||||
|
||||
public String getDefaultServiceName() {
|
||||
|
@ -62,7 +63,7 @@ public class TracerConfig {
|
|||
class SamplerConfig {
|
||||
|
||||
private Double rate;
|
||||
private String type;
|
||||
private String type = "AllSampler";
|
||||
private Map<String, String> skipTagsPatterns;
|
||||
|
||||
public String getType() {
|
||||
|
@ -88,9 +89,9 @@ class SamplerConfig {
|
|||
|
||||
class WriterConfig {
|
||||
|
||||
private String host;
|
||||
private Integer port;
|
||||
private String type;
|
||||
private String host = "localhost";
|
||||
private Integer port = 8126;
|
||||
private String type = DDAgentWriter.class.getSimpleName();
|
||||
|
||||
public void setHost(final String host) {
|
||||
this.host = host;
|
||||
|
|
|
@ -9,10 +9,25 @@ import org.junit.Test;
|
|||
|
||||
public class DDTracerFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testDefaults() throws Exception {
|
||||
final TracerConfig tracerConfig =
|
||||
FactoryUtils.loadConfigFromResource("dd-trace-default", TracerConfig.class);
|
||||
|
||||
assertThat(tracerConfig.getWriter()).isNotNull();
|
||||
assertThat(tracerConfig.getSampler()).isNotNull();
|
||||
assertThat(tracerConfig.getDefaultServiceName()).isEqualTo("java-app-default");
|
||||
assertThat(tracerConfig.getWriter().getHost()).isEqualTo("localhost");
|
||||
assertThat(tracerConfig.getWriter().getPort()).isEqualTo(8126);
|
||||
assertThat(tracerConfig.getWriter().getType()).isEqualTo(DDAgentWriter.class.getSimpleName());
|
||||
assertThat(tracerConfig.getSampler().getType()).isEqualTo(AllSampler.class.getSimpleName());
|
||||
assertThat(tracerConfig.getSampler().getRate()).isNull();
|
||||
}
|
||||
|
||||
@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();
|
||||
|
@ -23,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");
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
defaultServiceName: java-app-default
|
Loading…
Reference in New Issue