@@ -20,11 +20,13 @@ class ConfigCollectorTest extends DDSpecification {
2020 def " non-default config settings get collected" () {
2121 setup :
2222 injectEnvConfig(Strings . toEnvVar(configKey), configValue)
23+ def origin = ConfigOrigin . ENV
2324
2425 expect :
25- def setting = ConfigCollector . get(). collect(). get(configKey)
26- setting. stringValue() == configValue
27- setting. origin == ConfigOrigin . ENV
26+ def envConfigByKey = ConfigCollector . get(). collect(). get(origin)
27+ def config = envConfigByKey. get(configKey)
28+ config. stringValue() == configValue
29+ config. origin == ConfigOrigin . ENV
2830
2931 where :
3032 configKey | configValue
@@ -64,16 +66,27 @@ class ConfigCollectorTest extends DDSpecification {
6466
6567 def " should collect merged data from multiple sources" () {
6668 setup :
67- injectEnvConfig(Strings . toEnvVar(configKey), configValue1 )
68- injectSysConfig(configKey, configValue2 )
69+ injectEnvConfig(Strings . toEnvVar(configKey), envConfigValue )
70+ injectSysConfig(configKey, jvmConfigValue )
6971
70- expect :
71- def setting = ConfigCollector . get(). collect(). get(configKey)
72- setting. stringValue() == expectedValue
73- setting. origin == ConfigOrigin . JVM_PROP
72+ when :
73+ def collected = ConfigCollector . get(). collect()
74+
75+ then :
76+ def envSetting = collected. get(ConfigOrigin . ENV )
77+ def envConfig = envSetting. get(configKey)
78+ envConfig. stringValue() == envConfigValue
79+ envConfig. origin == ConfigOrigin . ENV
80+
81+ def jvmSetting = collected. get(ConfigOrigin . JVM_PROP )
82+ def jvmConfig = jvmSetting. get(configKey)
83+ jvmConfig. stringValue(). split(' ,' ). toList(). toSet() == jvmConfigValue. split(' ,' ). toList(). toSet()
84+ jvmConfig. origin == ConfigOrigin . JVM_PROP
85+
86+ // TODO: Add a check for which setting the collector recognizes as highest precedence
7487
7588 where :
76- configKey | configValue1 | configValue2 | expectedValue
89+ configKey | envConfigValue | jvmConfigValue | expectedValue
7790 // ConfigProvider.getMergedMap
7891 TracerConfig . TRACE_PEER_SERVICE_MAPPING | " service1:best_service,userService:my_service" | " service2:backup_service" | " service2:backup_service,service1:best_service,userService:my_service"
7992 // ConfigProvider.getOrderedMap
@@ -84,7 +97,8 @@ class ConfigCollectorTest extends DDSpecification {
8497
8598 def " default not-null config settings are collected" () {
8699 expect :
87- def setting = ConfigCollector . get(). collect(). get(configKey)
100+ def defaultConfigByKey = ConfigCollector . get(). collect(). get(ConfigOrigin . DEFAULT )
101+ def setting = defaultConfigByKey. get(configKey)
88102 setting. origin == ConfigOrigin . DEFAULT
89103 setting. stringValue() == defaultValue
90104
@@ -100,7 +114,8 @@ class ConfigCollectorTest extends DDSpecification {
100114
101115 def " default null config settings are also collected" () {
102116 when :
103- ConfigSetting cs = ConfigCollector . get(). collect(). get(configKey)
117+ def defaultConfigByKey = ConfigCollector . get(). collect(). get(ConfigOrigin . DEFAULT )
118+ ConfigSetting cs = defaultConfigByKey. get(configKey)
104119
105120 then :
106121 cs. key == configKey
@@ -121,7 +136,8 @@ class ConfigCollectorTest extends DDSpecification {
121136
122137 def " default empty maps and list config settings are collected as empty strings" () {
123138 when :
124- ConfigSetting cs = ConfigCollector . get(). collect(). get(configKey)
139+ def defaultConfigByKey = ConfigCollector . get(). collect(). get(ConfigOrigin . DEFAULT )
140+ ConfigSetting cs = defaultConfigByKey. get(configKey)
125141
126142 then :
127143 cs. key == configKey
@@ -143,15 +159,15 @@ class ConfigCollectorTest extends DDSpecification {
143159 when :
144160 ConfigCollector . get(). put(' key1' , ' value1' , ConfigOrigin . DEFAULT )
145161 ConfigCollector . get(). put(' key2' , ' value2' , ConfigOrigin . ENV )
146- ConfigCollector . get(). put(' key1' , ' replaced ' , ConfigOrigin . REMOTE )
162+ ConfigCollector . get(). put(' key1' , ' value4 ' , ConfigOrigin . REMOTE )
147163 ConfigCollector . get(). put(' key3' , ' value3' , ConfigOrigin . JVM_PROP )
148164
149165 then :
150- ConfigCollector . get(). collect(). values() . toSet() == [
151- ConfigSetting . of(' key1' , ' replaced ' , ConfigOrigin . REMOTE ),
152- ConfigSetting . of(' key2' , ' value2' , ConfigOrigin . ENV ),
153- ConfigSetting . of(' key3' , ' value3' , ConfigOrigin . JVM_PROP )
154- ] as Set
166+ def collected = ConfigCollector . get(). collect()
167+ collected . get( ConfigOrigin . REMOTE ) . get( ' key1 ' ) == ConfigSetting . of(' key1' , ' value4 ' , ConfigOrigin . REMOTE )
168+ collected . get( ConfigOrigin . ENV ) . get( ' key2 ' ) == ConfigSetting . of(' key2' , ' value2' , ConfigOrigin . ENV )
169+ collected . get( ConfigOrigin . JVM_PROP ) . get( ' key3 ' ) == ConfigSetting . of(' key3' , ' value3' , ConfigOrigin . JVM_PROP )
170+ collected . get( ConfigOrigin . DEFAULT ) . get( ' key1 ' ) == ConfigSetting . of( ' key1 ' , ' value1 ' , ConfigOrigin . DEFAULT )
155171 }
156172
157173
@@ -163,16 +179,16 @@ class ConfigCollectorTest extends DDSpecification {
163179 ConfigCollector . get(). put(' DD_API_KEY' , ' sensitive data' , ConfigOrigin . ENV )
164180
165181 then :
166- ConfigCollector . get(). collect(). get(' DD_API_KEY' ). stringValue() == ' <hidden>'
182+ def collected = ConfigCollector . get(). collect()
183+ collected. get(ConfigOrigin . ENV ). get(' DD_API_KEY' ). stringValue() == ' <hidden>'
167184 }
168185
169186 def " collects common setting default values" () {
170187 when :
171- def settings = ConfigCollector . get(). collect()
188+ def defaultConfigByKey = ConfigCollector . get(). collect() . get( ConfigOrigin . DEFAULT )
172189
173190 then :
174- def setting = settings. get(key)
175-
191+ def setting = defaultConfigByKey. get(key)
176192 setting. key == key
177193 setting. stringValue() == value
178194 setting. origin == ConfigOrigin . DEFAULT
@@ -202,11 +218,10 @@ class ConfigCollectorTest extends DDSpecification {
202218 injectEnvConfig(" DD_TRACE_SAMPLE_RATE" , " 0.3" )
203219
204220 when :
205- def settings = ConfigCollector . get(). collect()
221+ def envConfigByKey = ConfigCollector . get(). collect() . get( ConfigOrigin . ENV )
206222
207223 then :
208- def setting = settings. get(key)
209-
224+ def setting = envConfigByKey. get(key)
210225 setting. key == key
211226 setting. stringValue() == value
212227 setting. origin == ConfigOrigin . ENV
0 commit comments