-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathInProductEnablementIntegrationTest.java
More file actions
142 lines (129 loc) · 6.14 KB
/
InProductEnablementIntegrationTest.java
File metadata and controls
142 lines (129 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package datadog.smoketest;
import com.datadog.debugger.probe.LogProbe;
import datadog.trace.test.util.NonRetryable;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@NonRetryable
public class InProductEnablementIntegrationTest extends ServerAppDebuggerIntegrationTest {
private List<String> additionalJvmArgs = new ArrayList<>();
@Override
protected ProcessBuilder createProcessBuilder(Path logFilePath, String... params) {
List<String> commandParams = getDebuggerCommandParams();
// remove the dynamic instrumentation flag
commandParams.remove("-Ddd.dynamic.instrumentation.enabled=true");
commandParams.addAll(additionalJvmArgs);
return ProcessBuilderHelper.createProcessBuilder(
commandParams, logFilePath, getAppClass(), params);
}
@Test
@DisplayName("testDynamicInstrumentationEnablement")
void testDynamicInstrumentationEnablement() throws Exception {
appUrl = startAppAndAndGetUrl();
setConfigOverrides(createConfigOverrides(true, false));
LogProbe probe =
LogProbe.builder().probeId(PROBE_ID).where(TEST_APP_CLASS_NAME, TRACED_METHOD_NAME).build();
setCurrentConfiguration(createConfig(probe));
waitForFeatureStarted(appUrl, "Dynamic Instrumentation");
waitForInstrumentation(appUrl);
// disable DI
setConfigOverrides(createConfigOverrides(false, false));
waitForFeatureStopped(appUrl, "Dynamic Instrumentation");
waitForReTransformation(appUrl); // wait for retransformation of removed probe
}
@Test
@DisplayName("testDynamicInstrumentationEnablementWithLineProbe")
void testDynamicInstrumentationEnablementWithLineProbe() throws Exception {
additionalJvmArgs.add("-Ddd.third.party.excludes=datadog.smoketest");
appUrl = startAppAndAndGetUrl();
setConfigOverrides(createConfigOverrides(true, false));
LogProbe probe =
LogProbe.builder()
.probeId(LINE_PROBE_ID1)
.where("ServerDebuggerTestApplication.java", 329)
.build();
setCurrentConfiguration(createConfig(probe));
waitForFeatureStarted(appUrl, "Dynamic Instrumentation");
execute(appUrl, "topLevelMethod", "");
waitForInstrumentation(appUrl, "datadog.smoketest.debugger.TopLevel", true);
// disable DI
setConfigOverrides(createConfigOverrides(false, false));
waitForFeatureStopped(appUrl, "Dynamic Instrumentation");
waitForReTransformation(
appUrl,
"datadog.smoketest.debugger.TopLevel"); // wait for retransformation of removed probe
}
@Test
@DisplayName("testDynamicInstrumentationEnablementStaticallyDisabled")
void testDynamicInstrumentationEnablementStaticallyDisabled() throws Exception {
// explicitly disable dynamic instrumentation, preventing enablement
additionalJvmArgs.add("-Ddd.dynamic.instrumentation.enabled=false");
appUrl = startAppAndAndGetUrl();
setConfigOverrides(createConfigOverrides(true, false));
LogProbe probe =
LogProbe.builder().probeId(PROBE_ID).where(TEST_APP_CLASS_NAME, TRACED_METHOD_NAME).build();
setCurrentConfiguration(createConfig(probe));
waitForSpecificLine(appUrl, "Feature dynamic.instrumentation.enabled is explicitly disabled");
}
@Test
@DisplayName("testExceptionReplayEnablement")
void testExceptionReplayEnablement() throws Exception {
additionalJvmArgs.add("-Ddd.third.party.excludes=datadog.smoketest");
appUrl = startAppAndAndGetUrl();
setConfigOverrides(createConfigOverrides(false, true));
waitForFeatureStarted(appUrl, "Exception Replay");
execute(appUrl, TRACED_METHOD_NAME, "oops"); // instrumenting first exception
waitForInstrumentation(appUrl, SERVER_DEBUGGER_TEST_APP_CLASS, false);
// disable ER
setConfigOverrides(createConfigOverrides(false, false));
waitForFeatureStopped(appUrl, "Exception Replay");
waitForReTransformation(appUrl); // wait for retransformation of removed probes
}
// TODO test for failure of starting ER, SymDB and DI: should degrade gracefully
// TODO by not providing endpoints
@Test
@DisplayName("testExceptionReplayEnablementFailure")
void testExceptionReplayEnablementFailure() throws Exception {
additionalJvmArgs.add("-Ddd.exception.replay.enabled=true");
additionalJvmArgs.add("-Ddd.third.party.excludes=datadog.smoketest");
this.probeMockDispatcher.setDispatcher(this::noEndpointDispatch);
appUrl = startAppAndAndGetUrl();
waitForSpecificLine(appUrl, "Failed to init common component for debugger agent");
probeMockDispatcher.setDispatcher(this::datadogAgentDispatch);
setConfigOverrides(createConfigOverrides(true, true));
waitForFeatureStarted(appUrl, "Dynamic Instrumentation");
waitForFeatureStarted(appUrl, "Exception Replay");
}
private MockResponse noEndpointDispatch(RecordedRequest request) {
if (request.getPath().equals("/info")) {
// no debugger endpoints
String info =
"{\"endpoints\": [\"" + TRACE_URL_PATH + "\", \"" + LOG_UPLOAD_URL_PATH + "\"]}";
return new MockResponse().setResponseCode(200).setBody(info);
}
return datadogAgentDispatch(request);
}
private void waitForFeatureStarted(String appUrl, String feature) throws IOException {
String line = "INFO com.datadog.debugger.agent.DebuggerAgent - Started " + feature;
waitForSpecificLine(appUrl, line);
LOG.info("feature {} started", feature);
}
private void waitForFeatureStopped(String appUrl, String feature) throws IOException {
String line = "INFO com.datadog.debugger.agent.DebuggerAgent - Stopping " + feature;
waitForSpecificLine(appUrl, line);
LOG.info("feature {} stopped", feature);
}
private static ConfigOverrides createConfigOverrides(
boolean dynamicInstrumentationEnabled, boolean exceptionReplayEnabled) {
ConfigOverrides config = new ConfigOverrides();
config.libConfig = new LibConfig();
config.libConfig.dynamicInstrumentationEnabled = dynamicInstrumentationEnabled;
config.libConfig.exceptionReplayEnabled = exceptionReplayEnabled;
return config;
}
}