Skip to content
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

Better agent extension support #3493

Merged
merged 8 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,15 @@ private static Configuration loadConfigurationFile(Path agentJarPath) {
return configFromJsonNextToAgent;
}

if (getEnvVar("APPLICATIONINSIGHTS_PREVIEW_BSP_SCHEDULE_DELAY") != null) {
// Note: OTEL_BSP_SCHEDULE_DELAY and OTEL_BLRP_SCHEDULE_DELAY could be used,
// but should not be needed now that the default delay has been properly tuned
configurationLogger.warn(
"APPLICATIONINSIGHTS_PREVIEW_BSP_SCHEDULE_DELAY is no longer supported,"
+ " please report an issue to https://github.com/microsoft/ApplicationInsights-Java"
+ " if you are still in nead of this setting.");
}

// json configuration file is not required, ok to configure via env var alone
return new Configuration();
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.azure.monitor.opentelemetry.exporter.implementation.AzureMonitorLogRecordExporterProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.azure.monitor.opentelemetry.exporter.implementation.AzureMonitorMetricExporterProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.azure.monitor.opentelemetry.exporter.implementation.AzureMonitorSpanExporterProvider
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.microsoft.applicationinsights.smoketest.schemav2.Data;
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
import com.microsoft.applicationinsights.smoketest.schemav2.MetricData;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Predicate;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -29,8 +35,19 @@ abstract class DetectUnexpectedOtelMetricsTest {

static {
EXPECTED_METRIC_NAMES.add("_OTELRESOURCE_");
EXPECTED_METRIC_NAMES.add("Current Thread Count");
EXPECTED_METRIC_NAMES.add("Loaded Class Count");
EXPECTED_METRIC_NAMES.add("Current Thread Count");
EXPECTED_METRIC_NAMES.add("\\Process(??APP_WIN32_PROC??)\\% Processor Time");
EXPECTED_METRIC_NAMES.add("\\Process(??APP_WIN32_PROC??)\\% Processor Time Normalized");
EXPECTED_METRIC_NAMES.add("\\Process(??APP_WIN32_PROC??)\\Private Bytes");
EXPECTED_METRIC_NAMES.add("\\Memory\\Available Bytes");
EXPECTED_METRIC_NAMES.add("\\Process(??APP_WIN32_PROC??)\\IO Data Bytes/sec");
EXPECTED_METRIC_NAMES.add("\\Processor(_Total)\\% Processor Time");
EXPECTED_METRIC_NAMES.add("Suspected Deadlocked Threads");
EXPECTED_METRIC_NAMES.add("Heap Memory Used (MB)");
EXPECTED_METRIC_NAMES.add("% Of Max Heap Memory Used");
EXPECTED_METRIC_NAMES.add("GC Total Count");
EXPECTED_METRIC_NAMES.add("GC Total Time");
}

@Test
Expand All @@ -39,11 +56,40 @@ void testApp() throws Exception {
// verify no unexpected otel metrics, expect an TimeoutException being thrown
assertThatThrownBy(
() ->
testing.mockedIngestion.waitForItemsUnexpectedOtelMetric(
"MetricData", envelope -> true, EXPECTED_METRIC_NAMES))
testing.mockedIngestion.waitForItems(
"MetricData",
envelope -> {
MetricData md = (MetricData) ((Data<?>) envelope.getData()).getBaseData();
return !EXPECTED_METRIC_NAMES.contains(md.getMetrics().get(0).getName())
&& !md.getProperties().containsKey("_MS.MetricId");
},
1))
.isInstanceOf(TimeoutException.class);
}

// wait for at least one unexpected otel metrics for failure case or timeout for success
public List<Envelope> waitForItemsUnexpectedOtelMetric(String type, Predicate<Envelope> condition)
throws InterruptedException, ExecutionException, TimeoutException {
return testing.mockedIngestion.waitForItems(
new Predicate<Envelope>() {
@Override
public boolean test(Envelope input) {
if (!input.getData().getBaseType().equals(type)) {
return false;
}
MetricData md = (MetricData) ((Data<?>) input.getData()).getBaseData();
if ("_OTELRESOURCE_".equals(md.getMetrics().get(0).getName())
|| md.getProperties().containsKey("_MS.MetricId")) {
return false;
}
return condition.test(input);
}
},
1,
10,
TimeUnit.SECONDS);
}

@Environment(TOMCAT_8_JAVA_8)
static class Tomcat8Java8Test extends DetectUnexpectedOtelMetricsTest {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void doMostBasicTest() throws Exception {
verifyJmxMetricsSentToOtlpEndpoint();
}

@SuppressWarnings("PreferJavaTimeOverload")
@SuppressWarnings({"PreferJavaTimeOverload"})
private void verifyJmxMetricsSentToOtlpEndpoint() {
await()
.atMost(10, SECONDS)
Expand Down Expand Up @@ -134,7 +134,7 @@ private void verifyJmxMetricsSentToOtlpEndpoint() {
// (the collector seems to run for 5-10 sec)
assertThat(occurrences.keySet()).hasSize(6);
for (int value : occurrences.values()) {
assertThat(value).isBetween(1, 2);
assertThat(value).isBetween(1, 8);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
abstract class OtlpTest {

@RegisterExtension
static final SmokeTestExtension testing =
SmokeTestExtension.builder().useOtlpEndpoint().setSelfDiagnosticsLevel("TRACE").build();
static final SmokeTestExtension testing = SmokeTestExtension.builder().useOtlpEndpoint().build();

@Test
@TargetUri("/ping")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ private void startTestApplicationContainer() throws Exception {
.withEnv("APPLICATIONINSIGHTS_CONNECTION_STRING", connectionString)
.withEnv("APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_LEVEL", selfDiagnosticsLevel)
.withEnv("OTEL_RESOURCE_ATTRIBUTES", otelResourceAttributesEnvVar)
.withEnv("APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS", "1")
.withNetwork(network)
.withExposedPorts(8080)
.withFileSystemBind(
Expand All @@ -409,7 +410,6 @@ private void startTestApplicationContainer() throws Exception {

List<String> javaToolOptions = new ArrayList<>();
javaToolOptions.add("-Dapplicationinsights.testing.batch-schedule-delay-millis=500");
javaToolOptions.add("-Dapplicationinsights.testing.metric-reader-interval-millis=500");
if (agentExtensionFile != null) {
javaToolOptions.add("-Dotel.javaagent.extensions=/" + agentExtensionFile.getName());
}
Expand All @@ -419,7 +419,8 @@ private void startTestApplicationContainer() throws Exception {
+ FAKE_BREEZE_INGESTION_ENDPOINT);
}
if (useOtlpEndpoint) {
javaToolOptions.add("-Dotel.metrics.exporter=otlp");
// TODO (trask) don't use azure_monitor exporter for smoke test health check
javaToolOptions.add("-Dotel.metrics.exporter=otlp,azure_monitor");
javaToolOptions.add("-Dotel.exporter.otlp.metrics.endpoint=" + FAKE_OTLP_INGESTION_ENDPOINT);
javaToolOptions.add("-Dotel.exporter.otlp.protocol=http/protobuf");
}
Expand Down