Merge pull request #1348 from DataDog/mar-kolya/add-profiling-site-config
Add option to configure Datadog site used to send profiling information
This commit is contained in:
commit
c758a81bc9
|
@ -53,6 +53,7 @@ import okhttp3.Response;
|
|||
/** The class for uploading recordings to the backend. */
|
||||
@Slf4j
|
||||
public final class RecordingUploader {
|
||||
|
||||
private static final MediaType OCTET_STREAM = MediaType.parse("application/octet-stream");
|
||||
|
||||
static final String RECORDING_NAME_PARAM = "recording-name";
|
||||
|
@ -120,7 +121,7 @@ public final class RecordingUploader {
|
|||
private final Deque<Integer> requestSizeHistory;
|
||||
|
||||
public RecordingUploader(final Config config) {
|
||||
url = config.getProfilingUrl();
|
||||
url = config.getFinalProfilingUrl();
|
||||
apiKey = config.getProfilingApiKey();
|
||||
|
||||
/*
|
||||
|
@ -233,6 +234,7 @@ public final class RecordingUploader {
|
|||
|
||||
@FunctionalInterface
|
||||
private interface Compression {
|
||||
|
||||
RequestBody compress(InputStream is, int expectedSize) throws IOException;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ public class RecordingUploaderTest {
|
|||
server.start();
|
||||
url = server.url(URL_PATH);
|
||||
|
||||
when(config.getProfilingUrl()).thenReturn(server.url(URL_PATH).toString());
|
||||
when(config.getFinalProfilingUrl()).thenReturn(server.url(URL_PATH).toString());
|
||||
when(config.getProfilingApiKey()).thenReturn(APIKEY_VALUE);
|
||||
when(config.getMergedProfilingTags()).thenReturn(TAGS);
|
||||
when(config.getProfilingUploadTimeout()).thenReturn((int) REQUEST_TIMEOUT.getSeconds());
|
||||
|
@ -199,7 +199,7 @@ public class RecordingUploaderTest {
|
|||
public void testRequestWithProxy() throws IOException, InterruptedException {
|
||||
final String backendHost = "intake.profiling.datadoghq.com:1234";
|
||||
final String backendUrl = "http://intake.profiling.datadoghq.com:1234" + URL_PATH;
|
||||
when(config.getProfilingUrl())
|
||||
when(config.getFinalProfilingUrl())
|
||||
.thenReturn("http://intake.profiling.datadoghq.com:1234" + URL_PATH);
|
||||
when(config.getProfilingProxyHost()).thenReturn(server.url("").host());
|
||||
when(config.getProfilingProxyPort()).thenReturn(server.url("").port());
|
||||
|
@ -235,7 +235,7 @@ public class RecordingUploaderTest {
|
|||
@Test
|
||||
public void testRequestWithProxyDefaultPassword() throws IOException, InterruptedException {
|
||||
final String backendUrl = "http://intake.profiling.datadoghq.com:1234" + URL_PATH;
|
||||
when(config.getProfilingUrl())
|
||||
when(config.getFinalProfilingUrl())
|
||||
.thenReturn("http://intake.profiling.datadoghq.com:1234" + URL_PATH);
|
||||
when(config.getProfilingProxyHost()).thenReturn(server.url("").host());
|
||||
when(config.getProfilingProxyPort()).thenReturn(server.url("").port());
|
||||
|
|
|
@ -40,12 +40,16 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Slf4j
|
||||
@ToString(includeFieldNames = true)
|
||||
public class Config {
|
||||
|
||||
/** Config keys below */
|
||||
private static final String PREFIX = "dd.";
|
||||
|
||||
public static final String PROFILING_URL_TEMPLATE = "https://intake.profile.%s/v1/input";
|
||||
|
||||
private static final Pattern ENV_REPLACEMENT = Pattern.compile("[^a-zA-Z0-9_]");
|
||||
|
||||
public static final String CONFIGURATION_FILE = "trace.config";
|
||||
public static final String SITE = "site";
|
||||
public static final String SERVICE_NAME = "service.name";
|
||||
public static final String TRACE_ENABLED = "trace.enabled";
|
||||
public static final String INTEGRATIONS_ENABLED = "integrations.enabled";
|
||||
|
@ -93,7 +97,7 @@ public class Config {
|
|||
public static final String JMX_FETCH_ENABLED = "jmxfetch.enabled";
|
||||
public static final String JMX_FETCH_CONFIG_DIR = "jmxfetch.config.dir";
|
||||
public static final String JMX_FETCH_CONFIG = "jmxfetch.config";
|
||||
public static final String JMX_FETCH_METRICS_CONFIGS = "jmxfetch.metrics-configs";
|
||||
@Deprecated public static final String JMX_FETCH_METRICS_CONFIGS = "jmxfetch.metrics-configs";
|
||||
public static final String JMX_FETCH_CHECK_PERIOD = "jmxfetch.check-period";
|
||||
public static final String JMX_FETCH_REFRESH_BEANS_PERIOD = "jmxfetch.refresh-beans-period";
|
||||
public static final String JMX_FETCH_STATSD_HOST = "jmxfetch.statsd.host";
|
||||
|
@ -106,8 +110,8 @@ public class Config {
|
|||
public static final String LOGS_INJECTION_ENABLED = "logs.injection";
|
||||
|
||||
public static final String PROFILING_ENABLED = "profiling.enabled";
|
||||
@Deprecated // Use dd.site instead
|
||||
public static final String PROFILING_URL = "profiling.url";
|
||||
|
||||
public static final String PROFILING_API_KEY = "profiling.api-key";
|
||||
public static final String PROFILING_API_KEY_FILE = "profiling.api-key-file";
|
||||
public static final String PROFILING_API_KEY_OLD = "profiling.apikey";
|
||||
|
@ -134,6 +138,7 @@ public class Config {
|
|||
public static final String LANGUAGE_TAG_KEY = "language";
|
||||
public static final String LANGUAGE_TAG_VALUE = "jvm";
|
||||
|
||||
public static final String DEFAULT_SITE = "datadoghq.com";
|
||||
public static final String DEFAULT_SERVICE_NAME = "unnamed-java-app";
|
||||
|
||||
private static final boolean DEFAULT_TRACE_ENABLED = true;
|
||||
|
@ -173,8 +178,6 @@ public class Config {
|
|||
public static final boolean DEFAULT_LOGS_INJECTION_ENABLED = false;
|
||||
|
||||
public static final boolean DEFAULT_PROFILING_ENABLED = false;
|
||||
public static final String DEFAULT_PROFILING_URL =
|
||||
"https://intake.profile.datadoghq.com/v1/input";
|
||||
public static final int DEFAULT_PROFILING_START_DELAY = 10;
|
||||
public static final boolean DEFAULT_PROFILING_START_FORCE_FIRST = false;
|
||||
public static final int DEFAULT_PROFILING_UPLOAD_PERIOD = 60; // 1 min
|
||||
|
@ -220,6 +223,12 @@ public class Config {
|
|||
*/
|
||||
@Getter private final String runtimeId;
|
||||
|
||||
/**
|
||||
* Note: this has effect only on profiling site. Traces are sent to Datadog agent and are not
|
||||
* affected by this setting.
|
||||
*/
|
||||
@Getter private final String site;
|
||||
|
||||
@Getter private final String serviceName;
|
||||
@Getter private final boolean traceEnabled;
|
||||
@Getter private final boolean integrationsEnabled;
|
||||
|
@ -281,7 +290,7 @@ public class Config {
|
|||
@Getter private final Double traceRateLimit;
|
||||
|
||||
@Getter private final boolean profilingEnabled;
|
||||
@Getter private final String profilingUrl;
|
||||
@Deprecated private final String profilingUrl;
|
||||
@Getter private final String profilingApiKey;
|
||||
private final Map<String, String> profilingTags;
|
||||
@Getter private final int profilingStartDelay;
|
||||
|
@ -305,6 +314,7 @@ public class Config {
|
|||
|
||||
runtimeId = UUID.randomUUID().toString();
|
||||
|
||||
site = getSettingFromEnvironment(SITE, DEFAULT_SITE);
|
||||
serviceName = getSettingFromEnvironment(SERVICE_NAME, DEFAULT_SERVICE_NAME);
|
||||
|
||||
traceEnabled = getBooleanSettingFromEnvironment(TRACE_ENABLED, DEFAULT_TRACE_ENABLED);
|
||||
|
@ -427,7 +437,7 @@ public class Config {
|
|||
|
||||
profilingEnabled =
|
||||
getBooleanSettingFromEnvironment(PROFILING_ENABLED, DEFAULT_PROFILING_ENABLED);
|
||||
profilingUrl = getSettingFromEnvironment(PROFILING_URL, DEFAULT_PROFILING_URL);
|
||||
profilingUrl = getSettingFromEnvironment(PROFILING_URL, null);
|
||||
// Note: We do not want APiKey to be loaded from property for security reasons
|
||||
// Note: we do not use defined default here
|
||||
// FIXME: We should use better authentication mechanism
|
||||
|
@ -490,6 +500,7 @@ public class Config {
|
|||
private Config(final Properties properties, final Config parent) {
|
||||
runtimeId = parent.runtimeId;
|
||||
|
||||
site = properties.getProperty(SITE, parent.site);
|
||||
serviceName = properties.getProperty(SERVICE_NAME, parent.serviceName);
|
||||
|
||||
traceEnabled = getPropertyBooleanValue(properties, TRACE_ENABLED, parent.traceEnabled);
|
||||
|
@ -746,17 +757,25 @@ public class Config {
|
|||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
||||
public String getFinalProfilingUrl() {
|
||||
if (profilingUrl == null) {
|
||||
return String.format(PROFILING_URL_TEMPLATE, site);
|
||||
} else {
|
||||
return profilingUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIntegrationEnabled(
|
||||
final SortedSet<String> integrationNames, final boolean defaultEnabled) {
|
||||
return integrationEnabled(integrationNames, defaultEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should only be used internally. Use the instance getter instead {@link
|
||||
* #isIntegrationEnabled(SortedSet, boolean)}.
|
||||
* @param integrationNames
|
||||
* @param defaultEnabled
|
||||
* @return
|
||||
* @deprecated This method should only be used internally. Use the instance getter instead {@link
|
||||
* #isIntegrationEnabled(SortedSet, boolean)}.
|
||||
*/
|
||||
public static boolean integrationEnabled(
|
||||
final SortedSet<String> integrationNames, final boolean defaultEnabled) {
|
||||
|
@ -786,11 +805,11 @@ public class Config {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should only be used internally. Use the instance getter instead {@link
|
||||
* #isJmxFetchIntegrationEnabled(SortedSet, boolean)}.
|
||||
* @param integrationNames
|
||||
* @param defaultEnabled
|
||||
* @return
|
||||
* @deprecated This method should only be used internally. Use the instance getter instead {@link
|
||||
* #isJmxFetchIntegrationEnabled(SortedSet, boolean)}.
|
||||
*/
|
||||
public static boolean jmxFetchIntegrationEnabled(
|
||||
final SortedSet<String> integrationNames, final boolean defaultEnabled) {
|
||||
|
@ -815,11 +834,11 @@ public class Config {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should only be used internally. Use the instance getter instead {@link
|
||||
* #isTraceAnalyticsIntegrationEnabled(SortedSet, boolean)}.
|
||||
* @param integrationNames
|
||||
* @param defaultEnabled
|
||||
* @return
|
||||
* @deprecated This method should only be used internally. Use the instance getter instead {@link
|
||||
* #isTraceAnalyticsIntegrationEnabled(SortedSet, boolean)}.
|
||||
*/
|
||||
public static boolean traceAnalyticsIntegrationEnabled(
|
||||
final SortedSet<String> integrationNames, final boolean defaultEnabled) {
|
||||
|
|
|
@ -55,6 +55,7 @@ import static datadog.trace.api.Config.RUNTIME_ID_TAG
|
|||
import static datadog.trace.api.Config.SERVICE_MAPPING
|
||||
import static datadog.trace.api.Config.SERVICE_NAME
|
||||
import static datadog.trace.api.Config.SERVICE_TAG
|
||||
import static datadog.trace.api.Config.SITE
|
||||
import static datadog.trace.api.Config.SPAN_TAGS
|
||||
import static datadog.trace.api.Config.SPLIT_BY_TAGS
|
||||
import static datadog.trace.api.Config.TAGS
|
||||
|
@ -134,7 +135,8 @@ class ConfigTest extends DDSpecification {
|
|||
config.healthMetricsStatsdPort == null
|
||||
|
||||
config.profilingEnabled == false
|
||||
config.profilingUrl == Config.DEFAULT_PROFILING_URL
|
||||
config.site == Config.DEFAULT_SITE
|
||||
config.profilingUrl == null
|
||||
config.profilingApiKey == null
|
||||
config.mergedProfilingTags == [(HOST_TAG): config.getHostName(), (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
|
||||
config.profilingStartDelay == 10
|
||||
|
@ -199,6 +201,7 @@ class ConfigTest extends DDSpecification {
|
|||
prop.setProperty(TRACE_RATE_LIMIT, "200")
|
||||
|
||||
prop.setProperty(PROFILING_ENABLED, "true")
|
||||
prop.setProperty(SITE, "new site")
|
||||
prop.setProperty(PROFILING_URL, "new url")
|
||||
prop.setProperty(PROFILING_API_KEY, "new api key")
|
||||
prop.setProperty(PROFILING_TAGS, "f:6,host:test-host")
|
||||
|
@ -255,6 +258,7 @@ class ConfigTest extends DDSpecification {
|
|||
config.traceRateLimit == 200
|
||||
|
||||
config.profilingEnabled == true
|
||||
config.site == "new site"
|
||||
config.profilingUrl == "new url"
|
||||
config.profilingApiKey == "new api key" // we can still override via internal properties object
|
||||
config.mergedProfilingTags == [b: "2", f: "6", (HOST_TAG): "test-host", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
|
||||
|
@ -311,6 +315,7 @@ class ConfigTest extends DDSpecification {
|
|||
System.setProperty(PREFIX + TRACE_RATE_LIMIT, "200")
|
||||
|
||||
System.setProperty(PREFIX + PROFILING_ENABLED, "true")
|
||||
System.setProperty(PREFIX + SITE, "new site")
|
||||
System.setProperty(PREFIX + PROFILING_URL, "new url")
|
||||
System.setProperty(PREFIX + PROFILING_API_KEY, "new api key")
|
||||
System.setProperty(PREFIX + PROFILING_TAGS, "f:6,host:test-host")
|
||||
|
@ -367,6 +372,7 @@ class ConfigTest extends DDSpecification {
|
|||
config.traceRateLimit == 200
|
||||
|
||||
config.profilingEnabled == true
|
||||
config.site == "new site"
|
||||
config.profilingUrl == "new url"
|
||||
config.profilingApiKey == null // system properties cannot be used to provide a key
|
||||
config.mergedProfilingTags == [b: "2", f: "6", (HOST_TAG): "test-host", (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
|
||||
|
@ -1106,6 +1112,15 @@ class ConfigTest extends DDSpecification {
|
|||
|
||||
config.mergedProfilingTags == [a: "1", f: "6", (HOST_TAG): config.getHostName(), (RUNTIME_ID_TAG): config.getRuntimeId(), (SERVICE_TAG): config.serviceName, (LANGUAGE_TAG_KEY): LANGUAGE_TAG_VALUE]
|
||||
}
|
||||
|
||||
def "toString works when passwords are empty"() {
|
||||
when:
|
||||
def config = new Config()
|
||||
|
||||
then:
|
||||
config.toString().contains("profilingApiKey=null")
|
||||
config.toString().contains("profilingProxyPassword=null")
|
||||
}
|
||||
|
||||
def "sensitive information removed for toString/debug log"() {
|
||||
setup:
|
||||
|
@ -1124,12 +1139,30 @@ class ConfigTest extends DDSpecification {
|
|||
config.profilingProxyPassword == "test-secret-proxy-password"
|
||||
}
|
||||
|
||||
def "toString works when passwords are empty"() {
|
||||
def "custom datadog site"() {
|
||||
setup:
|
||||
def prop = new Properties()
|
||||
prop.setProperty(SITE, "some.new.site")
|
||||
|
||||
when:
|
||||
def config = new Config()
|
||||
Config config = Config.get(prop)
|
||||
|
||||
then:
|
||||
config.toString().contains("profilingApiKey=null")
|
||||
config.toString().contains("profilingProxyPassword=null")
|
||||
config.getFinalProfilingUrl() == "https://intake.profile.some.new.site/v1/input"
|
||||
}
|
||||
|
||||
|
||||
def "custom profiling url override"() {
|
||||
setup:
|
||||
def prop = new Properties()
|
||||
prop.setProperty(SITE, "some.new.site")
|
||||
prop.setProperty(PROFILING_URL, "https://some.new.url/goes/here")
|
||||
|
||||
when:
|
||||
Config config = Config.get(prop)
|
||||
|
||||
then:
|
||||
config.getFinalProfilingUrl() == "https://some.new.url/goes/here"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue