Skip to content

Commit 479d730

Browse files
committed
handle old 3.x agent
1 parent 4f9a614 commit 479d730

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtension.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public class SmokeTestExtension
7575
private static final File appFile = new File(System.getProperty("ai.smoke-test.test-app-file"));
7676

7777
// TODO (trask) make private and expose methods on AiSmokeTest(?)
78-
protected final MockedAppInsightsIngestionServer mockedIngestion =
79-
new MockedAppInsightsIngestionServer();
78+
protected final MockedAppInsightsIngestionServer mockedIngestion;
8079

8180
protected final MockedOtlpIngestionServer mockedOtlpIngestion = new MockedOtlpIngestionServer();
8281

@@ -167,6 +166,8 @@ public static SmokeTestExtensionBuilder builder() {
167166
this.jvmArgs = jvmArgs;
168167
this.useDefaultHttpPort = useDefaultHttpPort;
169168
this.useOtlpEndpoint = useOtlpEndpoint;
169+
170+
mockedIngestion = new MockedAppInsightsIngestionServer(useOld3xAgent);
170171
}
171172

172173
private static String getProfilerEndpoint(ProfilerState profilerState) {
@@ -281,16 +282,19 @@ protected String getAppContext() {
281282

282283
private void clearOutAnyInitLogs() throws Exception {
283284
if (!skipHealthCheck) {
284-
await().until(mockedIngestion::isReceivingLiveMetrics);
285+
if (!useOld3xAgent) {
286+
await().until(mockedIngestion::isReceivingLiveMetrics);
287+
}
285288
String contextRootUrl = getBaseUrl() + "/";
286289
HttpHelper.getResponseCodeEnsuringSampled(contextRootUrl);
287290
waitForHealthCheckTelemetry(contextRootUrl);
288-
await()
289-
.untilAsserted(
290-
() ->
291-
assertThat(mockedIngestion.getLiveMetrics().getRequestCount(contextRootUrl))
292-
.isEqualTo(1));
293-
291+
if (!useOld3xAgent) {
292+
await()
293+
.untilAsserted(
294+
() ->
295+
assertThat(mockedIngestion.getLiveMetrics().getRequestCount(contextRootUrl))
296+
.isEqualTo(1));
297+
}
294298
System.out.println("Clearing any RequestData from health check.");
295299
mockedIngestion.resetData();
296300
}

smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/fakeingestion/MockedAppInsightsIngestionServer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public class MockedAppInsightsIngestionServer {
2727
private final MockedQuickPulseServlet quickPulseServlet;
2828
private final Server server;
2929

30-
public MockedAppInsightsIngestionServer() {
30+
public MockedAppInsightsIngestionServer(boolean usingOld3xAgent) {
3131
server = new Server(DEFAULT_PORT);
3232
ServletHandler handler = new ServletHandler();
3333
server.setHandler(handler);
3434

3535
servlet = new MockedAppInsightsIngestionServlet();
3636
profilerSettingsServlet = new MockedProfilerSettingsServlet();
37-
quickPulseServlet = new MockedQuickPulseServlet();
37+
quickPulseServlet = new MockedQuickPulseServlet(usingOld3xAgent);
3838

3939
handler.addServletWithMapping(new ServletHolder(profilerSettingsServlet), "/profiler/*");
4040
handler.addServletWithMapping(new ServletHolder(quickPulseServlet), "/QuickPulseService.svc/*");
@@ -295,7 +295,7 @@ public LiveMetricsVerifier getLiveMetrics() {
295295

296296
@SuppressWarnings("SystemOut")
297297
public static void main(String[] args) throws Exception {
298-
MockedAppInsightsIngestionServer i = new MockedAppInsightsIngestionServer();
298+
MockedAppInsightsIngestionServer i = new MockedAppInsightsIngestionServer(false);
299299
System.out.println("Starting mocked ingestion on port " + DEFAULT_PORT);
300300
Runtime.getRuntime()
301301
.addShutdownHook(

smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/fakeingestion/MockedQuickPulseServlet.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
public class MockedQuickPulseServlet extends HttpServlet {
1515

16+
private final boolean usingOld3xAgent;
1617
private final AtomicBoolean pingReceived = new AtomicBoolean();
1718
private final AtomicBoolean postReceived = new AtomicBoolean();
1819
private volatile LiveMetricsVerifier verifier = new LiveMetricsVerifier();
@@ -23,7 +24,9 @@ public class MockedQuickPulseServlet extends HttpServlet {
2324

2425
private volatile boolean loggingEnabled;
2526

26-
public MockedQuickPulseServlet() {}
27+
public MockedQuickPulseServlet(boolean usingOld3xAgent) {
28+
this.usingOld3xAgent = usingOld3xAgent;
29+
}
2730

2831
@SuppressWarnings("SystemOut")
2932
private void logit(String message) {
@@ -34,6 +37,10 @@ private void logit(String message) {
3437

3538
@Override
3639
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
40+
if (usingOld3xAgent) {
41+
// the old 3.x agent doesn't conform to the expectations of this mock server
42+
return;
43+
}
3744
Readable reader = req.getReader();
3845
StringWriter sw = new StringWriter();
3946
CharStreams.copy(reader, sw);

0 commit comments

Comments
 (0)