Fix tests after changing config from static to instance access

This commit is contained in:
Luca Abbati 2019-06-05 10:56:20 +02:00
parent 901efee50e
commit 8debe771d4
No known key found for this signature in database
GPG Key ID: 74DBB952D9BA17F2
4 changed files with 15 additions and 11 deletions

View File

@ -23,17 +23,13 @@ public abstract class BaseDecorator {
protected final float traceAnalyticsSampleRate; protected final float traceAnalyticsSampleRate;
protected BaseDecorator() { protected BaseDecorator() {
Config config = Config.get();
final String[] instrumentationNames = instrumentationNames(); final String[] instrumentationNames = instrumentationNames();
traceAnalyticsEnabled = traceAnalyticsEnabled =
instrumentationNames.length > 0 instrumentationNames.length > 0
&& Config.get() && config.isTraceAnalyticsIntegrationEnabled(
.isTraceAnalyticsIntegrationEnabled( new TreeSet<>(Arrays.asList(instrumentationNames)), traceAnalyticsDefault());
new TreeSet<>(Arrays.asList(instrumentationNames)), traceAnalyticsDefault()); traceAnalyticsSampleRate = config.getInstrumentationAnalyticsSampleRate(instrumentationNames);
float rate = 1.0f;
for (final String name : instrumentationNames) {
rate = Config.get().getInstrumentationAnalyticsSampleRate(name);
}
traceAnalyticsSampleRate = rate;
} }
protected abstract String[] instrumentationNames(); protected abstract String[] instrumentationNames();

View File

@ -172,6 +172,7 @@ class BaseDecoratorTest extends Specification {
when: when:
BaseDecorator dec = withSystemProperty("dd.${integName}.analytics.enabled", "true") { BaseDecorator dec = withSystemProperty("dd.${integName}.analytics.enabled", "true") {
withSystemProperty("dd.${integName}.analytics.sample-rate", "$sampleRate") { withSystemProperty("dd.${integName}.analytics.sample-rate", "$sampleRate") {
ConfigUtils.resetConfig()
newDecorator(enabled) newDecorator(enabled)
} }
} }

View File

@ -81,6 +81,7 @@ class DefaultInstrumenterTest extends Specification {
def "configure default sys prop as #value"() { def "configure default sys prop as #value"() {
setup: setup:
System.setProperty("dd.integrations.enabled", value) System.setProperty("dd.integrations.enabled", value)
ConfigUtils.resetConfig()
def target = new TestDefaultInstrumenter("test") def target = new TestDefaultInstrumenter("test")
target.instrument(new AgentBuilder.Default()) target.instrument(new AgentBuilder.Default())
@ -98,6 +99,7 @@ class DefaultInstrumenterTest extends Specification {
def "configure default env var as #value"() { def "configure default env var as #value"() {
setup: setup:
environmentVariables.set("DD_INTEGRATIONS_ENABLED", value) environmentVariables.set("DD_INTEGRATIONS_ENABLED", value)
ConfigUtils.resetConfig()
def target = new TestDefaultInstrumenter("test") def target = new TestDefaultInstrumenter("test")
target.instrument(new AgentBuilder.Default()) target.instrument(new AgentBuilder.Default())

View File

@ -439,9 +439,14 @@ public class Config {
* Returns the sample rate for the specified instrumentation or {@link * Returns the sample rate for the specified instrumentation or {@link
* #DEFAULT_ANALYTICS_SAMPLE_RATE} if none specified. * #DEFAULT_ANALYTICS_SAMPLE_RATE} if none specified.
*/ */
public float getInstrumentationAnalyticsSampleRate(String instrumentationName) { public float getInstrumentationAnalyticsSampleRate(String... aliases) {
return getFloatSettingFromEnvironment( for (final String alias : aliases) {
instrumentationName + ".analytics.sample-rate", DEFAULT_ANALYTICS_SAMPLE_RATE); Float rate = getFloatSettingFromEnvironment(alias + ".analytics.sample-rate", null);
if (null != rate) {
return rate;
}
}
return DEFAULT_ANALYTICS_SAMPLE_RATE;
} }
/** /**