-
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0f33883
Fix flaky live metrics smoke test
trask 92f3a05
more
trask c6e9be2
refactor
trask 319ac58
cleanup
trask 0829ed9
fix
trask 7675488
debug
trask 5041444
fix
trask ed1e991
fix
trask 4f9a614
fix
trask 479d730
handle old 3.x agent
trask 3b84564
workaround
trask File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,9 +281,16 @@ protected String getAppContext() { | |
|
||
private void clearOutAnyInitLogs() throws Exception { | ||
if (!skipHealthCheck) { | ||
await().until(mockedIngestion::isReceivingLiveMetrics); | ||
String contextRootUrl = getBaseUrl() + "/"; | ||
HttpHelper.getResponseCodeEnsuringSampled(contextRootUrl); | ||
waitForHealthCheckTelemetry(contextRootUrl); | ||
await() | ||
.untilAsserted( | ||
() -> | ||
assertThat(mockedIngestion.getLiveMetrics().getRequestCount(contextRootUrl)) | ||
.isEqualTo(1)); | ||
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. this ensures that live metrics have been sent before resetData is called below |
||
|
||
System.out.println("Clearing any RequestData from health check."); | ||
mockedIngestion.resetData(); | ||
} | ||
|
132 changes: 132 additions & 0 deletions
132
...n/java/com/microsoft/applicationinsights/smoketest/fakeingestion/LiveMetricsVerifier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.