Polish "Add support for virtual threads in OtlpMetricRegistry configuration"
See gh-42407
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,7 +76,7 @@ public class OtlpMetricsExportAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnThreading(Threading.PLATFORM)
|
||||
public OtlpMeterRegistry otlpMeterRegistryPlatformThreads(OtlpConfig otlpConfig, Clock clock) {
|
||||
public OtlpMeterRegistry otlpMeterRegistry(OtlpConfig otlpConfig, Clock clock) {
|
||||
return new OtlpMeterRegistry(otlpConfig, clock);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class OtlpMetricsExportAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnThreading(Threading.VIRTUAL)
|
||||
public OtlpMeterRegistry otlpMeterRegistryVirtualThreads(OtlpConfig otlpConfig, Clock clock) {
|
||||
VirtualThreadTaskExecutor taskExecutor = new VirtualThreadTaskExecutor("otlp-meter-registry");
|
||||
VirtualThreadTaskExecutor taskExecutor = new VirtualThreadTaskExecutor("otlp-meter-registry-");
|
||||
return new OtlpMeterRegistry(otlpConfig, clock, taskExecutor.getVirtualThreadFactory());
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.testsupport.assertj;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
@@ -24,6 +25,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
import org.assertj.core.api.Assert;
|
||||
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* AssertJ {@link Assert} for {@link ScheduledThreadPoolExecutor}.
|
||||
*
|
||||
@@ -66,12 +69,11 @@ public final class ScheduledExecutorServiceAssert
|
||||
private boolean producesVirtualThreads() {
|
||||
try {
|
||||
return this.actual.schedule(() -> {
|
||||
// https://openjdk.org/jeps/444
|
||||
// jep 444 specifies that virtual threads will belong to
|
||||
// a special thread group given the name "VirtualThreads"
|
||||
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
|
||||
String threadGroupName = (threadGroup != null) ? threadGroup.getName() : "";
|
||||
return threadGroupName.equalsIgnoreCase("VirtualThreads");
|
||||
Method isVirtual = ReflectionUtils.findMethod(Thread.class, "isVirtual");
|
||||
if (isVirtual == null) {
|
||||
return false;
|
||||
}
|
||||
return (boolean) ReflectionUtils.invokeMethod(isVirtual, Thread.currentThread());
|
||||
}, 0, TimeUnit.SECONDS).get();
|
||||
}
|
||||
catch (InterruptedException | ExecutionException ex) {
|
||||
|
||||
Reference in New Issue
Block a user