Disable periodic metric reading in tests
MODIFY
testing/agent-exporter/src/main/java/io/opentelemetry/javaagent/testing/exporter/AgentTestingCustomizer.java
testing/agent-exporter/src/main/java/io/opentelemetry/javaagent/testing/exporter/AgentTestingCustomizer.java
@@ -23,7 +23,9 @@ public class AgentTestingCustomizer implements AutoConfigurationCustomizerProvid
static final MetricReader metricReader =
PeriodicMetricReader.builder(AgentTestingExporterFactory.metricExporter)
- .setInterval(Duration.ofMillis(100))
+ // Set really long interval. We'll call forceFlush when we need the metrics
+ // instead of collecting them periodically.
+ .setInterval(Duration.ofNanos(Long.MAX_VALUE))
.build();
static void reset() {

MODIFY
testing/agent-exporter/src/main/java/io/opentelemetry/javaagent/testing/exporter/AgentTestingExporterFactory.java
testing/agent-exporter/src/main/java/io/opentelemetry/javaagent/testing/exporter/AgentTestingExporterFactory.java
@@ -19,6 +19,7 @@ public class AgentTestingExporterFactory {
}
public static List<byte[]> getMetricExportRequests() {
+ AgentTestingCustomizer.metricReader.forceFlush().join(10, TimeUnit.SECONDS);
return metricExporter.getCollectedExportRequests();
}

Disable periodic metric reading in tests (#6025)