Merge branch '2.2.x'

This commit is contained in:
Marcin Grzejszczak
2021-02-26 14:17:34 +01:00
5 changed files with 27 additions and 14 deletions

View File

@@ -35,6 +35,10 @@ public class Pair {
return new Pair(key, value);
}
public static Pair onHook() {
return new Pair("spring.sleuth.reactor.instrumentation-type", SleuthReactorProperties.InstrumentationType.DECORATE_QUEUES.name());
}
public static Pair noSleuth() {
return new Pair("spring.sleuth.enabled", "false");
}

View File

@@ -40,6 +40,7 @@ import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.benchmarks.app.stream.SleuthBenchmarkingStreamApplication;
import org.springframework.cloud.sleuth.benchmarks.jmh.Pair;
import org.springframework.cloud.sleuth.benchmarks.jmh.TracerImplementation;
@@ -54,9 +55,9 @@ import org.springframework.messaging.support.MessageBuilder;
import static org.assertj.core.api.Assertions.assertThat;
@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 5, time = 1)
@Fork(2)
@Measurement(iterations = 10, time = 1)
@Warmup(iterations = 10, time = 1)
@Fork(4)
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Microbenchmark
@@ -133,6 +134,7 @@ public class MicroBenchmarkStreamTests {
} else {
assertThat(b3).startsWith("4883117762eb9420");
}
assertThat(this.applicationContext.getBean(Tracer.class).currentSpan()).isNull();
}
}
@@ -154,7 +156,7 @@ public class MicroBenchmarkStreamTests {
// @formatter:off
noSleuthSimple(Pair.noSleuth(), function("simple")),
sleuthSimpleOnQueues(function("simple")),
sleuthSimpleOnQueues(function("simple"), Pair.onHook()),
sleuthSimpleManual(function("simple_manual"), Pair.manual(), functionDisabled(), integrationDisabled()),
sleuthSimpleNoFunctionInstrumentationManual(function("simple_manual"), Pair.manual(), functionDisabled(), integrationEnabled()),
sleuthSimpleOnEach(function("simple"), Pair.onEach()),

View File

@@ -41,15 +41,18 @@ import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.benchmarks.app.webflux.SleuthBenchmarkingSpringWebFluxApp;
import org.springframework.cloud.sleuth.benchmarks.jmh.Pair;
import org.springframework.cloud.sleuth.benchmarks.jmh.TracerImplementation;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.web.reactive.server.WebTestClient;
@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 5, time = 1)
@Fork(2)
import static org.assertj.core.api.Assertions.assertThat;
@Measurement(iterations = 10, time = 1)
@Warmup(iterations = 10, time = 1)
@Fork(4)
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Microbenchmark
@@ -98,6 +101,7 @@ public class MicroBenchmarkHttpTests {
void run() {
this.webTestClient.get().uri(instrumentation.url).header("X-B3-TraceId", "4883117762eb9420")
.header("X-B3-SpanId", "4883117762eb9420").exchange().expectStatus().isOk();
assertThat(this.applicationContext.getBean(Tracer.class).currentSpan()).isNull();
}
@TearDown
@@ -118,12 +122,12 @@ public class MicroBenchmarkHttpTests {
// @formatter:off
noSleuthSimple("/simple", Pair.noSleuth()),
sleuthSimpleOnHooks("/simple"),
sleuthSimpleManual("/simpleManual", Pair.manual()),
sleuthSimpleOnEach("/simple", Pair.onEach()),
sleuthSimpleOnLast("/simple", Pair.onLast()),
onQueuesSimple("/simple", Pair.onHook()),
onManualSimple("/simpleManual", Pair.manual()),
onEachSimple("/simple", Pair.onEach()),
onLastSimple("/simple", Pair.onLast()),
noSleuthComplex("/complexNoSleuth", Pair.noSleuth()),
onHooksComplex("/complex"),
onQueueComplex("/complex", Pair.onHook()),
onManualComplex("/complexManual", Pair.manual()),
onEachComplex("/complex", Pair.onEach()),
onLastComplex("/complex", Pair.onLast());

View File

@@ -139,8 +139,8 @@ class HooksRefresher implements ApplicationListener<RefreshScopeRefreshedEvent>
}
Hooks.resetOnEachOperator(SLEUTH_TRACE_REACTOR_KEY);
Hooks.resetOnLastOperator(SLEUTH_TRACE_REACTOR_KEY);
Hooks.resetOnLastOperator(SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY);
Hooks.removeQueueWrapper(SLEUTH_TRACE_REACTOR_KEY);
Schedulers.resetOnScheduleHook(SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY);
switch (this.reactorProperties.getInstrumentationType()) {
case DECORATE_QUEUES:
if (TraceReactorAutoConfiguration.TraceReactorConfiguration.IS_QUEUE_WRAPPER_ON_THE_CLASSPATH) {
@@ -148,6 +148,8 @@ class HooksRefresher implements ApplicationListener<RefreshScopeRefreshedEvent>
log.trace("Adding queue wrapper instrumentation");
}
HookRegisteringBeanDefinitionRegistryPostProcessor.addQueueWrapper(context);
Schedulers.onScheduleHook(TraceReactorAutoConfiguration.SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY,
ReactorSleuth.scopePassingOnScheduleHook(this.context));
}
case DECORATE_ON_EACH:
if (log.isTraceEnabled()) {
@@ -197,7 +199,7 @@ class HookRegisteringBeanDefinitionRegistryPostProcessor implements BeanDefiniti
ConfigurableEnvironment environment = springContext.getEnvironment();
SleuthReactorProperties.InstrumentationType property = environment.getProperty(
"spring.sleuth.reactor.instrumentation-type", SleuthReactorProperties.InstrumentationType.class,
SleuthReactorProperties.InstrumentationType.DECORATE_QUEUES);
SleuthReactorProperties.InstrumentationType.DECORATE_ON_EACH);
if (wrapperNotOnClasspathHooksPropertyTurnedOn(property)) {
log.warn(
"You have explicitly set the decorate hooks option but you're using an old version of Reactor. Please upgrade to the latest Boot version (at least 2.4.3). Will fall back to the previous reactor instrumentation mode");

View File

@@ -83,6 +83,7 @@ public abstract class FlatMapTests {
testConfiguration(), Issue866Configuration.class)
.web(WebApplicationType.REACTIVE)
.properties("server.port=0", "spring.jmx.enabled=false",
"spring.sleuth.reactor.instrumentation-type=DECORATE_QUEUES",
"spring.application.name=TraceWebFluxOnQueuesTests", "security.basic.enabled=false",
"management.security.enabled=false")
.run();