Fix tests after changing config from static to instance access
This commit is contained in:
parent
901efee50e
commit
8debe771d4
|
@ -23,17 +23,13 @@ public abstract class BaseDecorator {
|
|||
protected final float traceAnalyticsSampleRate;
|
||||
|
||||
protected BaseDecorator() {
|
||||
Config config = Config.get();
|
||||
final String[] instrumentationNames = instrumentationNames();
|
||||
traceAnalyticsEnabled =
|
||||
instrumentationNames.length > 0
|
||||
&& Config.get()
|
||||
.isTraceAnalyticsIntegrationEnabled(
|
||||
&& config.isTraceAnalyticsIntegrationEnabled(
|
||||
new TreeSet<>(Arrays.asList(instrumentationNames)), traceAnalyticsDefault());
|
||||
float rate = 1.0f;
|
||||
for (final String name : instrumentationNames) {
|
||||
rate = Config.get().getInstrumentationAnalyticsSampleRate(name);
|
||||
}
|
||||
traceAnalyticsSampleRate = rate;
|
||||
traceAnalyticsSampleRate = config.getInstrumentationAnalyticsSampleRate(instrumentationNames);
|
||||
}
|
||||
|
||||
protected abstract String[] instrumentationNames();
|
||||
|
|
|
@ -172,6 +172,7 @@ class BaseDecoratorTest extends Specification {
|
|||
when:
|
||||
BaseDecorator dec = withSystemProperty("dd.${integName}.analytics.enabled", "true") {
|
||||
withSystemProperty("dd.${integName}.analytics.sample-rate", "$sampleRate") {
|
||||
ConfigUtils.resetConfig()
|
||||
newDecorator(enabled)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ class DefaultInstrumenterTest extends Specification {
|
|||
def "configure default sys prop as #value"() {
|
||||
setup:
|
||||
System.setProperty("dd.integrations.enabled", value)
|
||||
ConfigUtils.resetConfig()
|
||||
def target = new TestDefaultInstrumenter("test")
|
||||
target.instrument(new AgentBuilder.Default())
|
||||
|
||||
|
@ -98,6 +99,7 @@ class DefaultInstrumenterTest extends Specification {
|
|||
def "configure default env var as #value"() {
|
||||
setup:
|
||||
environmentVariables.set("DD_INTEGRATIONS_ENABLED", value)
|
||||
ConfigUtils.resetConfig()
|
||||
def target = new TestDefaultInstrumenter("test")
|
||||
target.instrument(new AgentBuilder.Default())
|
||||
|
||||
|
|
|
@ -439,9 +439,14 @@ public class Config {
|
|||
* Returns the sample rate for the specified instrumentation or {@link
|
||||
* #DEFAULT_ANALYTICS_SAMPLE_RATE} if none specified.
|
||||
*/
|
||||
public float getInstrumentationAnalyticsSampleRate(String instrumentationName) {
|
||||
return getFloatSettingFromEnvironment(
|
||||
instrumentationName + ".analytics.sample-rate", DEFAULT_ANALYTICS_SAMPLE_RATE);
|
||||
public float getInstrumentationAnalyticsSampleRate(String... aliases) {
|
||||
for (final String alias : aliases) {
|
||||
Float rate = getFloatSettingFromEnvironment(alias + ".analytics.sample-rate", null);
|
||||
if (null != rate) {
|
||||
return rate;
|
||||
}
|
||||
}
|
||||
return DEFAULT_ANALYTICS_SAMPLE_RATE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue