From 98c0fe32fa8da7a7b5f0c8108c05312c59fa6148 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 3 Sep 2019 22:04:14 -0700 Subject: [PATCH 1/5] Add operation id validation --- .../smoketest/TraceLog4j1_2Test.java | 60 ++++++++++++++----- .../smoketest/TraceLog4j2Test.java | 58 ++++++++++++++---- .../smoketest/TraceLogBackTest.java | 54 +++++++++++++---- 3 files changed, 133 insertions(+), 39 deletions(-) diff --git a/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java b/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java index 1b38699229b..532ac47b771 100644 --- a/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java +++ b/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java @@ -1,12 +1,19 @@ package com.microsoft.applicationinsights.smoketest; +import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import java.util.List; +import com.microsoft.applicationinsights.internal.schemav2.Data; +import com.microsoft.applicationinsights.internal.schemav2.Envelope; import com.microsoft.applicationinsights.internal.schemav2.ExceptionData; import com.microsoft.applicationinsights.internal.schemav2.ExceptionDetails; import com.microsoft.applicationinsights.internal.schemav2.MessageData; +import com.microsoft.applicationinsights.internal.schemav2.RemoteDependencyData; +import com.microsoft.applicationinsights.internal.schemav2.RequestData; import com.microsoft.applicationinsights.internal.schemav2.SeverityLevel; import org.junit.Test; @@ -15,43 +22,68 @@ public class TraceLog4j1_2Test extends AiSmokeTest { @Test @TargetUri("/traceLog4j1_2") - public void testTraceLog4j1_2() { + public void testTraceLog4j1_2() throws Exception { + List rdList = mockedIngestion.waitForItems("RequestData", 1); + List mdList = mockedIngestion.waitForItems("MessageData", 3); - assertEquals(3, mockedIngestion.getCountForType("MessageData")); + Envelope rdEnvelope = rdList.get(0); + Envelope mdEnvelope1 = mdList.get(0); + Envelope mdEnvelope2 = mdList.get(1); + Envelope mdEnvelope3 = mdList.get(2); + + MessageData md1 = (MessageData) ((Data) mdEnvelope1.getData()).getBaseData(); + MessageData md2 = (MessageData) ((Data) mdEnvelope2.getData()).getBaseData(); + MessageData md3 = (MessageData) ((Data) mdEnvelope3.getData()).getBaseData(); - MessageData md1 = getTelemetryDataForType(0, "MessageData"); assertEquals("This is log4j1.2 warn.", md1.getMessage()); assertEquals(SeverityLevel.Warning, md1.getSeverityLevel()); assertEquals("Logger", md1.getProperties().get("SourceType")); assertEquals("WARN", md1.getProperties().get("LoggingLevel")); + assertSameOperationId(mdEnvelope1, rdEnvelope); - - MessageData md2 = getTelemetryDataForType(1, "MessageData"); assertEquals("This is log4j1.2 error.", md2.getMessage()); assertEquals(SeverityLevel.Error, md2.getSeverityLevel()); assertEquals("Logger", md2.getProperties().get("SourceType")); assertEquals("ERROR", md2.getProperties().get("LoggingLevel")); + assertSameOperationId(mdEnvelope2, rdEnvelope); - MessageData md3 = getTelemetryDataForType(2, "MessageData"); assertEquals("This is log4j1.2 fatal.", md3.getMessage()); assertEquals(SeverityLevel.Critical, md3.getSeverityLevel()); assertEquals("Logger", md3.getProperties().get("SourceType")); assertEquals("FATAL", md3.getProperties().get("LoggingLevel")); + assertSameOperationId(mdEnvelope3, rdEnvelope); } @Test @TargetUri("traceLog4j1_2WithException") - public void testTraceLog4j1_2WithExeption() { - assertEquals(1, mockedIngestion.getCountForType("ExceptionData")); + public void testTraceLog4j1_2WithExeption() throws Exception { + List rdList = mockedIngestion.waitForItems("RequestData", 1); + List edList = mockedIngestion.waitForItems("ExceptionData", 1); + + Envelope rdEnvelope = rdList.get(0); + Envelope edEnvelope = edList.get(0); + + ExceptionData ed = (ExceptionData) ((Data) edEnvelope.getData()).getBaseData(); - ExceptionData ed1 = getTelemetryDataForType(0, "ExceptionData"); - List details = ed1.getExceptions(); + List details = ed.getExceptions(); ExceptionDetails ex = details.get(0); assertEquals("Fake Exception", ex.getMessage()); - assertEquals(SeverityLevel.Error, ed1.getSeverityLevel()); - assertEquals("This is an exception!", ed1.getProperties().get("Logger Message")); - assertEquals("Logger", ed1.getProperties().get("SourceType")); - assertEquals("ERROR", ed1.getProperties().get("LoggingLevel")); + assertEquals(SeverityLevel.Error, ed.getSeverityLevel()); + assertEquals("This is an exception!", ed.getProperties().get("Logger Message")); + assertEquals("Logger", ed.getProperties().get("SourceType")); + assertEquals("ERROR", ed.getProperties().get("LoggingLevel")); + assertSameOperationId(edEnvelope, rdEnvelope); + } + + private static void assertSameOperationId(Envelope rdEnvelope, Envelope rddEnvelope) { + String operationId = rdEnvelope.getTags().get("ai.operation.id"); + String operationParentId = rdEnvelope.getTags().get("ai.operation.parentId"); + + assertNotNull(operationId); + assertNotNull(operationParentId); + + assertEquals(operationId, rddEnvelope.getTags().get("ai.operation.id")); + assertEquals(operationParentId, rddEnvelope.getTags().get("ai.operation.parentId")); } } \ No newline at end of file diff --git a/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java b/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java index e7d2c53b5ba..900c3a73b72 100644 --- a/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java +++ b/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java @@ -1,9 +1,14 @@ package com.microsoft.applicationinsights.smoketest; +import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import java.util.List; +import com.microsoft.applicationinsights.internal.schemav2.Data; +import com.microsoft.applicationinsights.internal.schemav2.Envelope; import com.microsoft.applicationinsights.internal.schemav2.ExceptionData; import com.microsoft.applicationinsights.internal.schemav2.ExceptionDetails; import com.microsoft.applicationinsights.internal.schemav2.MessageData; @@ -16,41 +21,68 @@ public class TraceLog4j2Test extends AiSmokeTest { @Test @TargetUri("/traceLog4j2") - public void testTraceLog4j2() { - assertEquals(3, mockedIngestion.getCountForType("MessageData")); + public void testTraceLog4j2() throws Exception { + List rdList = mockedIngestion.waitForItems("RequestData", 1); + List mdList = mockedIngestion.waitForItems("MessageData", 3); + + Envelope rdEnvelope = rdList.get(0); + Envelope mdEnvelope1 = mdList.get(0); + Envelope mdEnvelope2 = mdList.get(1); + Envelope mdEnvelope3 = mdList.get(2); + + MessageData md1 = (MessageData) ((Data) mdEnvelope1.getData()).getBaseData(); + MessageData md2 = (MessageData) ((Data) mdEnvelope2.getData()).getBaseData(); + MessageData md3 = (MessageData) ((Data) mdEnvelope3.getData()).getBaseData(); - MessageData md1 = getTelemetryDataForType(0, "MessageData"); assertEquals("This is log4j2 warn.", md1.getMessage()); assertEquals(SeverityLevel.Warning, md1.getSeverityLevel()); assertEquals("Logger", md1.getProperties().get("SourceType")); assertEquals("WARN", md1.getProperties().get("LoggingLevel")); + assertSameOperationId(mdEnvelope1, rdEnvelope); - MessageData md2 = getTelemetryDataForType(1, "MessageData"); assertEquals("This is log4j2 error.", md2.getMessage()); assertEquals(SeverityLevel.Error, md2.getSeverityLevel()); assertEquals("Logger", md2.getProperties().get("SourceType")); assertEquals("ERROR", md2.getProperties().get("LoggingLevel")); + assertSameOperationId(mdEnvelope2, rdEnvelope); - MessageData md3 = getTelemetryDataForType(2, "MessageData"); assertEquals("This is log4j2 fatal.", md3.getMessage()); assertEquals(SeverityLevel.Critical, md3.getSeverityLevel()); assertEquals("Logger", md3.getProperties().get("SourceType")); assertEquals("FATAL", md3.getProperties().get("LoggingLevel")); + assertSameOperationId(mdEnvelope3, rdEnvelope); } @Test @TargetUri("/traceLog4j2WithException") - public void testTraceLog4j2WithException() { - assertEquals(1, mockedIngestion.getCountForType("ExceptionData")); + public void testTraceLog4j2WithException() throws Exception { + List rdList = mockedIngestion.waitForItems("RequestData", 1); + List edList = mockedIngestion.waitForItems("ExceptionData", 1); + + Envelope rdEnvelope = rdList.get(0); + Envelope edEnvelope = edList.get(0); + + ExceptionData ed = (ExceptionData) ((Data) edEnvelope.getData()).getBaseData(); - ExceptionData ed1 = getTelemetryDataForType(0, "ExceptionData"); - List details = ed1.getExceptions(); + List details = ed.getExceptions(); ExceptionDetails ex = details.get(0); assertEquals("Fake Exception", ex.getMessage()); - assertEquals(SeverityLevel.Error, ed1.getSeverityLevel()); - assertEquals("This is an exception!", ed1.getProperties().get("Logger Message")); - assertEquals("Logger", ed1.getProperties().get("SourceType")); - assertEquals("ERROR", ed1.getProperties().get("LoggingLevel")); + assertEquals(SeverityLevel.Error, ed.getSeverityLevel()); + assertEquals("This is an exception!", ed.getProperties().get("Logger Message")); + assertEquals("Logger", ed.getProperties().get("SourceType")); + assertEquals("ERROR", ed.getProperties().get("LoggingLevel")); + assertSameOperationId(edEnvelope, rdEnvelope); + } + + private static void assertSameOperationId(Envelope rdEnvelope, Envelope rddEnvelope) { + String operationId = rdEnvelope.getTags().get("ai.operation.id"); + String operationParentId = rdEnvelope.getTags().get("ai.operation.parentId"); + + assertNotNull(operationId); + assertNotNull(operationParentId); + + assertEquals(operationId, rddEnvelope.getTags().get("ai.operation.id")); + assertEquals(operationParentId, rddEnvelope.getTags().get("ai.operation.parentId")); } } \ No newline at end of file diff --git a/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java b/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java index 485336f0167..31b0098d499 100644 --- a/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java +++ b/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java @@ -1,9 +1,14 @@ package com.microsoft.applicationinsights.smoketest; +import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import java.util.List; +import com.microsoft.applicationinsights.internal.schemav2.Data; +import com.microsoft.applicationinsights.internal.schemav2.Envelope; import com.microsoft.applicationinsights.internal.schemav2.ExceptionData; import com.microsoft.applicationinsights.internal.schemav2.ExceptionDetails; import com.microsoft.applicationinsights.internal.schemav2.MessageData; @@ -24,35 +29,60 @@ public void skipJbosseap6AndJbosseap7Image() { @Test @TargetUri("/traceLogBack") - public void testTraceLogBack() { - assertEquals(2, mockedIngestion.getCountForType("MessageData")); + public void testTraceLogBack() throws Exception { + List rdList = mockedIngestion.waitForItems("RequestData", 1); + List mdList = mockedIngestion.waitForItems("MessageData", 2); + + Envelope rdEnvelope = rdList.get(0); + Envelope mdEnvelope1 = mdList.get(0); + Envelope mdEnvelope2 = mdList.get(1); + + MessageData md1 = (MessageData) ((Data) mdEnvelope1.getData()).getBaseData(); + MessageData md2 = (MessageData) ((Data) mdEnvelope2.getData()).getBaseData(); - MessageData md1 = getTelemetryDataForType(0, "MessageData"); assertEquals("This is logback warn.", md1.getMessage()); assertEquals(SeverityLevel.Warning, md1.getSeverityLevel()); assertEquals("Logger", md1.getProperties().get("SourceType")); assertEquals("WARN", md1.getProperties().get("LoggingLevel")); + assertSameOperationId(mdEnvelope1, rdEnvelope); - MessageData md2 = getTelemetryDataForType(1, "MessageData"); assertEquals("This is logback error.", md2.getMessage()); assertEquals(SeverityLevel.Error, md2.getSeverityLevel()); assertEquals("Logger", md2.getProperties().get("SourceType")); assertEquals("ERROR", md2.getProperties().get("LoggingLevel")); + assertSameOperationId(mdEnvelope2, rdEnvelope); } @Test @TargetUri("traceLogBackWithException") - public void testTraceLogBackWithExeption() { - assertEquals(1, mockedIngestion.getCountForType("ExceptionData")); + public void testTraceLogBackWithExeption() throws Exception { + List rdList = mockedIngestion.waitForItems("RequestData", 1); + List edList = mockedIngestion.waitForItems("ExceptionData", 1); + + Envelope rdEnvelope = rdList.get(0); + Envelope edEnvelope = edList.get(0); + + ExceptionData ed = (ExceptionData) ((Data) edEnvelope.getData()).getBaseData(); - ExceptionData ed1 = getTelemetryDataForType(0, "ExceptionData"); - List details = ed1.getExceptions(); + List details = ed.getExceptions(); ExceptionDetails ex = details.get(0); assertEquals("Fake Exception", ex.getMessage()); - assertEquals(SeverityLevel.Error, ed1.getSeverityLevel()); - assertEquals("This is an exception!", ed1.getProperties().get("Logger Message")); - assertEquals("Logger", ed1.getProperties().get("SourceType")); - assertEquals("ERROR", ed1.getProperties().get("LoggingLevel")); + assertEquals(SeverityLevel.Error, ed.getSeverityLevel()); + assertEquals("This is an exception!", ed.getProperties().get("Logger Message")); + assertEquals("Logger", ed.getProperties().get("SourceType")); + assertEquals("ERROR", ed.getProperties().get("LoggingLevel")); + assertSameOperationId(edEnvelope, rdEnvelope); + } + + private static void assertSameOperationId(Envelope rdEnvelope, Envelope rddEnvelope) { + String operationId = rdEnvelope.getTags().get("ai.operation.id"); + String operationParentId = rdEnvelope.getTags().get("ai.operation.parentId"); + + assertNotNull(operationId); + assertNotNull(operationParentId); + + assertEquals(operationId, rddEnvelope.getTags().get("ai.operation.id")); + assertEquals(operationParentId, rddEnvelope.getTags().get("ai.operation.parentId")); } } \ No newline at end of file From 9d67d3e34072b2b444c875002afadd8ae48f8249 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 3 Sep 2019 22:06:11 -0700 Subject: [PATCH 2/5] Remove commented out code --- .../AutoPerfCounters/src/main/resources/ApplicationInsights.xml | 1 - .../CachingCalculator/src/main/resources/ApplicationInsights.xml | 1 - .../CoreAndFilter/src/main/resources/ApplicationInsights.xml | 1 - .../FixedRateSampling/src/main/resources/ApplicationInsights.xml | 1 - .../HeartBeat/src/main/resources/ApplicationInsights.xml | 1 - .../TraceLog4j1_2/src/main/resources/ApplicationInsights.xml | 1 - .../src/main/resources/ApplicationInsights.xml | 1 - .../TraceLogBack/src/main/resources/ApplicationInsights.xml | 1 - .../src/main/resources/ApplicationInsights.xml | 1 - 9 files changed, 9 deletions(-) diff --git a/test/smoke/testApps/AutoPerfCounters/src/main/resources/ApplicationInsights.xml b/test/smoke/testApps/AutoPerfCounters/src/main/resources/ApplicationInsights.xml index f5eb33e5c50..69996045c9e 100644 --- a/test/smoke/testApps/AutoPerfCounters/src/main/resources/ApplicationInsights.xml +++ b/test/smoke/testApps/AutoPerfCounters/src/main/resources/ApplicationInsights.xml @@ -32,7 +32,6 @@ - http://fakeingestion:60606/v2/track true 1 diff --git a/test/smoke/testApps/CachingCalculator/src/main/resources/ApplicationInsights.xml b/test/smoke/testApps/CachingCalculator/src/main/resources/ApplicationInsights.xml index 48f7ffd39af..b55cd9da32c 100644 --- a/test/smoke/testApps/CachingCalculator/src/main/resources/ApplicationInsights.xml +++ b/test/smoke/testApps/CachingCalculator/src/main/resources/ApplicationInsights.xml @@ -33,7 +33,6 @@ - http://fakeingestion:60606/v2/track true 1 diff --git a/test/smoke/testApps/CoreAndFilter/src/main/resources/ApplicationInsights.xml b/test/smoke/testApps/CoreAndFilter/src/main/resources/ApplicationInsights.xml index 9cf182cec8b..4e3f798175e 100644 --- a/test/smoke/testApps/CoreAndFilter/src/main/resources/ApplicationInsights.xml +++ b/test/smoke/testApps/CoreAndFilter/src/main/resources/ApplicationInsights.xml @@ -33,7 +33,6 @@ - http://fakeingestion:60606/v2/track true 1 diff --git a/test/smoke/testApps/FixedRateSampling/src/main/resources/ApplicationInsights.xml b/test/smoke/testApps/FixedRateSampling/src/main/resources/ApplicationInsights.xml index 554f168515a..0e87455e5ab 100644 --- a/test/smoke/testApps/FixedRateSampling/src/main/resources/ApplicationInsights.xml +++ b/test/smoke/testApps/FixedRateSampling/src/main/resources/ApplicationInsights.xml @@ -32,7 +32,6 @@ - http://fakeingestion:60606/v2/track true 1 diff --git a/test/smoke/testApps/HeartBeat/src/main/resources/ApplicationInsights.xml b/test/smoke/testApps/HeartBeat/src/main/resources/ApplicationInsights.xml index fbba77f245e..52c4149996e 100644 --- a/test/smoke/testApps/HeartBeat/src/main/resources/ApplicationInsights.xml +++ b/test/smoke/testApps/HeartBeat/src/main/resources/ApplicationInsights.xml @@ -31,7 +31,6 @@ - http://fakeingestion:60606/v2/track true 1 diff --git a/test/smoke/testApps/TraceLog4j1_2/src/main/resources/ApplicationInsights.xml b/test/smoke/testApps/TraceLog4j1_2/src/main/resources/ApplicationInsights.xml index 50fc3800ef2..9a98357181f 100644 --- a/test/smoke/testApps/TraceLog4j1_2/src/main/resources/ApplicationInsights.xml +++ b/test/smoke/testApps/TraceLog4j1_2/src/main/resources/ApplicationInsights.xml @@ -28,7 +28,6 @@ - http://fakeingestion:60606/v2/track true 1 diff --git a/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/main/resources/ApplicationInsights.xml b/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/main/resources/ApplicationInsights.xml index 22cb692dcb6..965eb5d3a30 100644 --- a/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/main/resources/ApplicationInsights.xml +++ b/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/main/resources/ApplicationInsights.xml @@ -28,7 +28,6 @@ - http://fakeingestion:60606/v2/track diff --git a/test/smoke/testApps/TraceLogBack/src/main/resources/ApplicationInsights.xml b/test/smoke/testApps/TraceLogBack/src/main/resources/ApplicationInsights.xml index 83ba3cfbf43..b8adf68352d 100644 --- a/test/smoke/testApps/TraceLogBack/src/main/resources/ApplicationInsights.xml +++ b/test/smoke/testApps/TraceLogBack/src/main/resources/ApplicationInsights.xml @@ -27,7 +27,6 @@ - http://fakeingestion:60606/v2/track true 1 diff --git a/test/smoke/testApps/TraceLogBackUsingAgent/src/main/resources/ApplicationInsights.xml b/test/smoke/testApps/TraceLogBackUsingAgent/src/main/resources/ApplicationInsights.xml index ee5405bd399..7f0e340e2de 100644 --- a/test/smoke/testApps/TraceLogBackUsingAgent/src/main/resources/ApplicationInsights.xml +++ b/test/smoke/testApps/TraceLogBackUsingAgent/src/main/resources/ApplicationInsights.xml @@ -27,7 +27,6 @@ - http://fakeingestion:60606/v2/track From 861f0be9a4a07294ead2d71060b2c0696554ab4a Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 3 Sep 2019 22:09:01 -0700 Subject: [PATCH 3/5] Remove unused imports --- .../smoketest/SampleTestWithDependencyContainer.java | 1 - .../microsoft/ajl/simplecalc/SimpleTrackPageViewServlet.java | 2 -- .../microsoft/ajl/simplecalc/SlowRequestCpuBoundServlet.java | 3 --- .../applicationinsights/smoketest/CoreAndFilterTests.java | 1 - .../smoketestapp/CustomInstrumentationTest.java | 2 -- .../applicationinsights/smoketest/TraceLog4j1_2Test.java | 4 ---- .../applicationinsights/smoketest/TraceLog4j2Test.java | 2 -- .../applicationinsights/smoketest/TraceLogBackTest.java | 1 - .../applicationinsights/smoketest/TraceLogBackTest.java | 2 -- 9 files changed, 18 deletions(-) diff --git a/test/smoke/testApps/CachingCalculator/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SampleTestWithDependencyContainer.java b/test/smoke/testApps/CachingCalculator/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SampleTestWithDependencyContainer.java index bb10f42ef99..b129947c92f 100644 --- a/test/smoke/testApps/CachingCalculator/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SampleTestWithDependencyContainer.java +++ b/test/smoke/testApps/CachingCalculator/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SampleTestWithDependencyContainer.java @@ -5,7 +5,6 @@ import com.microsoft.applicationinsights.internal.schemav2.Data; import com.microsoft.applicationinsights.internal.schemav2.Envelope; import com.microsoft.applicationinsights.internal.schemav2.RemoteDependencyData; -import com.microsoft.applicationinsights.internal.schemav2.RequestData; import org.junit.*; import static org.hamcrest.Matchers.hasSize; diff --git a/test/smoke/testApps/CoreAndFilter/src/main/java/com/microsoft/ajl/simplecalc/SimpleTrackPageViewServlet.java b/test/smoke/testApps/CoreAndFilter/src/main/java/com/microsoft/ajl/simplecalc/SimpleTrackPageViewServlet.java index e9681af2c74..916d483b6c5 100644 --- a/test/smoke/testApps/CoreAndFilter/src/main/java/com/microsoft/ajl/simplecalc/SimpleTrackPageViewServlet.java +++ b/test/smoke/testApps/CoreAndFilter/src/main/java/com/microsoft/ajl/simplecalc/SimpleTrackPageViewServlet.java @@ -1,8 +1,6 @@ package com.microsoft.ajl.simplecalc; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; diff --git a/test/smoke/testApps/CoreAndFilter/src/main/java/com/microsoft/ajl/simplecalc/SlowRequestCpuBoundServlet.java b/test/smoke/testApps/CoreAndFilter/src/main/java/com/microsoft/ajl/simplecalc/SlowRequestCpuBoundServlet.java index 27b800e929b..9dae73686db 100644 --- a/test/smoke/testApps/CoreAndFilter/src/main/java/com/microsoft/ajl/simplecalc/SlowRequestCpuBoundServlet.java +++ b/test/smoke/testApps/CoreAndFilter/src/main/java/com/microsoft/ajl/simplecalc/SlowRequestCpuBoundServlet.java @@ -1,9 +1,6 @@ package com.microsoft.ajl.simplecalc; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import org.apache.commons.lang3.StringUtils; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; diff --git a/test/smoke/testApps/CoreAndFilter/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java b/test/smoke/testApps/CoreAndFilter/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java index 1d1508c44b5..536f400a25a 100644 --- a/test/smoke/testApps/CoreAndFilter/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java +++ b/test/smoke/testApps/CoreAndFilter/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java @@ -21,7 +21,6 @@ import com.microsoft.applicationinsights.smoketest.matchers.PageViewDataMatchers; import com.microsoft.applicationinsights.smoketest.matchers.TraceDataMatchers; import com.microsoft.applicationinsights.telemetry.Duration; -import org.junit.Ignore; import org.junit.Test; import static com.microsoft.applicationinsights.smoketest.matchers.ExceptionDataMatchers.ExceptionDetailsMatchers.withMessage; diff --git a/test/smoke/testApps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketestapp/CustomInstrumentationTest.java b/test/smoke/testApps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketestapp/CustomInstrumentationTest.java index cc6fad87832..f31c5cf65a6 100644 --- a/test/smoke/testApps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketestapp/CustomInstrumentationTest.java +++ b/test/smoke/testApps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketestapp/CustomInstrumentationTest.java @@ -13,10 +13,8 @@ import com.microsoft.applicationinsights.smoketest.UseAgent; import org.junit.Test; -import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @UseAgent("CustomInstrumentation") diff --git a/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java b/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java index 532ac47b771..64d4310f727 100644 --- a/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java +++ b/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java @@ -1,9 +1,7 @@ package com.microsoft.applicationinsights.smoketest; -import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import java.util.List; @@ -12,8 +10,6 @@ import com.microsoft.applicationinsights.internal.schemav2.ExceptionData; import com.microsoft.applicationinsights.internal.schemav2.ExceptionDetails; import com.microsoft.applicationinsights.internal.schemav2.MessageData; -import com.microsoft.applicationinsights.internal.schemav2.RemoteDependencyData; -import com.microsoft.applicationinsights.internal.schemav2.RequestData; import com.microsoft.applicationinsights.internal.schemav2.SeverityLevel; import org.junit.Test; diff --git a/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java b/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java index 900c3a73b72..d5aaee126b5 100644 --- a/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java +++ b/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java @@ -1,9 +1,7 @@ package com.microsoft.applicationinsights.smoketest; -import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import java.util.List; diff --git a/test/smoke/testApps/TraceLogBack/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java b/test/smoke/testApps/TraceLogBack/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java index b1345e623ba..90992da2b5f 100644 --- a/test/smoke/testApps/TraceLogBack/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java +++ b/test/smoke/testApps/TraceLogBack/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java @@ -5,7 +5,6 @@ import java.util.Comparator; import java.util.List; -import com.microsoft.applicationinsights.internal.schemav2.Envelope; import com.microsoft.applicationinsights.internal.schemav2.ExceptionData; import com.microsoft.applicationinsights.internal.schemav2.ExceptionDetails; import com.microsoft.applicationinsights.internal.schemav2.MessageData; diff --git a/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java b/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java index 31b0098d499..bfa58f683b9 100644 --- a/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java +++ b/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java @@ -1,9 +1,7 @@ package com.microsoft.applicationinsights.smoketest; -import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import java.util.List; From 97dfc6af95dcd3a8ab61ed02273d5f3bd48ef6fe Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 4 Sep 2019 09:19:14 -0700 Subject: [PATCH 4/5] Improve test reliability --- .../smoketest/TraceLog4j1_2Test.java | 15 ++++++++++++--- .../smoketest/TraceLog4j2Test.java | 15 ++++++++++++--- .../smoketest/TraceLogBackTest.java | 13 +++++++++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java b/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java index 64d4310f727..9ceb8a13543 100644 --- a/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java +++ b/test/smoke/testApps/TraceLog4j1_2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j1_2Test.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.util.Comparator; import java.util.List; import com.microsoft.applicationinsights.internal.schemav2.Data; @@ -27,9 +28,17 @@ public void testTraceLog4j1_2() throws Exception { Envelope mdEnvelope2 = mdList.get(1); Envelope mdEnvelope3 = mdList.get(2); - MessageData md1 = (MessageData) ((Data) mdEnvelope1.getData()).getBaseData(); - MessageData md2 = (MessageData) ((Data) mdEnvelope2.getData()).getBaseData(); - MessageData md3 = (MessageData) ((Data) mdEnvelope3.getData()).getBaseData(); + List logs = mockedIngestion.getTelemetryDataByType("MessageData"); + logs.sort(new Comparator() { + @Override + public int compare(MessageData o1, MessageData o2) { + return o1.getSeverityLevel().compareTo(o2.getSeverityLevel()); + } + }); + + MessageData md1 = logs.get(0); + MessageData md2 = logs.get(1); + MessageData md3 = logs.get(2); assertEquals("This is log4j1.2 warn.", md1.getMessage()); assertEquals(SeverityLevel.Warning, md1.getSeverityLevel()); diff --git a/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java b/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java index d5aaee126b5..3d73cdbaf03 100644 --- a/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java +++ b/test/smoke/testApps/TraceLog4j2UsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLog4j2Test.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.util.Comparator; import java.util.List; import com.microsoft.applicationinsights.internal.schemav2.Data; @@ -28,9 +29,17 @@ public void testTraceLog4j2() throws Exception { Envelope mdEnvelope2 = mdList.get(1); Envelope mdEnvelope3 = mdList.get(2); - MessageData md1 = (MessageData) ((Data) mdEnvelope1.getData()).getBaseData(); - MessageData md2 = (MessageData) ((Data) mdEnvelope2.getData()).getBaseData(); - MessageData md3 = (MessageData) ((Data) mdEnvelope3.getData()).getBaseData(); + List logs = mockedIngestion.getTelemetryDataByType("MessageData"); + logs.sort(new Comparator() { + @Override + public int compare(MessageData o1, MessageData o2) { + return o1.getSeverityLevel().compareTo(o2.getSeverityLevel()); + } + }); + + MessageData md1 = logs.get(0); + MessageData md2 = logs.get(1); + MessageData md3 = logs.get(2); assertEquals("This is log4j2 warn.", md1.getMessage()); assertEquals(SeverityLevel.Warning, md1.getSeverityLevel()); diff --git a/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java b/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java index bfa58f683b9..98dc579d704 100644 --- a/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java +++ b/test/smoke/testApps/TraceLogBackUsingAgent/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/TraceLogBackTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.util.Comparator; import java.util.List; import com.microsoft.applicationinsights.internal.schemav2.Data; @@ -35,8 +36,16 @@ public void testTraceLogBack() throws Exception { Envelope mdEnvelope1 = mdList.get(0); Envelope mdEnvelope2 = mdList.get(1); - MessageData md1 = (MessageData) ((Data) mdEnvelope1.getData()).getBaseData(); - MessageData md2 = (MessageData) ((Data) mdEnvelope2.getData()).getBaseData(); + List logs = mockedIngestion.getTelemetryDataByType("MessageData"); + logs.sort(new Comparator() { + @Override + public int compare(MessageData o1, MessageData o2) { + return o1.getSeverityLevel().compareTo(o2.getSeverityLevel()); + } + }); + + MessageData md1 = logs.get(0); + MessageData md2 = logs.get(1); assertEquals("This is logback warn.", md1.getMessage()); assertEquals(SeverityLevel.Warning, md1.getSeverityLevel()); From 417f60380750c425e3b79be23f3c0ae15e9dcdac Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 4 Sep 2019 20:25:47 -0700 Subject: [PATCH 5/5] Improve sampling test --- .../smoketest/AiSmokeTest.java | 35 +++++++++++------- .../smoketest/TargetUri.java | 5 +++ .../SimpleFixedRateSamplingServlet.java | 10 +++--- .../smoketest/FixedRateSamplingTest.java | 36 ++++++++++--------- 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/AiSmokeTest.java b/test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/AiSmokeTest.java index 7a5b08a3d02..65690662a00 100644 --- a/test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/AiSmokeTest.java +++ b/test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/AiSmokeTest.java @@ -155,6 +155,7 @@ protected static void stopContainer(ContainerInfo info) throws Exception { protected String targetUri; protected String httpMethod; protected long targetUriDelayMs; + protected long targetUriCallCount; protected long targetUriTimeoutMs; //endregion @@ -187,6 +188,7 @@ protected void starting(Description description) { thiz.targetUri = null; thiz.httpMethod = null; thiz.targetUriDelayMs = 0L; + thiz.targetUriCallCount = 1; thiz.targetUriTimeoutMs = TELEMETRY_RECEIVE_TIMEOUT_SECONDS * 1000; } else { thiz.targetUri = targetUri.value(); @@ -195,6 +197,7 @@ protected void starting(Description description) { } thiz.httpMethod = targetUri.method().toUpperCase(); thiz.targetUriDelayMs = targetUri.delay(); + thiz.targetUriCallCount = targetUri.callCount(); thiz.targetUriTimeoutMs = targetUri.timeout() > 0 ? targetUri.timeout() : TELEMETRY_RECEIVE_TIMEOUT_SECONDS * 1000; } @@ -395,20 +398,26 @@ protected void callTargetUriAndWaitForTelemetry() throws Exception { } System.out.println("Calling "+targetUri+" ..."); String url = getBaseUrl()+targetUri; - System.out.println("calling " + url); - final String content; - switch(httpMethod) { - case "GET": - content = HttpHelper.get(url); - break; - default: - throw new NotSupportedException(String.format("http method '%s' is not currently supported", httpMethod)); + if (targetUriCallCount == 1) { + System.out.println("calling " + url); + } else { + System.out.println("calling " + url + " " + targetUriCallCount + " times"); + } + for (int i = 0; i < targetUriCallCount; i++) { + final String content; + switch (httpMethod) { + case "GET": + content = HttpHelper.get(url); + break; + default: + throw new NotSupportedException( + String.format("http method '%s' is not currently supported", httpMethod)); + } + String expectationMessage = "The base context in testApps should return a nonempty response."; + assertNotNull(String.format("Null response from targetUri: '%s'. %s", targetUri, expectationMessage), content); + assertTrue(String.format("Empty response from targetUri: '%s'. %s", targetUri, expectationMessage), + content.length() > 0); } - - String expectationMessage = "The base context in testApps should return a nonempty response."; - assertNotNull(String.format("Null response from targetUri: '%s'. %s", targetUri, expectationMessage), content); - assertTrue(String.format("Empty response from targetUri: '%s'. %s", targetUri, expectationMessage), content.length() > 0); - if (this.targetUriTimeoutMs > 0) { Stopwatch sw = Stopwatch.createStarted(); mockedIngestion.awaitAnyItems(this.targetUriTimeoutMs, TimeUnit.MILLISECONDS); diff --git a/test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/TargetUri.java b/test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/TargetUri.java index 06844ed4527..f00dd71eef7 100644 --- a/test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/TargetUri.java +++ b/test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/TargetUri.java @@ -16,6 +16,11 @@ */ long delay() default 0L; + /** + * The number of times to call the target uri. + */ + int callCount() default 1; + /** * The number of milliseconds to wait for a response. */ diff --git a/test/smoke/testApps/FixedRateSampling/src/main/java/com/microsoft/ajl/simplecalc/SimpleFixedRateSamplingServlet.java b/test/smoke/testApps/FixedRateSampling/src/main/java/com/microsoft/ajl/simplecalc/SimpleFixedRateSamplingServlet.java index dbf70ca604b..d571a9e1ec7 100644 --- a/test/smoke/testApps/FixedRateSampling/src/main/java/com/microsoft/ajl/simplecalc/SimpleFixedRateSamplingServlet.java +++ b/test/smoke/testApps/FixedRateSampling/src/main/java/com/microsoft/ajl/simplecalc/SimpleFixedRateSamplingServlet.java @@ -1,6 +1,7 @@ package com.microsoft.ajl.simplecalc; import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; @@ -19,6 +20,8 @@ public class SimpleFixedRateSamplingServlet extends HttpServlet { private static final long serialVersionUID = -5889330779672565409L; private TelemetryClient client = new TelemetryClient(); + private final AtomicInteger count = new AtomicInteger(); + /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) @@ -27,11 +30,6 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletFuncs.getRenderedHtml(request, response); client.trackTrace("Trace Test."); - for (int i = 0; i < 100; i++) { - String str = String.format("Event Test %s", i); - EventTelemetry et = new EventTelemetry(str); - et.getContext().getOperation().setId(String.valueOf(i)); - client.trackEvent(et); - } + client.trackEvent(new EventTelemetry("Event Test " + count.getAndIncrement())); } } \ No newline at end of file diff --git a/test/smoke/testApps/FixedRateSampling/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/FixedRateSamplingTest.java b/test/smoke/testApps/FixedRateSampling/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/FixedRateSamplingTest.java index 9c0045cf03d..3b6fb315ca7 100644 --- a/test/smoke/testApps/FixedRateSampling/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/FixedRateSamplingTest.java +++ b/test/smoke/testApps/FixedRateSampling/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/FixedRateSamplingTest.java @@ -1,5 +1,7 @@ package com.microsoft.applicationinsights.smoketest; +import java.util.List; + import com.microsoft.applicationinsights.internal.schemav2.Envelope; import org.junit.*; @@ -9,29 +11,29 @@ public class FixedRateSamplingTest extends AiSmokeTest { @Test @TargetUri("/fixedRateSampling") - public void testFixedRateSamplingInExcludedTypes() { - assertEquals(1, mockedIngestion.getCountForType("RequestData")); - assertEquals(100.0, getSampleRate("RequestData", 0), Math.ulp(50.0)); + public void testFixedRateSamplingInExcludedTypes() throws Exception { + List rdList = mockedIngestion.waitForItems("RequestData", 1); + Envelope rd = rdList.get(0); + assertEquals(100.0, rd.getSampleRate(), Math.ulp(50.0)); } @Test - @TargetUri(value = "/fixedRateSampling", delay = 10000) - public void testFixedRateSamplingInIncludedTypes() { - int count = mockedIngestion.getCountForType("EventData"); - assertThat(count, both(greaterThanOrEqualTo(40)).and(lessThanOrEqualTo(60))); - assertEquals(50.0, getSampleRate("EventData", 0), Math.ulp(50.0)); + @TargetUri(value = "/fixedRateSampling", callCount = 100) + public void testFixedRateSamplingInIncludedTypes() throws Exception { + mockedIngestion.waitForItems("RequestData", 100); + List edList = mockedIngestion.getItemsEnvelopeDataType("EventData"); + // super super low chance that number of events sampled is less than 10 or greater than 90 + assertThat(edList.size(), both(greaterThanOrEqualTo(10)).and(lessThanOrEqualTo(90))); + Envelope ed = edList.get(0); + assertEquals(50.0, ed.getSampleRate(), Math.ulp(50.0)); } @Test @TargetUri("/fixedRateSampling") - public void testFixedRateSamplingNotInExcludedTypes() { - assertEquals(1, mockedIngestion.getCountForType("MessageData")); - assertEquals(100.0, getSampleRate("MessageData", 0), Math.ulp(50.0)); - } - - protected double getSampleRate(String type, int index) { - Envelope envelope = mockedIngestion.getItemsEnvelopeDataType(type).get(index); - return envelope.getSampleRate(); + public void testFixedRateSamplingNotInExcludedTypes() throws Exception { + mockedIngestion.waitForItems("RequestData", 1); + List mdList = mockedIngestion.waitForItems("MessageData", 1); + Envelope md = mdList.get(0); + assertEquals(100.0, md.getSampleRate(), Math.ulp(50.0)); } - } \ No newline at end of file