1
1
package datadog.smoketest
2
2
3
3
import datadog.smoketest.dynamicconfig.ServiceMappingApplication
4
-
5
4
import static java.util.concurrent.TimeUnit.SECONDS
6
5
7
6
class DynamicServiceMappingSmokeTest extends AbstractSmokeTest {
@@ -21,11 +20,13 @@ class DynamicServiceMappingSmokeTest extends AbstractSmokeTest {
21
20
22
21
ProcessBuilder processBuilder = new ProcessBuilder (command)
23
22
processBuilder. directory(new File (buildDirectory))
23
+ return processBuilder
24
24
}
25
25
26
- def " Updated service mapping observed" () {
27
- when :
28
- def newConfig = """
26
+ @Override
27
+ def setup () {
28
+ // Set the initial remote configuration before the application starts
29
+ def initialConfig = """
29
30
{
30
31
"lib_config": {
31
32
"tracing_service_mapping": [{
@@ -35,11 +36,64 @@ class DynamicServiceMappingSmokeTest extends AbstractSmokeTest {
35
36
}
36
37
}
37
38
""" as String
39
+ setRemoteConfig(" datadog/2/APM_TRACING/config_overrides/config" , initialConfig)
40
+ }
38
41
39
- setRemoteConfig(" datadog/2/APM_TRACING/config_overrides/config" , newConfig)
42
+ def " Service mapping updates are observed and reported via telemetry" () {
43
+ when :
44
+ // Wait for the app to start and apply the initial mapping
45
+ assert ! testedProcess. waitFor(5 , SECONDS ) // app should still be running
46
+
47
+ // Set the updated mapping after startup
48
+ def updatedConfig = """
49
+ {
50
+ "lib_config": {
51
+ "tracing_service_mapping": [{
52
+ "from_key": "${ ServiceMappingApplication.ORIGINAL_SERVICE_NAME} ",
53
+ "to_name": "baz"
54
+ }]
55
+ }
56
+ }
57
+ """ as String
58
+ setRemoteConfig(" datadog/2/APM_TRACING/config_overrides/config" , updatedConfig)
40
59
41
60
then :
61
+ // Wait for the process to exit (should be 0 if both mappings observed)
42
62
assert testedProcess. waitFor(TIMEOUT_SECS , SECONDS )
43
63
assert testedProcess. exitValue() == 0
64
+
65
+ // Debug: Print all received telemetry messages
66
+ println " === All received telemetry messages ==="
67
+ telemetryFlatMessages. each { msg ->
68
+ println " Telemetry: ${ msg.request_type} - ${ msg.payload?.configuration?.size() ?: 0} configs"
69
+ if (msg. payload?. configuration) {
70
+ msg. payload. configuration. each { config ->
71
+ if (config. name?. contains(" service" ) || config. name?. contains(" mapping" )) {
72
+ println " Config: ${ config.name} = ${ config.value} (origin: ${ config.origin} )"
73
+ }
74
+ }
75
+ }
76
+ }
77
+ println " === End telemetry messages ==="
78
+
79
+ // Check initial mapping in app-started telemetry
80
+ def startedTelemetry = telemetryFlatMessages. find { it. request_type == " app-started" }
81
+ assert startedTelemetry != null : " No app-started telemetry message found. Received: ${ telemetryFlatMessages.collect { it.request_type }} "
82
+ def startedConfigs = startedTelemetry. payload. configuration
83
+ def initialMapping = startedConfigs. find {
84
+ it. name == " service_mapping" && it. origin == " remote_config"
85
+ }
86
+ initialMapping != null
87
+ initialMapping. value == " ${ ServiceMappingApplication.ORIGINAL_SERVICE_NAME} :${ ServiceMappingApplication.MAPPED_SERVICE_NAME} "
88
+
89
+ // Check updated mapping in app-client-configuration-change telemetry
90
+ def changeTelemetry = telemetryFlatMessages. find { it. request_type == " app-client-configuration-change" }
91
+ assert changeTelemetry != null : " No app-client-configuration-change telemetry message found. Received: ${ telemetryFlatMessages.collect { it.request_type }} "
92
+ def changeConfigs = changeTelemetry. payload. configuration
93
+ def updatedMapping = changeConfigs. find {
94
+ it. name == " service_mapping" && it. origin == " remote_config"
95
+ }
96
+ updatedMapping != null
97
+ updatedMapping. value == " ${ ServiceMappingApplication.ORIGINAL_SERVICE_NAME} :baz"
44
98
}
45
99
}
0 commit comments