11package  datadog.smoketest 
22
33import  datadog.smoketest.dynamicconfig.ServiceMappingApplication 
4- 
54import static  java.util.concurrent.TimeUnit.SECONDS 
65
76class  DynamicServiceMappingSmokeTest  extends  AbstractSmokeTest  {
@@ -21,11 +20,13 @@ class DynamicServiceMappingSmokeTest extends AbstractSmokeTest {
2120
2221    ProcessBuilder  processBuilder =  new  ProcessBuilder (command)
2322    processBuilder. directory(new  File (buildDirectory))
23+     return  processBuilder
2424  }
2525
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 =  """ 
2930        { 
3031          "lib_config": { 
3132            "tracing_service_mapping": [{ 
@@ -35,11 +36,64 @@ class DynamicServiceMappingSmokeTest extends AbstractSmokeTest {
3536          } 
3637        } 
3738    """   as  String 
39+     setRemoteConfig(" datadog/2/APM_TRACING/config_overrides/config" 
40+   }
3841
39-     setRemoteConfig(" datadog/2/APM_TRACING/config_overrides/config" 
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" 
4059
4160    then :
61+     //  Wait for the process to exit (should be 0 if both mappings observed)
4262    assert  testedProcess. waitFor(TIMEOUT_SECS , SECONDS )
4363    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} " 
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} ${ 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} " 
4498  }
4599}
0 commit comments