-
Notifications
You must be signed in to change notification settings - Fork 207
Fix flaky live metrics smoke test #4275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0f33883
92f3a05
c6e9be2
319ac58
0829ed9
7675488
5041444
ed1e991
4f9a614
479d730
3b84564
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nullable; | ||
import org.awaitility.core.ConditionTimeoutException; | ||
import org.junit.jupiter.api.extension.AfterAllCallback; | ||
import org.junit.jupiter.api.extension.AfterEachCallback; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
|
@@ -75,8 +76,7 @@ public class SmokeTestExtension | |
private static final File appFile = new File(System.getProperty("ai.smoke-test.test-app-file")); | ||
|
||
// TODO (trask) make private and expose methods on AiSmokeTest(?) | ||
protected final MockedAppInsightsIngestionServer mockedIngestion = | ||
new MockedAppInsightsIngestionServer(); | ||
protected final MockedAppInsightsIngestionServer mockedIngestion; | ||
|
||
protected final MockedOtlpIngestionServer mockedOtlpIngestion = new MockedOtlpIngestionServer(); | ||
|
||
|
@@ -167,6 +167,8 @@ public static SmokeTestExtensionBuilder builder() { | |
this.jvmArgs = jvmArgs; | ||
this.useDefaultHttpPort = useDefaultHttpPort; | ||
this.useOtlpEndpoint = useOtlpEndpoint; | ||
|
||
mockedIngestion = new MockedAppInsightsIngestionServer(useOld3xAgent); | ||
} | ||
|
||
private static String getProfilerEndpoint(ProfilerState profilerState) { | ||
|
@@ -281,9 +283,24 @@ protected String getAppContext() { | |
|
||
private void clearOutAnyInitLogs() throws Exception { | ||
if (!skipHealthCheck) { | ||
if (!useOld3xAgent) { | ||
await().until(mockedIngestion::isReceivingLiveMetrics); | ||
} | ||
String contextRootUrl = getBaseUrl() + "/"; | ||
HttpHelper.getResponseCodeEnsuringSampled(contextRootUrl); | ||
waitForHealthCheckTelemetry(contextRootUrl); | ||
if (!useOld3xAgent) { | ||
try { | ||
await() | ||
.untilAsserted( | ||
() -> | ||
assertThat(mockedIngestion.getLiveMetrics().getRequestCount(contextRootUrl)) | ||
.isEqualTo(1)); | ||
} catch (ConditionTimeoutException e) { | ||
// TODO (trask) need to fix race condition in live metrics | ||
// where sometimes it loses telemetry | ||
Comment on lines
+300
to
+301
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm working on a separate fix for this in azure-sdk-for-java repo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Azure/azure-sdk-for-java#45944 I will test it in a separate PR by removing this catch (after this PR is merged) |
||
} | ||
} | ||
System.out.println("Clearing any RequestData from health check."); | ||
mockedIngestion.resetData(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.applicationinsights.smoketest.fakeingestion; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.azure.json.JsonProviders; | ||
import com.azure.json.JsonReader; | ||
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.DocumentIngress; | ||
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.DocumentType; | ||
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.Exception; | ||
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.MetricPoint; | ||
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.MonitoringDataPoint; | ||
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.Request; | ||
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.Trace; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class LiveMetricsVerifier { | ||
|
||
private final List<MonitoringDataPoint> points = new ArrayList<>(); | ||
|
||
public void apply(String postBody) throws IOException { | ||
List<MonitoringDataPoint> dataPoints; | ||
try (JsonReader reader = JsonProviders.createReader(postBody)) { | ||
dataPoints = reader.readArray(MonitoringDataPoint::fromJson); | ||
} | ||
|
||
// Because the mock ping/posts should succeed, there should be one MonitoringDataPoint per post | ||
assertThat(dataPoints).hasSize(1); | ||
points.add(dataPoints.get(0)); | ||
} | ||
|
||
public int getRequestCountFromMetric() { | ||
return getMetricCount("\\ApplicationInsights\\Requests/Sec"); | ||
} | ||
|
||
public int getDependencyCountFromMetric() { | ||
return getMetricCount("\\ApplicationInsights\\Dependency Calls/Sec"); | ||
} | ||
|
||
public int getRequestCount(String url) { | ||
int count = 0; | ||
for (MonitoringDataPoint point : points) { | ||
List<DocumentIngress> docs = point.getDocuments(); | ||
for (DocumentIngress doc : docs) { | ||
if (doc.getDocumentType().equals(DocumentType.REQUEST)) { | ||
Request request = (Request) doc; | ||
if (url.equals(request.getUrl())) { | ||
count++; | ||
} | ||
} | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
public int getExceptionCount(String exceptionMessage) { | ||
int count = 0; | ||
for (MonitoringDataPoint point : points) { | ||
List<DocumentIngress> docs = point.getDocuments(); | ||
for (DocumentIngress doc : docs) { | ||
if (doc.getDocumentType().equals(DocumentType.EXCEPTION)) { | ||
Exception ex = (Exception) doc; | ||
if (ex.getExceptionMessage().equals(exceptionMessage)) { | ||
count++; | ||
} | ||
} | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
public int getTraceCount(String traceMessage) { | ||
int count = 0; | ||
for (MonitoringDataPoint point : points) { | ||
List<DocumentIngress> docs = point.getDocuments(); | ||
for (DocumentIngress doc : docs) { | ||
if (doc.getDocumentType().equals(DocumentType.TRACE)) { | ||
Trace trace = (Trace) doc; | ||
if (trace.getMessage().equals(traceMessage)) { | ||
count++; | ||
} | ||
} | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
public void confirmDocsAreFiltered() { | ||
for (MonitoringDataPoint point : points) { | ||
List<DocumentIngress> docs = point.getDocuments(); | ||
for (DocumentIngress doc : docs) { | ||
assertThat(doc.getDocumentType()).isNotEqualTo(DocumentType.REMOTE_DEPENDENCY); | ||
harsimar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
public void confirmPerfCountersNonZero() { | ||
for (MonitoringDataPoint point : points) { | ||
List<MetricPoint> metrics = point.getMetrics(); | ||
for (MetricPoint metric : metrics) { | ||
String name = metric.getName(); | ||
double value = metric.getValue(); | ||
if (name.equals("\\Process\\Physical Bytes") | ||
|| name.equals("\\% Process\\Processor Time Normalized")) { | ||
assertThat(value).isNotEqualTo(0); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private int getMetricCount(String metricName) { | ||
int count = 0; | ||
for (MonitoringDataPoint point : points) { | ||
List<MetricPoint> metrics = point.getMetrics(); | ||
for (MetricPoint metric : metrics) { | ||
String name = metric.getName(); | ||
double value = metric.getValue(); | ||
if (name.equals(metricName)) { | ||
if (Math.floor(value) != value) { | ||
throw new IllegalStateException("Not an integer: " + value); | ||
} | ||
count += (int) value; | ||
} | ||
} | ||
} | ||
return count; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.