Skip to content

Commit bc353f0

Browse files
traskheyams
andauthored
Add synthetic metric dimension smoke test (#2528)
Co-authored-by: Helen <[email protected]>
1 parent 3b36f75 commit bc353f0

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsTest.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ abstract class HttpPreaggregatedMetricsTest {
3333
@Test
3434
@TargetUri("/httpUrlConnection")
3535
void testHttpUrlConnection() throws Exception {
36+
testHttpUrlConnectionAndSynthetic(false);
37+
}
38+
39+
@Test
40+
@TargetUri(value = "/httpUrlConnection", userAgent = "AlwaysOn")
41+
void testHttpUrlConnectionAndSynthetic() throws Exception {
42+
testHttpUrlConnectionAndSynthetic(true);
43+
}
44+
45+
private void testHttpUrlConnectionAndSynthetic(boolean synthetic) throws Exception {
3646
verifyHttpclientRequestsAndDependencies("https://mock.codes/200?q=spaces%20test");
3747

3848
List<Envelope> clientMetrics =
@@ -41,7 +51,7 @@ void testHttpUrlConnection() throws Exception {
4151
testing.mockedIngestion.waitForMetricItems("http.server.duration", 1);
4252

4353
verifyHttpClientPreAggregatedMetrics(clientMetrics);
44-
verifyHttpServerPreAggregatedMetrics(serverMetrics);
54+
verifyHttpServerPreAggregatedMetrics(serverMetrics, synthetic);
4555
}
4656

4757
private static void verifyHttpclientRequestsAndDependencies(String successUrlWithQueryString)
@@ -113,28 +123,29 @@ private static void verifyHttpClientPreAggregatedMetrics(List<Envelope> metrics)
113123
Envelope envelope1 = metrics.get(0);
114124
validateTags(envelope1);
115125
MetricData md1 = (MetricData) ((Data<?>) envelope1.getData()).getBaseData();
116-
validateMetricData("client", md1, "200");
126+
validateMetricData("client", md1, "200", false);
117127

118128
// 2nd pre-aggregated metric
119129
Envelope envelope2 = metrics.get(1);
120130
validateTags(envelope2);
121131
MetricData md2 = (MetricData) ((Data<?>) envelope2.getData()).getBaseData();
122-
validateMetricData("client", md2, "404");
132+
validateMetricData("client", md2, "404", false);
123133

124134
// 3rd pre-aggregated metric
125135
Envelope envelope3 = metrics.get(2);
126136
validateTags(envelope3);
127137
MetricData md3 = (MetricData) ((Data<?>) envelope3.getData()).getBaseData();
128-
validateMetricData("client", md3, "500");
138+
validateMetricData("client", md3, "500", false);
129139
}
130140

131-
private static void verifyHttpServerPreAggregatedMetrics(List<Envelope> metrics) {
141+
private static void verifyHttpServerPreAggregatedMetrics(
142+
List<Envelope> metrics, boolean synthetic) {
132143
assertThat(metrics.size()).isEqualTo(1);
133144
// 1st pre-aggregated metric
134145
Envelope envelope1 = metrics.get(0);
135146
validateTags(envelope1);
136147
MetricData md1 = (MetricData) ((Data<?>) envelope1.getData()).getBaseData();
137-
validateMetricData("server", md1, "200");
148+
validateMetricData("server", md1, "200", synthetic);
138149
}
139150

140151
private static void validateTags(Envelope envelope) {
@@ -144,7 +155,8 @@ private static void validateTags(Envelope envelope) {
144155
assertThat(tags).containsEntry("ai.cloud.role", "testrolename");
145156
}
146157

147-
private static void validateMetricData(String type, MetricData metricData, String resultCode) {
158+
private static void validateMetricData(
159+
String type, MetricData metricData, String resultCode, boolean synthetic) {
148160
List<DataPoint> dataPoints = metricData.getMetrics();
149161
assertThat(dataPoints).hasSize(1);
150162
DataPoint dataPoint = dataPoints.get(0);
@@ -161,13 +173,14 @@ private static void validateMetricData(String type, MetricData metricData, Strin
161173
assertThat(properties.get("Dependency.Success")).isEqualTo(expectedSuccess);
162174
assertThat(properties.get("dependency/target")).isEqualTo("mock.codes");
163175
assertThat(properties.get("Dependency.Type")).isEqualTo("Http");
176+
assertThat(properties.get("operation/synthetic")).isEqualTo("False");
164177
} else {
165178
assertThat(properties).hasSize(7);
166179
assertThat(properties.get("_MS.MetricId")).isEqualTo("requests/duration");
167180
assertThat(properties.get("request/resultCode")).isEqualTo(resultCode);
168181
assertThat(properties.get("Request.Success")).isEqualTo(expectedSuccess);
182+
assertThat(properties.get("operation/synthetic")).isEqualTo(synthetic ? "True" : "False");
169183
}
170-
assertThat(properties.get("operation/synthetic")).isEqualTo("False");
171184
assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance");
172185
assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename");
173186
assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True");

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ public static int getResponseCodeEnsuringSampled(String url) throws IOException
2020
return getResponseCode(httpGet);
2121
}
2222

23-
public static String get(String url) throws IOException {
24-
return getBody(new HttpGet(url));
23+
public static String get(String url, String userAgent) throws IOException {
24+
HttpGet httpGet = new HttpGet(url);
25+
if (!userAgent.isEmpty()) {
26+
httpGet.setHeader("User-Agent", userAgent);
27+
}
28+
return getBody(httpGet);
2529
}
2630

2731
private static String getBody(HttpGet httpGet) throws IOException {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void beforeEach(ExtensionContext context) throws Exception {
186186
System.out.println("calling " + url + " " + targetUri.callCount() + " times");
187187
}
188188
for (int i = 0; i < targetUri.callCount(); i++) {
189-
HttpHelper.get(url);
189+
HttpHelper.get(url, targetUri.userAgent());
190190
}
191191
}
192192

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515

1616
/** The number of times to call the target uri. */
1717
int callCount() default 1;
18+
19+
String userAgent() default "";
1820
}

0 commit comments

Comments
 (0)