Fail build on warnings (#170)

* Fail build on warnings

* Update dependencyManagement/build.gradle.kts

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
This commit is contained in:
Anuraag Agrawal 2022-01-07 16:15:27 +09:00 committed by GitHub
parent 4c2ee90767
commit 6ed9ba70d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 137 additions and 170 deletions

View File

@ -45,7 +45,7 @@ class RateLimiterTest {
// move time 5s forward, enough to accumulate credits for 10 messages, but it should still be
// capped at 2
clock.advance(Duration.ofMillis(5000));
clock.advance(Duration.ofSeconds(5));
assertThat(limiter.trySpend(1.0)).isTrue();
assertThat(limiter.trySpend(1.0)).isTrue();

View File

@ -25,6 +25,32 @@ tasks {
withType<JavaCompile>().configureEach {
with(options) {
release.set(8)
if (name != "jmhCompileGeneratedClasses") {
compilerArgs.addAll(
listOf(
"-Xlint:all",
// We suppress the "try" warning because it disallows managing an auto-closeable with
// try-with-resources without referencing the auto-closeable within the try block.
"-Xlint:-try",
// We suppress the "processing" warning as suggested in
// https://groups.google.com/forum/#!topic/bazel-discuss/_R3A9TJSoPM
"-Xlint:-processing",
// We suppress the "options" warning because it prevents compilation on modern JDKs
"-Xlint:-options",
// Fail build on any warning
"-Werror"
)
)
}
encoding = "UTF-8"
if (name.contains("Test")) {
// serialVersionUI is basically guaranteed to be useless in tests
compilerArgs.add("-Xlint:-serial")
}
}
}

View File

@ -57,6 +57,7 @@ val DEPENDENCY_SETS = listOf(
)
val DEPENDENCIES = listOf(
"com.google.code.findbugs:annotations:3.0.1u2",
"com.google.code.findbugs:jsr305:3.0.2",
"com.squareup.okhttp3:okhttp:3.14.9",
"com.uber.nullaway:nullaway:0.9.2",

View File

@ -29,6 +29,7 @@ public interface RecordedEventHandler extends Consumer<RecordedEvent>, Predicate
* @param event - event instance to see if we're interested
* @return true if event is interesting, false otherwise
*/
@Override
default boolean test(RecordedEvent event) {
return event.getEventType().getName().equalsIgnoreCase(getEventName());
}

View File

@ -24,13 +24,14 @@ public class AbstractMetricsTest {
@BeforeAll
static void initializeOpenTelemetry() {
metricReader = new InMemoryMetricReader();
metricReader = InMemoryMetricReader.create();
meterProvider =
SdkMeterProvider.builder().registerMetricReader(metricReader).buildAndRegisterGlobal();
JfrMetrics.enable(meterProvider);
}
protected void waitAndAssertMetrics(Consumer<MetricDataAssert>... assertions) {
@SafeVarargs
protected final void waitAndAssertMetrics(Consumer<MetricDataAssert>... assertions) {
await()
.untilAsserted(
() -> {

View File

@ -6,6 +6,7 @@
package io.opentelemetry.contrib.jmxmetrics;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.awaitility.Awaitility.await;
import static org.testcontainers.Testcontainers.exposeHostPorts;
@ -24,13 +25,13 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.assertj.core.api.MapAssert;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@ -93,12 +94,14 @@ public abstract class AbstractIntegrationTest {
.withCopyFileToContainer(
MountableFile.forClasspathResource(configName), "/app/" + configName)
.withCommand(scraperCommand.toArray(new String[0]))
.withStartupTimeout(Duration.ofSeconds(120))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forLogMessage(".*Started GroovyRunner.*", 1));
scraper.start();
}
@AfterAll
// No need to block other tests waiting on return.
@SuppressWarnings("FutureReturnValueIgnored")
void afterAll() {
otlpServer.stop();
}
@ -108,7 +111,8 @@ public abstract class AbstractIntegrationTest {
otlpServer.reset();
}
protected void waitAndAssertMetrics(Consumer<Metric>... assertions) {
@SafeVarargs
protected final void waitAndAssertMetrics(Consumer<Metric>... assertions) {
await()
.atMost(Duration.ofSeconds(30))
.untilAsserted(
@ -150,7 +154,7 @@ public abstract class AbstractIntegrationTest {
}
protected void assertSum(Metric metric, String name, String description, String unit) {
assertSum(metric, name, description, unit, true);
assertSum(metric, name, description, unit, /* isMonotonic= */ true);
}
protected void assertSum(
@ -182,57 +186,62 @@ public abstract class AbstractIntegrationTest {
assertTypedPoints(metric.getSum().getDataPointsList(), types);
}
protected void assertSumWithAttributes(
@SafeVarargs
protected final void assertSumWithAttributes(
Metric metric,
String name,
String description,
String unit,
List<Map<String, String>> attributeGroups) {
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
assertThat(metric.getName()).isEqualTo(name);
assertThat(metric.getDescription()).isEqualTo(description);
assertThat(metric.getUnit()).isEqualTo(unit);
assertThat(metric.hasSum()).isTrue();
assertAttributedPoints(metric.getSum().getDataPointsList(), attributeGroups);
assertAttributedPoints(metric.getSum().getDataPointsList(), attributeGroupAssertions);
}
protected void assertGaugeWithAttributes(
@SafeVarargs
protected final void assertGaugeWithAttributes(
Metric metric,
String name,
String description,
String unit,
List<Map<String, String>> attributeGroups) {
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
assertThat(metric.getName()).isEqualTo(name);
assertThat(metric.getDescription()).isEqualTo(description);
assertThat(metric.getUnit()).isEqualTo(unit);
assertThat(metric.hasGauge()).isTrue();
assertAttributedPoints(metric.getGauge().getDataPointsList(), attributeGroups);
assertAttributedPoints(metric.getGauge().getDataPointsList(), attributeGroupAssertions);
}
private static final String expectedMeterVersion() {
private static String expectedMeterVersion() {
// Automatically set by gradle when running the tests
String version = System.getProperty("gradle.project.version");
assert version != null && !version.isEmpty();
assertThat(version).isNotBlank();
return version;
}
@SuppressWarnings("unchecked")
private static void assertTypedPoints(List<NumberDataPoint> points, List<String> types) {
List<Map<String, String>> expectedAttributes =
Consumer<MapAssert<String, String>>[] assertions =
types.stream()
.map(
type ->
new HashMap<String, String>() {
{
put("name", type);
}
})
.collect(Collectors.toList());
(Consumer<MapAssert<String, String>>)
attrs -> attrs.containsOnly(entry("name", type)))
.toArray(Consumer[]::new);
assertAttributedPoints(points, expectedAttributes);
assertAttributedPoints(points, assertions);
}
@SuppressWarnings("unchecked")
private static void assertAttributedPoints(
List<NumberDataPoint> points, List<Map<String, String>> attributeGroups) {
List<NumberDataPoint> points,
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
Consumer<Map<String, String>>[] assertions =
Arrays.stream(attributeGroupAssertions)
.map(assertion -> (Consumer<Map<String, String>>) m -> assertion.accept(assertThat(m)))
.toArray(Consumer[]::new);
assertThat(points)
.extracting(
numberDataPoint ->
@ -240,15 +249,7 @@ public abstract class AbstractIntegrationTest {
.collect(
Collectors.toMap(
KeyValue::getKey, keyValue -> keyValue.getValue().getStringValue())))
.satisfiesExactlyInAnyOrder(
attributeGroups.stream()
.map(
expected ->
(Consumer<Map<String, String>>)
pointAttributes ->
assertThat(pointAttributes)
.containsExactlyInAnyOrderEntriesOf(expected))
.toArray(Consumer[]::new));
.satisfiesExactlyInAnyOrder(assertions);
}
private static class OtlpGrpcServer extends ServerExtension {

View File

@ -32,7 +32,7 @@ abstract class OtlpIntegrationTest extends AbstractIntegrationTest {
"/etc/cassandra/jmxremote.password")
.withNetworkAliases("cassandra")
.withExposedPorts(7199)
.withStartupTimeout(Duration.ofSeconds(120))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forListeningPort());
@Test

View File

@ -5,13 +5,14 @@
package io.opentelemetry.contrib.jmxmetrics.target_systems;
import static org.assertj.core.api.Assertions.entry;
import io.opentelemetry.contrib.jmxmetrics.AbstractIntegrationTest;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.function.Consumer;
import org.assertj.core.api.MapAssert;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
@ -22,7 +23,7 @@ import org.testcontainers.utility.MountableFile;
class CassandraIntegrationTest extends AbstractIntegrationTest {
CassandraIntegrationTest() {
super(false, "target-systems/cassandra.properties");
super(/* configFromStdin= */ false, "target-systems/cassandra.properties");
}
@Container
@ -35,7 +36,7 @@ class CassandraIntegrationTest extends AbstractIntegrationTest {
"/etc/cassandra/jmxremote.password")
.withNetworkAliases("cassandra")
.withExposedPorts(7199)
.withStartupTimeout(Duration.ofSeconds(120))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forListeningPort());
@Test
@ -113,7 +114,7 @@ class CassandraIntegrationTest extends AbstractIntegrationTest {
"cassandra.storage.load.count",
"Size of the on disk data size this node manages",
"by",
false),
/* isMonotonic= */ false),
metric ->
assertSum(
metric,
@ -126,14 +127,16 @@ class CassandraIntegrationTest extends AbstractIntegrationTest {
"cassandra.storage.total_hints.in_progress.count",
"Number of hints attempting to be sent currently",
"1",
false),
/* isMonotonic= */ false),
metric ->
assertSumWithAttributes(
metric,
"cassandra.client.request.count",
"Number of requests by operation",
"1",
getRequestCountAttributes()),
attrs -> attrs.containsOnly(entry("operation", "RangeSlice")),
attrs -> attrs.containsOnly(entry("operation", "Read")),
attrs -> attrs.containsOnly(entry("operation", "Write"))),
metric ->
assertSumWithAttributes(
metric,
@ -143,21 +146,8 @@ class CassandraIntegrationTest extends AbstractIntegrationTest {
getRequestErrorCountAttributes()));
}
private List<Map<String, String>> getRequestCountAttributes() {
List<String> operations = Arrays.asList("RangeSlice", "Read", "Write");
return operations.stream()
.map(
op ->
new HashMap<String, String>() {
{
put("operation", op);
}
})
.collect(Collectors.toList());
}
private List<Map<String, String>> getRequestErrorCountAttributes() {
@SuppressWarnings("unchecked")
private static Consumer<MapAssert<String, String>>[] getRequestErrorCountAttributes() {
List<String> operations = Arrays.asList("RangeSlice", "Read", "Write");
List<String> statuses = Arrays.asList("Timeout", "Failure", "Unavailable");
@ -167,12 +157,10 @@ class CassandraIntegrationTest extends AbstractIntegrationTest {
statuses.stream()
.map(
st ->
new HashMap<String, String>() {
{
put("operation", op);
put("status", st);
}
}))
.collect(Collectors.toList());
(Consumer<MapAssert<String, String>>)
attrs ->
attrs.containsOnly(
entry("operation", op), entry("status", st))))
.toArray(Consumer[]::new);
}
}

View File

@ -19,7 +19,7 @@ import org.testcontainers.utility.MountableFile;
class JvmTargetSystemIntegrationTest extends AbstractIntegrationTest {
JvmTargetSystemIntegrationTest() {
super(false, "target-systems/jvm.properties");
super(/* configFromStdin= */ false, "target-systems/jvm.properties");
}
@Container
@ -32,7 +32,7 @@ class JvmTargetSystemIntegrationTest extends AbstractIntegrationTest {
"/etc/cassandra/jmxremote.password")
.withNetworkAliases("cassandra")
.withExposedPorts(7199)
.withStartupTimeout(Duration.ofSeconds(120))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forListeningPort());
@Test

View File

@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.contrib.jmxmetrics.AbstractIntegrationTest;
import io.opentelemetry.proto.metrics.v1.Metric;
import io.opentelemetry.proto.metrics.v1.NumberDataPoint;
import java.io.IOException;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
@ -28,7 +29,7 @@ import org.testcontainers.utility.MountableFile;
abstract class KafkaIntegrationTest extends AbstractIntegrationTest {
protected KafkaIntegrationTest(String configName) {
super(false, configName);
super(/* configFromStdin= */ false, configName);
}
@Container
@ -36,7 +37,7 @@ abstract class KafkaIntegrationTest extends AbstractIntegrationTest {
new GenericContainer<>("zookeeper:3.5")
.withNetwork(Network.SHARED)
.withNetworkAliases("zookeeper")
.withStartupTimeout(Duration.ofSeconds(120))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forListeningPort());
@Container
@ -48,7 +49,7 @@ abstract class KafkaIntegrationTest extends AbstractIntegrationTest {
.withEnv("JMX_PORT", "7199")
.withNetworkAliases("kafka")
.withExposedPorts(7199)
.withStartupTimeout(Duration.ofSeconds(120))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forListeningPort())
.dependsOn(zookeeper);
@ -61,7 +62,7 @@ abstract class KafkaIntegrationTest extends AbstractIntegrationTest {
"sh",
"-c",
"unset JMX_PORT; for i in `seq 3`; do kafka-topics.sh --bootstrap-server localhost:9092 --create --topic test-topic-$i; done");
} catch (Exception e) {
} catch (IOException | InterruptedException e) {
throw new AssertionError(e);
}
}
@ -198,7 +199,7 @@ abstract class KafkaIntegrationTest extends AbstractIntegrationTest {
"test-topic-.*",
"--max-messages",
"100")
.withStartupTimeout(Duration.ofSeconds(120))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forListeningPort())
.dependsOn(createTopics);
@ -278,7 +279,7 @@ abstract class KafkaIntegrationTest extends AbstractIntegrationTest {
MountableFile.forClasspathResource("target-systems/kafka-producer.sh"),
"/usr/bin/kafka-producer.sh")
.withCommand("kafka-producer.sh")
.withStartupTimeout(Duration.ofSeconds(120))
.withStartupTimeout(Duration.ofMinutes(2))
.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("kafka-producer")))
.waitingFor(Wait.forListeningPort())
.dependsOn(createTopics);

View File

@ -5,12 +5,10 @@
package io.opentelemetry.contrib.jmxmetrics.target_systems;
import static org.assertj.core.api.Assertions.entry;
import io.opentelemetry.contrib.jmxmetrics.AbstractIntegrationTest;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
@ -21,7 +19,7 @@ import org.testcontainers.junit.jupiter.Container;
class TomcatIntegrationTest extends AbstractIntegrationTest {
TomcatIntegrationTest() {
super(false, "target-systems/tomcat.properties");
super(/* configFromStdin= */ false, "target-systems/tomcat.properties");
}
@Container
@ -37,23 +35,18 @@ class TomcatIntegrationTest extends AbstractIntegrationTest {
"https://tomcat.apache.org/tomcat-9.0-doc/appdev/sample/sample.war",
"/usr/local/tomcat/webapps/ROOT.war")
.env(
new HashMap<String, String>() {
{
put(
"CATALINA_OPTS",
"-Dcom.sun.management.jmxremote.local.only=false "
+ "-Dcom.sun.management.jmxremote.authenticate=false "
+ "-Dcom.sun.management.jmxremote.ssl=false "
+ "-Dcom.sun.management.jmxremote.port=9010 "
+ "-Dcom.sun.management.jmxremote.rmi.port=9010");
}
})
"CATALINA_OPTS",
"-Dcom.sun.management.jmxremote.local.only=false "
+ "-Dcom.sun.management.jmxremote.authenticate=false "
+ "-Dcom.sun.management.jmxremote.ssl=false "
+ "-Dcom.sun.management.jmxremote.port=9010 "
+ "-Dcom.sun.management.jmxremote.rmi.port=9010")
.build()))
.withNetwork(Network.SHARED)
.withEnv("LOCAL_JMX", "no")
.withNetworkAliases("tomcat")
.withExposedPorts(9010)
.withStartupTimeout(Duration.ofSeconds(120))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forListeningPort());
@Test
@ -67,103 +60,52 @@ class TomcatIntegrationTest extends AbstractIntegrationTest {
"tomcat.errors",
"The number of errors encountered.",
"errors",
Collections.singletonList(
new HashMap<String, String>() {
{
put("proto_handler", "\"http-nio-8080\"");
}
})),
attrs -> attrs.containsOnly(entry("proto_handler", "\"http-nio-8080\""))),
metric ->
assertSumWithAttributes(
metric,
"tomcat.processing_time",
"The total processing time.",
"ms",
Collections.singletonList(
new HashMap<String, String>() {
{
put("proto_handler", "\"http-nio-8080\"");
}
})),
attrs -> attrs.containsOnly(entry("proto_handler", "\"http-nio-8080\""))),
metric ->
assertSumWithAttributes(
metric,
"tomcat.traffic",
"The number of bytes transmitted and received.",
"by",
new ArrayList<Map<String, String>>() {
{
add(
new HashMap<String, String>() {
{
put("proto_handler", "\"http-nio-8080\"");
put("direction", "sent");
}
});
add(
new HashMap<String, String>() {
{
put("proto_handler", "\"http-nio-8080\"");
put("direction", "received");
}
});
}
}),
attrs ->
attrs.containsOnly(
entry("proto_handler", "\"http-nio-8080\""), entry("direction", "sent")),
attrs ->
attrs.containsOnly(
entry("proto_handler", "\"http-nio-8080\""),
entry("direction", "received"))),
metric ->
assertGaugeWithAttributes(
metric,
"tomcat.threads",
"The number of threads",
"threads",
new ArrayList<Map<String, String>>() {
{
add(
new HashMap<String, String>() {
{
put("proto_handler", "\"http-nio-8080\"");
put("state", "idle");
}
});
add(
new HashMap<String, String>() {
{
put("proto_handler", "\"http-nio-8080\"");
put("state", "busy");
}
});
}
}),
attrs ->
attrs.containsOnly(
entry("proto_handler", "\"http-nio-8080\""), entry("state", "idle")),
attrs ->
attrs.containsOnly(
entry("proto_handler", "\"http-nio-8080\""), entry("state", "busy"))),
metric ->
assertSumWithAttributes(
metric,
"tomcat.max_time",
"Maximum time to process a request.",
"ms",
new ArrayList<Map<String, String>>() {
{
add(
new HashMap<String, String>() {
{
put("proto_handler", "\"http-nio-8080\"");
}
});
}
}),
attrs -> attrs.containsOnly(entry("proto_handler", "\"http-nio-8080\""))),
metric ->
assertSumWithAttributes(
metric,
"tomcat.request_count",
"The total requests.",
"requests",
new ArrayList<Map<String, String>>() {
{
add(
new HashMap<String, String>() {
{
put("proto_handler", "\"http-nio-8080\"");
}
});
}
}));
attrs -> attrs.containsOnly(entry("proto_handler", "\"http-nio-8080\""))));
}
}

