forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#44686 from cescoffier/virtual-thread-met…
…rics Enable Virtual Thread Binder if micrometer-java21 is on the Classpath
- Loading branch information
Showing
16 changed files
with
593 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
42 changes: 42 additions & 0 deletions
42
...t/src/main/java/io/quarkus/micrometer/deployment/binder/VirtualThreadBinderProcessor.java
This file contains 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,42 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.NativeMonitoringBuildItem; | ||
import io.quarkus.deployment.pkg.NativeConfig; | ||
import io.quarkus.micrometer.runtime.MicrometerRecorder; | ||
import io.quarkus.micrometer.runtime.config.MicrometerConfig; | ||
|
||
/** | ||
* Add support for virtual thread metric collections. | ||
*/ | ||
public class VirtualThreadBinderProcessor { | ||
static final String VIRTUAL_THREAD_COLLECTOR_CLASS_NAME = "io.quarkus.micrometer.runtime.binder.virtualthreads.VirtualThreadCollector"; | ||
|
||
static final String VIRTUAL_THREAD_BINDER_CLASS_NAME = "io.micrometer.java21.instrument.binder.jdk.VirtualThreadMetrics"; | ||
static final Class<?> VIRTUAL_THREAD_BINDER_CLASS = MicrometerRecorder.getClassForName(VIRTUAL_THREAD_BINDER_CLASS_NAME); | ||
|
||
static class VirtualThreadSupportEnabled implements BooleanSupplier { | ||
MicrometerConfig mConfig; | ||
|
||
public boolean getAsBoolean() { | ||
return VIRTUAL_THREAD_BINDER_CLASS != null // The binder is in another Micrometer artifact | ||
&& mConfig.checkBinderEnabledWithDefault(mConfig.binder.virtualThreads); | ||
} | ||
} | ||
|
||
@BuildStep(onlyIf = VirtualThreadSupportEnabled.class) | ||
AdditionalBeanBuildItem createCDIEventConsumer() { | ||
return AdditionalBeanBuildItem.builder() | ||
.addBeanClass(VIRTUAL_THREAD_COLLECTOR_CLASS_NAME) | ||
.setUnremovable().build(); | ||
} | ||
|
||
@BuildStep(onlyIf = VirtualThreadSupportEnabled.class) | ||
void addNativeMonitoring(BuildProducer<NativeMonitoringBuildItem> nativeMonitoring) { | ||
nativeMonitoring.produce(new NativeMonitoringBuildItem(NativeConfig.MonitoringOption.JFR)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...c/test/java/io/quarkus/micrometer/deployment/binder/VirtualThreadMetricsDisabledTest.java
This file contains 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,41 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.inject.spi.BeanManager; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.micrometer.runtime.binder.virtualthreads.VirtualThreadCollector; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class VirtualThreadMetricsDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("test-logging.properties") | ||
.overrideConfigKey("quarkus.micrometer.binder.virtual-threads.enabled", "true") | ||
|
||
.overrideConfigKey("quarkus.micrometer.binder-enabled-default", "false") | ||
.overrideConfigKey("quarkus.micrometer.registry-enabled-default", "false") | ||
.overrideConfigKey("quarkus.redis.devservices.enabled", "false") | ||
.withEmptyApplication(); | ||
|
||
@Inject | ||
BeanManager beans; | ||
|
||
@Test | ||
void testNoInstancePresentIfDisabled() { | ||
assertTrue( | ||
beans.createInstance().select() | ||
.stream().filter(this::isVirtualThreadCollector).findAny().isEmpty(), | ||
"No VirtualThreadCollector expected"); | ||
} | ||
|
||
private boolean isVirtualThreadCollector(Object bean) { | ||
return bean.getClass().toString().equals(VirtualThreadCollector.class.toString()); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...yment/src/test/java/io/quarkus/micrometer/deployment/binder/VirtualThreadMetricsTest.java
This file contains 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,44 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledForJreRange; | ||
import org.junit.jupiter.api.condition.JRE; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.micrometer.runtime.binder.virtualthreads.VirtualThreadCollector; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
@EnabledForJreRange(min = JRE.JAVA_21) | ||
public class VirtualThreadMetricsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("test-logging.properties") | ||
.overrideConfigKey("quarkus.redis.devservices.enabled", "false") | ||
.withEmptyApplication(); | ||
|
||
@Inject | ||
Instance<VirtualThreadCollector> collector; | ||
|
||
@Test | ||
void testInstancePresent() { | ||
assertTrue(collector.isResolvable(), "VirtualThreadCollector expected"); | ||
} | ||
|
||
@Test | ||
void testBinderCreated() { | ||
assertThat(collector.get().getBinder()).isNotNull(); | ||
} | ||
|
||
@Test | ||
void testTags() { | ||
assertThat(collector.get().getTags()).isEmpty(); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...c/test/java/io/quarkus/micrometer/deployment/binder/VirtualThreadMetricsWithTagsTest.java
This file contains 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,53 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledForJreRange; | ||
import org.junit.jupiter.api.condition.JRE; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.micrometer.runtime.binder.virtualthreads.VirtualThreadCollector; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
@EnabledForJreRange(min = JRE.JAVA_21) | ||
public class VirtualThreadMetricsWithTagsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("test-logging.properties") | ||
.overrideConfigKey("quarkus.micrometer.binder.virtual-threads.tags", "k1=v1, k2=v2") | ||
.overrideConfigKey("quarkus.redis.devservices.enabled", "false") | ||
.withEmptyApplication(); | ||
|
||
@Inject | ||
Instance<VirtualThreadCollector> collector; | ||
|
||
@Test | ||
void testInstancePresent() { | ||
assertTrue(collector.isResolvable(), "VirtualThreadCollector expected"); | ||
} | ||
|
||
@Test | ||
void testBinderCreated() { | ||
assertThat(collector.get().getBinder()).isNotNull(); | ||
} | ||
|
||
@Test | ||
void testTags() { | ||
assertThat(collector.get().getTags()).hasSize(2) | ||
.anySatisfy(t -> { | ||
assertThat(t.getKey()).isEqualTo("k1"); | ||
assertThat(t.getValue()).isEqualTo("v1"); | ||
}) | ||
.anySatisfy(t -> { | ||
assertThat(t.getKey()).isEqualTo("k2"); | ||
assertThat(t.getValue()).isEqualTo("v2"); | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.