-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathProbeStateIntegrationTest.java
More file actions
173 lines (160 loc) · 6.95 KB
/
Copy pathProbeStateIntegrationTest.java
File metadata and controls
173 lines (160 loc) · 6.95 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package datadog.smoketest;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.datadog.debugger.agent.Configuration;
import com.datadog.debugger.agent.ProbeStatus;
import com.datadog.debugger.probe.LogProbe;
import com.datadog.debugger.sink.Snapshot;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.condition.DisabledIf;
public class ProbeStateIntegrationTest extends ServerAppDebuggerIntegrationTest {
@BeforeEach
@Override
void setup(TestInfo testInfo) throws Exception {
super.setup(testInfo);
appUrl = startAppAndAndGetUrl();
}
@Test
@DisplayName("testAddRemoveProbes")
@DisabledIf(
value = "datadog.environment.JavaVirtualMachine#isJ9",
disabledReason = "Flaky on J9 JVMs")
void testAddRemoveProbes() throws Exception {
LogProbe logProbe =
LogProbe.builder().probeId(PROBE_ID).where(TEST_APP_CLASS_NAME, FULL_METHOD_NAME).build();
addProbe(logProbe);
waitForInstrumentation(appUrl);
execute(appUrl, FULL_METHOD_NAME);
List<Snapshot> snapshots = waitForSnapshots();
assertEquals(1, snapshots.size());
assertEquals(FULL_METHOD_NAME, snapshots.get(0).getProbe().getLocation().getMethod());
setCurrentConfiguration(createConfig(Collections.emptyList())); // remove probes
waitForReTransformation(appUrl);
addProbe(logProbe);
waitForInstrumentation(appUrl);
execute(appUrl, FULL_METHOD_NAME);
snapshots = waitForSnapshots();
assertEquals(1, snapshots.size());
assertEquals(FULL_METHOD_NAME, snapshots.get(0).getProbe().getLocation().getMethod());
}
@Test
@DisplayName("testDisableEnableProbes")
@DisabledIf(
value = "datadog.environment.JavaVirtualMachine#isJ9",
disabledReason = "Flaky on J9 JVMs")
void testDisableEnableProbes() throws Exception {
LogProbe logProbe =
LogProbe.builder().probeId(PROBE_ID).where(TEST_APP_CLASS_NAME, FULL_METHOD_NAME).build();
addProbe(logProbe);
waitForInstrumentation(appUrl);
execute(appUrl, FULL_METHOD_NAME);
List<Snapshot> snapshots = waitForSnapshots();
assertEquals(1, snapshots.size());
assertEquals(FULL_METHOD_NAME, snapshots.get(0).getProbe().getLocation().getMethod());
setCurrentConfiguration(createConfig(Collections.emptyList())); // no probe
waitForReTransformation(appUrl);
addProbe(logProbe);
waitForInstrumentation(appUrl);
execute(appUrl, FULL_METHOD_NAME);
snapshots = waitForSnapshots();
assertEquals(1, snapshots.size());
assertEquals(FULL_METHOD_NAME, snapshots.get(0).getProbe().getLocation().getMethod());
}
@Test
@DisplayName("testDisableEnableProbesUsingDenyList")
@DisabledIf(
value = "datadog.environment.JavaVirtualMachine#isJ9",
disabledReason = "Flaky on J9 JVMs")
@Disabled("Not supported for config coming from RemoteConfig")
void testDisableEnableProbesUsingDenyList() throws Exception {
LogProbe logProbe =
LogProbe.builder().probeId(PROBE_ID).where(TEST_APP_CLASS_NAME, FULL_METHOD_NAME).build();
addProbe(logProbe);
waitForInstrumentation(appUrl);
execute(appUrl, FULL_METHOD_NAME);
List<Snapshot> snapshots = waitForSnapshots();
assertEquals(1, snapshots.size());
assertEquals(FULL_METHOD_NAME, snapshots.get(0).getProbe().getLocation().getMethod());
datadogAgentServer.enqueue(EMPTY_200_RESPONSE); // expect BLOCKED status
Configuration.FilterList denyList =
new Configuration.FilterList(asList("datadog.smoketest.debugger"), Collections.emptyList());
setCurrentConfiguration(createConfig(asList(logProbe), null, denyList));
waitForReTransformation(appUrl);
waitForAProbeStatus(ProbeStatus.Status.BLOCKED);
datadogAgentServer.enqueue(EMPTY_200_RESPONSE); // expect INSTALLED status
addProbe(logProbe);
// waitForInstrumentation(appUrl);
waitForReTransformation(appUrl);
waitForAProbeStatus(ProbeStatus.Status.INSTALLED);
execute(appUrl, FULL_METHOD_NAME);
snapshots = waitForSnapshots();
assertEquals(1, snapshots.size());
assertEquals(FULL_METHOD_NAME, snapshots.get(0).getProbe().getLocation().getMethod());
}
@Test
@DisplayName("testDisableEnableProbesUsingAllowList")
@DisabledIf(
value = "datadog.environment.JavaVirtualMachine#isJ9",
disabledReason = "Flaky on J9 JVMs")
@Disabled("Not supported for config coming from RemoteConfig")
void testDisableEnableProbesUsingAllowList() throws Exception {
LogProbe logProbe =
LogProbe.builder().probeId(PROBE_ID).where(TEST_APP_CLASS_NAME, FULL_METHOD_NAME).build();
addProbe(logProbe);
waitForInstrumentation(appUrl);
execute(appUrl, FULL_METHOD_NAME);
List<Snapshot> snapshots = waitForSnapshots();
assertEquals(1, snapshots.size());
assertEquals(FULL_METHOD_NAME, snapshots.get(0).getProbe().getLocation().getMethod());
datadogAgentServer.enqueue(EMPTY_200_RESPONSE); // expect BLOCKED status
Configuration.FilterList allowList =
new Configuration.FilterList(asList("datadog.not.debugger"), Collections.emptyList());
setCurrentConfiguration(createConfig(asList(logProbe), allowList, null));
waitForReTransformation(appUrl);
waitForAProbeStatus(ProbeStatus.Status.BLOCKED);
datadogAgentServer.enqueue(EMPTY_200_RESPONSE); // expect INSTALLED status
addProbe(logProbe);
// waitForInstrumentation(appUrl);
waitForReTransformation(appUrl);
waitForAProbeStatus(ProbeStatus.Status.INSTALLED);
execute(appUrl, FULL_METHOD_NAME);
snapshots = waitForSnapshots();
assertEquals(1, snapshots.size());
assertEquals(FULL_METHOD_NAME, snapshots.get(0).getProbe().getLocation().getMethod());
}
@Test
@DisplayName("testProbeStatusError")
@DisabledIf(
value = "datadog.environment.JavaVirtualMachine#isJ9",
disabledReason = "Flaky on J9 JVMs")
public void testProbeStatusError() throws Exception {
LogProbe logProbe =
LogProbe.builder()
.probeId(PROBE_ID)
.where(TEST_APP_CLASS_NAME, "unknownMethodName")
.build();
addProbe(logProbe);
AtomicBoolean received = new AtomicBoolean();
AtomicBoolean error = new AtomicBoolean();
registerProbeStatusListener(
probeStatus -> {
if (probeStatus.getDiagnostics().getStatus() == ProbeStatus.Status.RECEIVED) {
received.set(true);
}
if (probeStatus.getDiagnostics().getStatus() == ProbeStatus.Status.ERROR) {
assertEquals(
"Cannot find method datadog/smoketest/debugger/ServerDebuggerTestApplication::unknownMethodName",
probeStatus.getDiagnostics().getException().getMessage());
error.set(true);
}
});
processRequests(() -> received.get() && error.get());
}
}