|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package com.microsoft.applicationinsights.smoketest; |
| 5 | + |
| 6 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11; |
| 7 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9; |
| 8 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17; |
| 9 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17_OPENJ9; |
| 10 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_21; |
| 11 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_21_OPENJ9; |
| 12 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_23; |
| 13 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_23_OPENJ9; |
| 14 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8; |
| 15 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9; |
| 16 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8; |
| 17 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.assertj.core.data.MapEntry.entry; |
| 20 | + |
| 21 | +import com.microsoft.applicationinsights.smoketest.schemav2.Data; |
| 22 | +import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; |
| 23 | +import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; |
| 24 | +import com.microsoft.applicationinsights.smoketest.schemav2.MetricData; |
| 25 | +import java.util.Comparator; |
| 26 | +import java.util.List; |
| 27 | +import java.util.Map; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 30 | + |
| 31 | +@UseAgent |
| 32 | +abstract class HttpPreaggregatedMetricsTestOtlpEnabled { |
| 33 | + |
| 34 | + @RegisterExtension |
| 35 | + static final SmokeTestExtension testing = SmokeTestExtension.builder() |
| 36 | + .useOtlpViaEnvVars() |
| 37 | + .build(); |
| 38 | + |
| 39 | + @Test |
| 40 | + @TargetUri("/httpUrlConnection") |
| 41 | + void testMsSentToAmw() throws Exception { |
| 42 | + verifyMetrics(); |
| 43 | + } |
| 44 | + |
| 45 | + private void verifyMetrics() throws Exception { |
| 46 | + List<Envelope> clientMetrics = |
| 47 | + testing.mockedIngestion.waitForStandardMetricItems("dependencies/duration", 3); |
| 48 | + List<Envelope> serverMetrics = |
| 49 | + testing.mockedIngestion.waitForStandardMetricItems("requests/duration", 1); |
| 50 | + |
| 51 | + verifyHttpClientPreAggregatedMetrics(clientMetrics); |
| 52 | + verifyHttpServerPreAggregatedMetrics(serverMetrics); |
| 53 | + } |
| 54 | + |
| 55 | + private static void verifyHttpClientPreAggregatedMetrics(List<Envelope> metrics) { |
| 56 | + assertThat(metrics.size()).isEqualTo(3); |
| 57 | + // sort metrics based on result code |
| 58 | + metrics.sort( |
| 59 | + Comparator.comparing( |
| 60 | + obj -> { |
| 61 | + MetricData metricData = (MetricData) ((Data<?>) obj.getData()).getBaseData(); |
| 62 | + return metricData.getProperties().get("dependency/resultCode"); |
| 63 | + })); |
| 64 | + |
| 65 | + // 1st pre-aggregated metric |
| 66 | + Envelope envelope1 = metrics.get(0); |
| 67 | + MetricData md1 = (MetricData) ((Data<?>) envelope1.getData()).getBaseData(); |
| 68 | + validateMetricData(md1); |
| 69 | + |
| 70 | + // 2nd pre-aggregated metric |
| 71 | + Envelope envelope2 = metrics.get(1); |
| 72 | + MetricData md2 = (MetricData) ((Data<?>) envelope2.getData()).getBaseData(); |
| 73 | + validateMetricData(md2); |
| 74 | + |
| 75 | + // 3rd pre-aggregated metric |
| 76 | + Envelope envelope3 = metrics.get(2); |
| 77 | + MetricData md3 = (MetricData) ((Data<?>) envelope3.getData()).getBaseData(); |
| 78 | + validateMetricData(md3); |
| 79 | + } |
| 80 | + |
| 81 | + private static void verifyHttpServerPreAggregatedMetrics(List<Envelope> metrics) { |
| 82 | + assertThat(metrics.size()).isEqualTo(1); |
| 83 | + // 1st pre-aggregated metric |
| 84 | + Envelope envelope1 = metrics.get(0); |
| 85 | + MetricData md1 = (MetricData) ((Data<?>) envelope1.getData()).getBaseData(); |
| 86 | + validateMetricData(md1); |
| 87 | + } |
| 88 | + |
| 89 | + private static void validateMetricData(MetricData metricData) { |
| 90 | + List<DataPoint> dataPoints = metricData.getMetrics(); |
| 91 | + assertThat(dataPoints).hasSize(1); |
| 92 | + |
| 93 | + // Verify properties - specifically that _MS.SentToAMW is true |
| 94 | + Map<String, String> properties = metricData.getProperties(); |
| 95 | + assertThat(properties.get("_MS.SentToAMW")).isEqualTo("true"); |
| 96 | + } |
| 97 | + |
| 98 | + @Environment(TOMCAT_8_JAVA_8) |
| 99 | + static class Tomcat8Java8Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 100 | + |
| 101 | + @Environment(TOMCAT_8_JAVA_8_OPENJ9) |
| 102 | + static class Tomcat8Java8OpenJ9Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 103 | + |
| 104 | + @Environment(TOMCAT_8_JAVA_11) |
| 105 | + static class Tomcat8Java11Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 106 | + |
| 107 | + @Environment(TOMCAT_8_JAVA_11_OPENJ9) |
| 108 | + static class Tomcat8Java11OpenJ9Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 109 | + |
| 110 | + @Environment(TOMCAT_8_JAVA_17) |
| 111 | + static class Tomcat8Java17Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 112 | + |
| 113 | + @Environment(TOMCAT_8_JAVA_17_OPENJ9) |
| 114 | + static class Tomcat8Java17OpenJ9Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 115 | + |
| 116 | + @Environment(TOMCAT_8_JAVA_21) |
| 117 | + static class Tomcat8Java21Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 118 | + |
| 119 | + @Environment(TOMCAT_8_JAVA_21_OPENJ9) |
| 120 | + static class Tomcat8Java21OpenJ9Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 121 | + |
| 122 | + @Environment(TOMCAT_8_JAVA_23) |
| 123 | + static class Tomcat8Java23Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 124 | + |
| 125 | + @Environment(TOMCAT_8_JAVA_23_OPENJ9) |
| 126 | + static class Tomcat8Java23OpenJ9Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 127 | + |
| 128 | + @Environment(WILDFLY_13_JAVA_8) |
| 129 | + static class Wildfly13Java8Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 130 | + |
| 131 | + @Environment(WILDFLY_13_JAVA_8_OPENJ9) |
| 132 | + static class Wildfly13Java8OpenJ9Test extends HttpPreaggregatedMetricsTestOtlpEnabled {} |
| 133 | +} |
0 commit comments