View File

@ -5,6 +5,7 @@
package io.opentelemetry.contrib.jmxmetrics
import groovy.jmx.GroovyMBean
import groovy.transform.PackageScope
import java.util.logging.Logger
import javax.management.openmbean.CompositeData
@ -57,7 +58,7 @@ class InstrumentHelper {
* @param instrument - The {@link io.opentelemetry.api.metrics.Instrument}-producing {@link OtelHelper} method pointer:
* (e.g. new OtelHelper().&doubleValueRecorder)
*/
InstrumentHelper(MBeanHelper mBeanHelper, String instrumentName, String description, String unit, Map<String, Closure> labelFuncs, Map<String, Map<String, Closure>> MBeanAttributes, Closure instrument) {
InstrumentHelper(MBeanHelper mBeanHelper, String instrumentName, String description, String unit, Map<String, Closure<?>> labelFuncs, Map<String, Map<String, Closure<?>>> MBeanAttributes, Closure<?> instrument) {
this.mBeanHelper = mBeanHelper
this.instrumentName = instrumentName
this.description = description

View File

@ -5,6 +5,7 @@
package io.opentelemetry.contrib.jmxmetrics
import groovy.jmx.GroovyMBean
import groovy.transform.PackageScope
import javax.management.MBeanServerConnection
import javax.management.ObjectName

View File

@ -5,6 +5,7 @@
package io.opentelemetry.contrib.jmxmetrics
import groovy.jmx.GroovyMBean
import io.opentelemetry.api.metrics.DoubleCounter
import io.opentelemetry.api.metrics.DoubleHistogram
import io.opentelemetry.api.metrics.DoubleUpDownCounter

View File

@ -80,7 +80,7 @@ class InstrumenterHelperTest {
@BeforeEach
void setupOtel() {
metricReader = new InMemoryMetricReader();
metricReader = InMemoryMetricReader.create();
meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).build();
otel = new OtelHelper(jmxClient, new GroovyMetricEnvironment(meterProvider, "otel.test"));
@ -455,7 +455,7 @@ class InstrumenterHelperTest {
String instrumentName = "multiple." + instrumentMethod + ".counter";
String description = "multiple double counter description";
Map<String, Map<String, Closure>> attributes = new HashMap<>();
Map<String, Map<String, Closure<?>>> attributes = new HashMap<>();
attributes.put(
"FirstAttribute",
Collections.singletonMap("Thing", (Closure<?>) Eval.me("{ mbean -> 1 }")));
@ -544,6 +544,7 @@ class InstrumenterHelperTest {
.toArray(Consumer[]::new);
}
@SuppressWarnings("unchecked")
private Consumer<DoublePointData>[] assertAttributeDoublePoints() {
return Stream.<Consumer<DoublePointData>>of(
point ->
@ -681,7 +682,7 @@ class InstrumenterHelperTest {
String description,
String attribute) {
Closure<?> instrument = (Closure<?>) Eval.me("otel", otel, "otel.&" + instrumentMethod);
Map<String, Closure> labelFuncs = new HashMap<>();
Map<String, Closure<?>> labelFuncs = new HashMap<>();
labelFuncs.put("labelOne", (Closure<?>) Eval.me("{ unused -> 'labelOneValue' }"));
labelFuncs.put(
"labelTwo", (Closure<?>) Eval.me("{ mbean -> mbean.name().getKeyProperty('thing') }"));
@ -702,9 +703,9 @@ class InstrumenterHelperTest {
String instrumentMethod,
String instrumentName,
String description,
Map<String, Map<String, Closure>> attributes) {
Map<String, Map<String, Closure<?>>> attributes) {
Closure<?> instrument = (Closure<?>) Eval.me("otel", otel, "otel.&" + instrumentMethod);
Map<String, Closure> labelFuncs = new HashMap<>();
Map<String, Closure<?>> labelFuncs = new HashMap<>();
InstrumentHelper instrumentHelper =
new InstrumentHelper(
mBeanHelper, instrumentName, description, "1", labelFuncs, attributes, instrument);

View File

@ -26,7 +26,7 @@ class OtelHelperAsynchronousMetricTest {
@BeforeEach
void setUp() {
metricReader = new InMemoryMetricReader();
metricReader = InMemoryMetricReader.create();
meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).build();
otel = new OtelHelper(null, new GroovyMetricEnvironment(meterProvider, "otel.test"));
}

View File

@ -10,7 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import groovy.util.GroovyMBean;
import groovy.jmx.GroovyMBean;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

View File

@ -30,7 +30,7 @@ class OtelHelperSynchronousMetricTest {
@BeforeEach
void setUp() {
metricReader = new InMemoryMetricReader();
metricReader = InMemoryMetricReader.create();
meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).build();
otel = new OtelHelper(null, new GroovyMetricEnvironment(meterProvider, "otel.test"));
}

View File

@ -28,13 +28,12 @@ public class MojoGoalExecutionHandlerConfiguration {
new SnykTestHandler(),
new SpringBootBuildImageHandler());
List<MojoGoalExecutionHandler> spiHandlers = new ArrayList();
List<MojoGoalExecutionHandler> spiHandlers = new ArrayList<>();
// Must use the classloader of the class rather the default ThreadContextClassloader to prevent
// java.util.ServiceConfigurationError:
// io.opentelemetry.maven.handler.MojoGoalExecutionHandler:
// io.opentelemetry.maven.handler.SpringBootBuildImageHandler not a subtype
ServiceLoader.load(MojoGoalExecutionHandler.class, classLoader)
.forEach(handler -> spiHandlers.add(handler));
ServiceLoader.load(MojoGoalExecutionHandler.class, classLoader).forEach(spiHandlers::add);
Map<MavenGoal, MojoGoalExecutionHandler> mojoGoalExecutionHandlers = new HashMap<>();

View File

@ -43,7 +43,7 @@ import org.junit.jupiter.api.Test;
* TODO Find a better solution to instantiate a MavenProject and a MojoExecutionEvent. See
* https://github.com/takari/takari-lifecycle/blob/master/takari-lifecycle-plugin/src/test/java/io/takari/maven/plugins/plugin/PluginDescriptorMojoTest.java
*/
@SuppressWarnings("DeduplicateConstants")
@SuppressWarnings({"DeduplicateConstants", "deprecation"})
public class MojoGoalExecutionHandlerTest {
@Test

View File

@ -8,4 +8,7 @@ description = "Utility to attach OpenTelemetry Java Instrumentation agent from c
dependencies {
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent:1.6.0")
implementation("net.bytebuddy:byte-buddy-agent:1.11.18")
// Used by byte-buddy but not brought in as a transitive dependency.
compileOnly("com.google.code.findbugs:annotations")
}