Applied checkstyle

This commit is contained in:
Marcin Grzejszczak
2019-02-07 16:41:59 +01:00
parent 37df4c4df8
commit 2f7cf78614
380 changed files with 7749 additions and 5259 deletions

View File

@@ -1,4 +1,4 @@
root=true
root = true
[*.java]
indent_style = tab
@@ -13,4 +13,12 @@ continuation_indent_size = 8
[*.xml]
indent_style = tab
indent_size = 4
continuation_indent_size = 8
continuation_indent_size = 8
[*.yml]
indent_style = space
indent_size = 2
[*.yaml]
indent_style = space
indent_size = 2

View File

@@ -1 +1 @@
-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom

Binary file not shown.

View File

@@ -13,5 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip

View File

@@ -16,74 +16,78 @@
-->
<settings>
<servers>
<server>
<id>repo.spring.io</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<!--
N.B. this profile is only here to support users and IDEs that do not use Maven 3.3.
It isn't needed on the command line if you use the wrapper script (mvnw) or if you use
a native Maven with the right version. Eclipse users should points their Maven tooling to
this settings file, or copy the profile into their ~/.m2/settings.xml.
-->
<id>spring</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--
Turns on jdk8 for tests
-->
<id>ide</id>
<activation><activeByDefault>true</activeByDefault></activation>
</profile>
</profiles>
<servers>
<server>
<id>repo.spring.io</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<!--
N.B. this profile is only here to support users and IDEs that do not use Maven 3.3.
It isn't needed on the command line if you use the wrapper script (mvnw) or if you use
a native Maven with the right version. Eclipse users should points their Maven tooling to
this settings file, or copy the profile into their ~/.m2/settings.xml.
-->
<id>spring</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--
Turns on jdk8 for tests
-->
<id>ide</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
</settings>

View File

@@ -0,0 +1 @@

File diff suppressed because it is too large Load Diff

View File

@@ -35,4 +35,4 @@ For now we're testing the performance impact of the following:
- our custom Trace HTTP filter
- instrumentation of controllers - `@Callable` returning and the sync one
- instrumentation of RestTemplate
- `@Async` annotated methods
- `@Async` annotated methods

View File

@@ -14,8 +14,8 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -249,7 +249,8 @@
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
<createDependencyReducedPom>false
</createDependencyReducedPom>
</configuration>
</execution>
</executions>
@@ -281,7 +282,9 @@
<goal>start</goal>
</goals>
<configuration>
<jvmArguments>"-Dserver.port=9875" "-Dspring.sleuth.enabled=false"</jvmArguments>
<jvmArguments>"-Dserver.port=9875"
"-Dspring.sleuth.enabled=false"
</jvmArguments>
<jmxPort>8875</jmxPort>
<fork>true</fork>
</configuration>
@@ -344,7 +347,8 @@
<suppressJMeterOutput>false</suppressJMeterOutput>
<ignoreResultFailures>true</ignoreResultFailures>
<propertiesJMeter>
<jmeter.save.saveservice.thread_counts>true</jmeter.save.saveservice.thread_counts>
<jmeter.save.saveservice.thread_counts>true
</jmeter.save.saveservice.thread_counts>
<sampleresult.useNanoTime>true</sampleresult.useNanoTime>
</propertiesJMeter>
<jmeterPlugins>
@@ -424,7 +428,9 @@
<artifactId>jmeter-analysis-maven-plugin</artifactId>
<version>1.0.6</version>
<configuration>
<targetDirectory>${project.build.directory}/jmeter/results/analysis/</targetDirectory>
<targetDirectory>
${project.build.directory}/jmeter/results/analysis/
</targetDirectory>
</configuration>
<executions>
<execution>
@@ -434,7 +440,9 @@
<goal>analyze</goal>
</goals>
<configuration>
<source>${project.build.directory}/jmeter/results/AsyncHttpBenchmarks.jtl</source>
<source>
${project.build.directory}/jmeter/results/AsyncHttpBenchmarks.jtl
</source>
</configuration>
</execution>
<execution>
@@ -444,7 +452,9 @@
<goal>analyze</goal>
</goals>
<configuration>
<source>${project.build.directory}/jmeter/results/AsyncMethodBenchmarks.jtl</source>
<source>
${project.build.directory}/jmeter/results/AsyncMethodBenchmarks.jtl
</source>
</configuration>
</execution>
<execution>
@@ -454,7 +464,9 @@
<goal>analyze</goal>
</goals>
<configuration>
<source>${project.build.directory}/jmeter/results/SyncHttpBenchmarks.jtl</source>
<source>
${project.build.directory}/jmeter/results/SyncHttpBenchmarks.jtl
</source>
</configuration>
</execution>
<execution>
@@ -464,7 +476,9 @@
<goal>analyze</goal>
</goals>
<configuration>
<source>${project.build.directory}/jmeter/results/*.jtl</source>
<source>
${project.build.directory}/jmeter/results/*.jtl
</source>
</configuration>
</execution>
</executions>
@@ -481,25 +495,34 @@
</goals>
<phase>verify</phase>
<configuration>
<inputFile>${project.build.directory}/jmeter/results/AsyncHttpBenchmarks.jtl</inputFile>
<inputFile>
${project.build.directory}/jmeter/results/AsyncHttpBenchmarks.jtl
</inputFile>
<graphs>
<graph>
<pluginType>ResponseTimesOverTime</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/AsyncHttpBenchmarks-ResponseTimesOverTime.png</outputFile>
<outputFile>
${project.build.directory}/jmeter/results/AsyncHttpBenchmarks-ResponseTimesOverTime.png
</outputFile>
</graph>
<graph>
<pluginType>ResponseTimesPercentiles</pluginType>
<pluginType>ResponseTimesPercentiles
</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/AsyncHttpBenchmarks-ResponseTimesPercentiles.png</outputFile>
<outputFile>
${project.build.directory}/jmeter/results/AsyncHttpBenchmarks-ResponseTimesPercentiles.png
</outputFile>
</graph>
<graph>
<pluginType>LatenciesOverTime</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/AsyncHttpBenchmarks-LatenciesOverTime.png</outputFile>
<outputFile>
${project.build.directory}/jmeter/results/AsyncHttpBenchmarks-LatenciesOverTime.png
</outputFile>
</graph>
</graphs>
</configuration>
@@ -511,25 +534,34 @@
</goals>
<phase>verify</phase>
<configuration>
<inputFile>${project.build.directory}/jmeter/results/AsyncMethodBenchmarks.jtl</inputFile>
<inputFile>
${project.build.directory}/jmeter/results/AsyncMethodBenchmarks.jtl
</inputFile>
<graphs>
<graph>
<pluginType>ResponseTimesOverTime</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/AsyncMethodBenchmarks-ResponseTimesOverTime.png</outputFile>
<outputFile>
${project.build.directory}/jmeter/results/AsyncMethodBenchmarks-ResponseTimesOverTime.png
</outputFile>
</graph>
<graph>
<pluginType>ResponseTimesPercentiles</pluginType>
<pluginType>ResponseTimesPercentiles
</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/AsyncMethodBenchmarks-ResponseTimesPercentiles.png</outputFile>
<outputFile>
${project.build.directory}/jmeter/results/AsyncMethodBenchmarks-ResponseTimesPercentiles.png
</outputFile>
</graph>
<graph>
<pluginType>LatenciesOverTime</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/AsyncMethodBenchmarks-LatenciesOverTime.png</outputFile>
<outputFile>
${project.build.directory}/jmeter/results/AsyncMethodBenchmarks-LatenciesOverTime.png
</outputFile>
</graph>
</graphs>
</configuration>
@@ -541,25 +573,34 @@
</goals>
<phase>verify</phase>
<configuration>
<inputFile>${project.build.directory}/jmeter/results/SyncHttpBenchmarks.jtl</inputFile>
<inputFile>
${project.build.directory}/jmeter/results/SyncHttpBenchmarks.jtl
</inputFile>
<graphs>
<graph>
<pluginType>ResponseTimesOverTime</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/SyncHttpBenchmarks-ResponseTimesOverTime.png</outputFile>
<outputFile>
${project.build.directory}/jmeter/results/SyncHttpBenchmarks-ResponseTimesOverTime.png
</outputFile>
</graph>
<graph>
<pluginType>ResponseTimesPercentiles</pluginType>
<pluginType>ResponseTimesPercentiles
</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/SyncHttpBenchmarks-ResponseTimesPercentiles.png</outputFile>
<outputFile>
${project.build.directory}/jmeter/results/SyncHttpBenchmarks-ResponseTimesPercentiles.png
</outputFile>
</graph>
<graph>
<pluginType>LatenciesOverTime</pluginType>
<width>800</width>
<height>600</height>
<outputFile>${project.build.directory}/jmeter/results/SyncHttpBenchmarks-LatenciesOverTime.png</outputFile>
<outputFile>
${project.build.directory}/jmeter/results/SyncHttpBenchmarks-LatenciesOverTime.png
</outputFile>
</graph>
</graphs>
</configuration>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -22,6 +22,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import javax.annotation.PreDestroy;
import brave.Span;
@@ -29,6 +30,7 @@ import brave.Tracer;
import brave.sampler.Sampler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
@@ -54,8 +56,8 @@ import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
@EnableAsync
public class SleuthBenchmarkingSpringApp implements
ApplicationListener<ServletWebServerInitializedEvent> {
public class SleuthBenchmarkingSpringApp
implements ApplicationListener<ServletWebServerInitializedEvent> {
private static final Log log = LogFactory.getLog(SleuthBenchmarkingSpringApp.class);
@@ -63,8 +65,15 @@ public class SleuthBenchmarkingSpringApp implements
public int port;
@Autowired(required = false) Tracer tracer;
@Autowired AClass aClass;
@Autowired(required = false)
Tracer tracer;
@Autowired
AClass aClass;
public static void main(String... args) {
SpringApplication.run(SleuthBenchmarkingSpringApp.class, args);
}
@RequestMapping("/foo")
public String foo() {
@@ -100,9 +109,11 @@ public class SleuthBenchmarkingSpringApp implements
}
@Bean
public ServletWebServerFactory servletContainer(@Value("${server.port:0}") int serverPort) {
public ServletWebServerFactory servletContainer(
@Value("${server.port:0}") int serverPort) {
log.info("Starting container at port [" + serverPort + "]");
return new TomcatServletWebServerFactory(serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
return new TomcatServletWebServerFactory(
serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}
@PreDestroy
@@ -110,21 +121,26 @@ public class SleuthBenchmarkingSpringApp implements
this.pool.shutdownNow();
}
@Bean Sampler alwaysSampler() {
@Bean
Sampler alwaysSampler() {
return Sampler.ALWAYS_SAMPLE;
}
@Bean AnotherClass anotherClass() {
@Bean
AnotherClass anotherClass() {
return new AnotherClass(this.tracer);
}
@Bean AClass aClass() {
@Bean
AClass aClass() {
return new AClass(this.tracer, anotherClass());
}
@Bean SkipPatternProvider patternProvider() {
@Bean
SkipPatternProvider patternProvider() {
return new SkipPatternProvider() {
@Override public Pattern skipPattern() {
@Override
public Pattern skipPattern() {
return Pattern.compile("");
}
};
@@ -134,12 +150,12 @@ public class SleuthBenchmarkingSpringApp implements
return this.pool;
}
public static void main(String... args) {
SpringApplication.run(SleuthBenchmarkingSpringApp.class, args);
}
}
class AClass {
private final Tracer tracer;
private final AnotherClass anotherClass;
AClass(Tracer tracer, AnotherClass anotherClass) {
@@ -151,7 +167,8 @@ class AClass {
Span manual = this.tracer.nextSpan().name("span-name");
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(manual.start())) {
return this.anotherClass.continuedSpan();
} finally {
}
finally {
manual.finish();
}
}
@@ -160,9 +177,11 @@ class AClass {
public String newSpan() {
return this.anotherClass.continuedAnnotation("bar");
}
}
class AnotherClass {
private final Tracer tracer;
AnotherClass(Tracer tracer) {
@@ -182,4 +201,5 @@ class AnotherClass {
span.annotate("continuedspan.after");
return response;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -14,14 +14,17 @@
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.app.webflux;
import brave.Tracer;
import java.util.regex.Pattern;
import brave.sampler.Sampler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import reactor.core.publisher.Mono;
import zipkin2.Span;
import zipkin2.reporter.Reporter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -34,24 +37,25 @@ import org.springframework.context.annotation.Bean;
import org.springframework.util.SocketUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import zipkin2.Span;
import zipkin2.reporter.Reporter;
import java.util.regex.Pattern;
/**
* @author alvin
*/
@SpringBootApplication
@RestController
public class SleuthBenchmarkingSpringWebFluxApp implements ApplicationListener<ReactiveWebServerInitializedEvent> {
public class SleuthBenchmarkingSpringWebFluxApp
implements ApplicationListener<ReactiveWebServerInitializedEvent> {
private static final Log log = LogFactory.getLog(SleuthBenchmarkingSpringWebFluxApp.class);
private static final Log log = LogFactory
.getLog(SleuthBenchmarkingSpringWebFluxApp.class);
public int port;
public static void main(String... args) {
new SpringApplicationBuilder(SleuthBenchmarkingSpringWebFluxApp.class)
.web(WebApplicationType.REACTIVE).application().run(args);
}
@RequestMapping("/foo")
public Mono<String> foo() {
return Mono.just("foo");
@@ -67,18 +71,12 @@ public class SleuthBenchmarkingSpringWebFluxApp implements ApplicationListener<R
return () -> Pattern.compile("");
}
@Bean
NettyReactiveWebServerFactory nettyReactiveWebServerFactory(@Value("${server.port:0}") int serverPort) {
NettyReactiveWebServerFactory nettyReactiveWebServerFactory(
@Value("${server.port:0}") int serverPort) {
log.info("Starting container at port [" + serverPort + "]");
return new NettyReactiveWebServerFactory(serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}
public static void main(String... args) {
new SpringApplicationBuilder(SleuthBenchmarkingSpringWebFluxApp.class)
.web(WebApplicationType.REACTIVE)
.application()
.run(args);
return new NettyReactiveWebServerFactory(
serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}
@Bean
@@ -86,11 +84,9 @@ public class SleuthBenchmarkingSpringWebFluxApp implements ApplicationListener<R
return Reporter.NOOP;
}
@Override
public void onApplicationEvent(ReactiveWebServerInitializedEvent event) {
this.port = event.getWebServer().getPort();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -30,6 +30,7 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp;
import org.springframework.context.ConfigurableApplicationContext;
@@ -44,35 +45,37 @@ import static org.assertj.core.api.BDDAssertions.then;
@Threads(Threads.MAX)
public class AnnotationBenchmarks {
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile SleuthBenchmarkingSpringApp sleuth;
@Setup public void setup() {
this.withSleuth = new SpringApplication(
SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.sleuth = this.withSleuth.getBean(
SleuthBenchmarkingSpringApp.class);
}
@TearDown public void clean() {
this.sleuth.clean();
this.withSleuth.close();
}
}
@Benchmark
public void manuallyCreatedSpans(BenchmarkContext context)
throws Exception {
public void manuallyCreatedSpans(BenchmarkContext context) throws Exception {
then(context.sleuth.manualSpan()).isEqualTo("continued");
}
@Benchmark
public void spanCreatedWithAnnotations(BenchmarkContext context)
throws Exception {
public void spanCreatedWithAnnotations(BenchmarkContext context) throws Exception {
then(context.sleuth.newSpan()).isEqualTo("continued");
}
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile SleuthBenchmarkingSpringApp sleuth;
@Setup
public void setup() {
this.withSleuth = new SpringApplication(SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.sleuth = this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class);
}
@TearDown
public void clean() {
this.sleuth.clean();
this.withSleuth.close();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.util.concurrent.TimeUnit;
@@ -29,6 +30,7 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp;
import org.springframework.context.ConfigurableApplicationContext;
@@ -43,47 +45,51 @@ import static org.assertj.core.api.BDDAssertions.then;
@Threads(Threads.MAX)
public class AsyncBenchmarks {
@Benchmark
public void asyncMethodWithoutSleuth(BenchmarkContext context) throws Exception {
then(context.untracedAsyncMethodHavingBean.async().get()).isEqualTo("async");
}
@Benchmark
public void asyncMethodWithSleuth(BenchmarkContext context) throws Exception {
then(context.tracedAsyncMethodHavingBean.async().get()).isEqualTo("async");
}
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile ConfigurableApplicationContext withoutSleuth;
volatile SleuthBenchmarkingSpringApp tracedAsyncMethodHavingBean;
volatile SleuthBenchmarkingSpringApp untracedAsyncMethodHavingBean;
@Setup public void setup() {
this.withSleuth = new SpringApplication(
SleuthBenchmarkingSpringApp.class)
@Setup
public void setup() {
this.withSleuth = new SpringApplication(SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.withoutSleuth = new SpringApplication(
SleuthBenchmarkingSpringApp.class)
this.withoutSleuth = new SpringApplication(SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withoutSleuth",
"--spring.sleuth.enabled=false",
"--spring.sleuth.async.enabled=false");
this.tracedAsyncMethodHavingBean = this.withSleuth.getBean(
SleuthBenchmarkingSpringApp.class);
this.untracedAsyncMethodHavingBean = this.withoutSleuth.getBean(
SleuthBenchmarkingSpringApp.class);
this.tracedAsyncMethodHavingBean = this.withSleuth
.getBean(SleuthBenchmarkingSpringApp.class);
this.untracedAsyncMethodHavingBean = this.withoutSleuth
.getBean(SleuthBenchmarkingSpringApp.class);
}
@TearDown public void clean() {
@TearDown
public void clean() {
this.tracedAsyncMethodHavingBean.clean();
this.untracedAsyncMethodHavingBean.clean();
this.withSleuth.close();
this.withoutSleuth.close();
}
}
@Benchmark
public void asyncMethodWithoutSleuth(BenchmarkContext context)
throws Exception {
then(context.untracedAsyncMethodHavingBean.async().get()).isEqualTo("async");
}
@Benchmark
public void asyncMethodWithSleuth(BenchmarkContext context)
throws Exception {
then(context.tracedAsyncMethodHavingBean.async().get()).isEqualTo("async");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -38,6 +40,7 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp;
import org.springframework.context.ConfigurableApplicationContext;
@@ -65,35 +68,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@Threads(Threads.MAX)
public class HttpFilterBenchmarks {
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile DummyFilter dummyFilter = new DummyFilter();
volatile TracingFilter tracingFilter;
volatile MockMvc mockMvcForTracedController;
volatile MockMvc mockMvcForUntracedController;
@Setup public void setup() {
this.withSleuth = new SpringApplication(
SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.tracingFilter = this.withSleuth.getBean(TracingFilter.class);
this.mockMvcForTracedController = MockMvcBuilders.standaloneSetup(
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class))
.build();
this.mockMvcForUntracedController = MockMvcBuilders.standaloneSetup(
new VanillaController())
.build();
}
@TearDown public void clean() {
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class).clean();
this.withSleuth.close();
}
}
@Benchmark
@Measurement(iterations = 5, time = 1)
@Fork(3)
@@ -133,38 +107,80 @@ public class HttpFilterBenchmarks {
}
private MockHttpServletRequestBuilder builder() {
return get("/").accept(MediaType.APPLICATION_JSON)
.header("User-Agent", "MockMvc");
return get("/").accept(MediaType.APPLICATION_JSON).header("User-Agent",
"MockMvc");
}
private void performRequest(MockMvc mockMvc, String url, String expectedResult) throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/" + url))
.andExpect(status().isOk())
.andExpect(request().asyncStarted())
.andReturn();
private void performRequest(MockMvc mockMvc, String url, String expectedResult)
throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/" + url)).andExpect(status().isOk())
.andExpect(request().asyncStarted()).andReturn();
mockMvc.perform(asyncDispatch(mvcResult))
.andExpect(status().isOk())
mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk())
.andExpect(content().string(expectedResult));
}
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile DummyFilter dummyFilter = new DummyFilter();
volatile TracingFilter tracingFilter;
volatile MockMvc mockMvcForTracedController;
volatile MockMvc mockMvcForUntracedController;
@Setup
public void setup() {
this.withSleuth = new SpringApplication(SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.tracingFilter = this.withSleuth.getBean(TracingFilter.class);
this.mockMvcForTracedController = MockMvcBuilders
.standaloneSetup(
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class))
.build();
this.mockMvcForUntracedController = MockMvcBuilders
.standaloneSetup(new VanillaController()).build();
}
@TearDown
public void clean() {
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class).clean();
this.withSleuth.close();
}
}
private static class DummyFilter implements Filter {
@Override public void init(FilterConfig filterConfig) throws ServletException {}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override public void doFilter(ServletRequest request, ServletResponse response,
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
@Override public void destroy() { }
@Override
public void destroy() {
}
}
@RestController
private static class VanillaController {
@RequestMapping("/vanilla")
public Callable<String> vanilla() {
return () -> "vanilla";
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2019 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.io.BufferedReader;
@@ -35,10 +36,15 @@ import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpr
public class ProcessLauncherState {
private Process started;
private List<String> args;
private List<String> extraArgs;
private File home;
private String mainClass = SleuthBenchmarkingSpringApp.class.getName();
private int length;
public ProcessLauncherState(String dir, String... args) {
@@ -58,6 +64,21 @@ public class ProcessLauncherState {
this.home = new File(dir);
}
protected static String output(InputStream inputStream, String marker)
throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while ((line = br.readLine()) != null && !line.contains(marker)) {
sb.append(line + System.getProperty("line.separator"));
}
if (line != null) {
sb.append(line + System.getProperty("line.separator"));
}
return sb.toString();
}
public void setMainClass(String mainClass) {
this.mainClass = mainClass;
}
@@ -101,7 +122,7 @@ public class ProcessLauncherState {
public void run() throws Exception {
List<String> args = new ArrayList<>(this.args);
args.add(args.size() - this.length, this.mainClass);
if (extraArgs!=null) {
if (extraArgs != null) {
args.addAll(extraArgs);
}
ProcessBuilder builder = new ProcessBuilder(args);
@@ -122,22 +143,8 @@ public class ProcessLauncherState {
System.out.println(output(started.getInputStream(), "Started"));
}
protected static String output(InputStream inputStream, String marker)
throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while ((line = br.readLine()) != null && !line.contains(marker)) {
sb.append(line + System.getProperty("line.separator"));
}
if (line != null) {
sb.append(line + System.getProperty("line.separator"));
}
return sb.toString();
}
public File getHome() {
return home;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import brave.spring.web.TracingClientHttpRequestInterceptor;
@@ -33,6 +35,7 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.sleuth.benchmarks.app.mvc.SleuthBenchmarkingSpringApp;
import org.springframework.context.ConfigurableApplicationContext;
@@ -44,8 +47,7 @@ import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.BDDAssertions.then;
/**
* We're checking how much overhead does the instrumentation
* of the RestTemplate take
* We're checking how much overhead does the instrumentation of the RestTemplate take
*/
@Measurement(iterations = 5)
@Warmup(iterations = 10)
@@ -55,20 +57,37 @@ import static org.assertj.core.api.BDDAssertions.then;
@Threads(Threads.MAX)
public class RestTemplateBenchmark {
@Benchmark
public void syncEndpointWithoutSleuth(BenchmarkContext context)
throws IOException, ServletException {
then(context.untracedTemplate.getForObject("/foo", String.class))
.isEqualTo("foo");
}
@Benchmark
public void syncEndpointWithSleuth(BenchmarkContext context)
throws ServletException, IOException {
then(context.tracedTemplate.getForObject("/foo", String.class)).isEqualTo("foo");
}
@State(Scope.Benchmark)
public static class BenchmarkContext {
volatile ConfigurableApplicationContext withSleuth;
volatile MockMvc mockMvc;
volatile RestTemplate tracedTemplate;
volatile RestTemplate untracedTemplate;
@Setup public void setup() {
new SpringApplication(
SleuthBenchmarkingSpringApp.class)
.run("--spring.jmx.enabled=false",
"--spring.application.name=withSleuth");
this.mockMvc = MockMvcBuilders.standaloneSetup(
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class))
@Setup
public void setup() {
new SpringApplication(SleuthBenchmarkingSpringApp.class).run(
"--spring.jmx.enabled=false", "--spring.application.name=withSleuth");
this.mockMvc = MockMvcBuilders
.standaloneSetup(
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class))
.build();
this.tracedTemplate = new RestTemplate(
new MockMvcClientHttpRequestFactory(this.mockMvc));
@@ -78,22 +97,12 @@ public class RestTemplateBenchmark {
new MockMvcClientHttpRequestFactory(this.mockMvc));
}
@TearDown public void clean() {
@TearDown
public void clean() {
this.withSleuth.getBean(SleuthBenchmarkingSpringApp.class).clean();
this.withSleuth.close();
}
}
@Benchmark
public void syncEndpointWithoutSleuth(BenchmarkContext context)
throws IOException, ServletException {
then(context.untracedTemplate.getForObject("/foo", String.class)).isEqualTo("foo");
}
@Benchmark
public void syncEndpointWithSleuth(BenchmarkContext context)
throws ServletException, IOException {
then(context.tracedTemplate.getForObject("/foo", String.class)).isEqualTo("foo");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,8 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.httpclient.TracingHttpClientBuilder;
@@ -41,15 +45,13 @@ import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import zipkin2.reporter.Reporter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.sleuth.benchmarks.app.webflux.SleuthBenchmarkingSpringWebFluxApp;
import org.springframework.context.ConfigurableApplicationContext;
import zipkin2.reporter.Reporter;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 10, time = 1)
@@ -60,31 +62,34 @@ import java.util.concurrent.TimeUnit;
@State(Scope.Benchmark)
public class SpringWebFluxBenchmarks {
protected static TraceContext defaultTraceContext = TraceContext.newBuilder()
.traceIdHigh(333L).traceId(444L).spanId(3).sampled(true).build();
protected ConfigurableApplicationContext applicationContext;
protected SleuthBenchmarkingSpringWebFluxApp springWebFluxApp;
CloseableHttpClient client;
CloseableHttpClient tracedClient;
CloseableHttpClient unsampledClient;
private String baseUrl;
protected static TraceContext defaultTraceContext =
TraceContext.newBuilder().traceIdHigh(333L).traceId(444L).spanId(3).sampled(true).build();
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + SpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
public String getBaseUrl() {
return baseUrl;
}
private String baseUrl;
protected CloseableHttpClient newClient(HttpTracing httpTracing) {
return TracingHttpClientBuilder.create(httpTracing)
.disableAutomaticRetries()
return TracingHttpClientBuilder.create(httpTracing).disableAutomaticRetries()
.build();
}
protected CloseableHttpClient newClient() {
return HttpClients.custom()
.disableAutomaticRetries()
.build();
return HttpClients.custom().disableAutomaticRetries().build();
}
protected void get(CloseableHttpClient client) throws Exception {
@@ -95,31 +100,27 @@ public class SpringWebFluxBenchmarks {
client.close();
}
@Setup
public void setup() {
ConfigurableApplicationContext context = initContext();
this.applicationContext = context;
this.springWebFluxApp = this.applicationContext.getBean(
SleuthBenchmarkingSpringWebFluxApp.class);
this.springWebFluxApp = this.applicationContext
.getBean(SleuthBenchmarkingSpringWebFluxApp.class);
baseUrl = "http://127.0.0.1:" + springWebFluxApp.port + "/foo";
client = newClient();
tracedClient = newClient(HttpTracing.create(
Tracing.newBuilder().spanReporter(Reporter.NOOP).build()
));
unsampledClient = newClient(HttpTracing.create(
Tracing.newBuilder().sampler(Sampler.NEVER_SAMPLE).spanReporter(Reporter.NOOP).build()
));
tracedClient = newClient(HttpTracing
.create(Tracing.newBuilder().spanReporter(Reporter.NOOP).build()));
unsampledClient = newClient(HttpTracing.create(Tracing.newBuilder()
.sampler(Sampler.NEVER_SAMPLE).spanReporter(Reporter.NOOP).build()));
postSetUp();
}
protected ConfigurableApplicationContext initContext() {
SpringApplication application = new SpringApplicationBuilder(SleuthBenchmarkingSpringWebFluxApp.class)
.web(WebApplicationType.REACTIVE)
.application();
SpringApplication application = new SpringApplicationBuilder(
SleuthBenchmarkingSpringWebFluxApp.class).web(WebApplicationType.REACTIVE)
.application();
customSpringApplication(application);
return application
.run(runArgs());
return application.run(runArgs());
}
protected void customSpringApplication(SpringApplication springApplication) {
@@ -129,14 +130,12 @@ public class SpringWebFluxBenchmarks {
protected void postSetUp() {
}
protected String[] runArgs() {
return new String[]{"--spring.jmx.enabled=false",
return new String[] { "--spring.jmx.enabled=false",
"--spring.application.name=defaultTraceContext",
"--spring.sleuth.enabled=true"};
"--spring.sleuth.enabled=true" };
}
@TearDown
public void clean() throws Exception {
close(client);
@@ -146,7 +145,8 @@ public class SpringWebFluxBenchmarks {
try {
this.applicationContext.close();
} catch (Exception ig) {
}
catch (Exception ig) {
}
}
@@ -168,18 +168,10 @@ public class SpringWebFluxBenchmarks {
@Benchmark
public void tracedClient_get_resumeTrace() throws Exception {
try (CurrentTraceContext.Scope scope = Tracing.current().currentTraceContext().newScope(defaultTraceContext)) {
try (CurrentTraceContext.Scope scope = Tracing.current().currentTraceContext()
.newScope(defaultTraceContext)) {
get(tracedClient);
}
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + SpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2019 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import org.openjdk.jmh.annotations.Benchmark;
@@ -42,27 +43,34 @@ public class StartupBenchmark {
state.setExtraArgs("--spring.sleuth.annotation.enabled=false");
state.run();
}
@Benchmark
public void withoutAsync(ApplicationState state) throws Exception {
state.setExtraArgs("--spring.sleuth.async.enabled=false", "--spring.sleuth.annotation.enabled=false");
state.setExtraArgs("--spring.sleuth.async.enabled=false",
"--spring.sleuth.annotation.enabled=false");
state.run();
}
@Benchmark
public void withoutScheduled(ApplicationState state) throws Exception {
state.setExtraArgs("--spring.sleuth.scheduled.enabled=false", "--spring.sleuth.async.enabled=false", "--spring.sleuth.annotation.enabled=false");
state.setExtraArgs("--spring.sleuth.scheduled.enabled=false",
"--spring.sleuth.async.enabled=false",
"--spring.sleuth.annotation.enabled=false");
state.run();
}
@Benchmark
public void withoutWeb(ApplicationState state) throws Exception {
state.setExtraArgs("--spring.sleuth.web.enabled=false", "--spring.sleuth.scheduled.enabled=false", "--spring.sleuth.async.enabled=false", "--spring.sleuth.annotation.enabled=false");
state.setExtraArgs("--spring.sleuth.web.enabled=false",
"--spring.sleuth.scheduled.enabled=false",
"--spring.sleuth.async.enabled=false",
"--spring.sleuth.annotation.enabled=false");
state.run();
}
@State(Scope.Benchmark)
public static class ApplicationState extends ProcessLauncherState {
public ApplicationState() {
super("target", "--server.port=0");
}
@@ -71,6 +79,7 @@ public class StartupBenchmark {
public void stop() throws Exception {
super.after();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import org.openjdk.jmh.runner.Runner;
@@ -25,12 +26,20 @@ import org.openjdk.jmh.runner.options.OptionsBuilder;
*/
public class WithOutReactorSleuthSpringWebFluxBenchmarks extends SpringWebFluxBenchmarks {
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder().include(
".*" + WithOutReactorSleuthSpringWebFluxBenchmarks.class.getSimpleName()
+ ".*")
.build();
new Runner(opt).run();
}
@Override
protected String[] runArgs() {
return new String[]{"--spring.jmx.enabled=false",
return new String[] { "--spring.jmx.enabled=false",
"--spring.application.name=defaultTraceContext",
"--spring.sleuth.enabled=true",
"--spring.sleuth.reactor.enabled=false"
"--spring.sleuth.enabled=true", "--spring.sleuth.reactor.enabled=false"
};
}
@@ -40,11 +49,4 @@ public class WithOutReactorSleuthSpringWebFluxBenchmarks extends SpringWebFluxBe
super.postSetUp();
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + WithOutReactorSleuthSpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.benchmarks.jmh.benchmarks;
import org.openjdk.jmh.runner.Runner;
@@ -25,11 +26,19 @@ import org.openjdk.jmh.runner.options.OptionsBuilder;
*/
public class WithOutSleuthSpringWebFluxBenchmarks extends SpringWebFluxBenchmarks {
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder().include(
".*" + WithOutSleuthSpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
@Override
protected String[] runArgs() {
return new String[]{"--spring.jmx.enabled=false",
return new String[] { "--spring.jmx.enabled=false",
"--spring.application.name=defaultTraceContext",
"--spring.sleuth.enabled=false"};
"--spring.sleuth.enabled=false" };
}
@Override
@@ -37,11 +46,4 @@ public class WithOutSleuthSpringWebFluxBenchmarks extends SpringWebFluxBenchmark
super.postSetUp();
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + WithOutSleuthSpringWebFluxBenchmarks.class.getSimpleName() + ".*")
.build();
new Runner(opt).run();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -26,9 +26,11 @@ public class RunSleuthJmhBenchmarksFromIde {
// Convenience main entry-point for testing from IDE
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(RunSleuthJmhBenchmarksFromIde.class.getPackage().getName() + ".benchmarks.*")
.include(RunSleuthJmhBenchmarksFromIde.class.getPackage().getName()
+ ".benchmarks.*")
.build();
new Runner(opt).run();
}
}
}

View File

@@ -13,5 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
sampleresult.useNanoTime=true

View File

@@ -15,8 +15,9 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
@@ -30,7 +31,8 @@
<properties>
<docs.main>spring-cloud-sleuth</docs.main>
<!-- Comma separated list of whitelisted branches -->
<docs.whitelisted.branches>1.0.x,1.1.x,1.2.x,1.3.x,2.0.x</docs.whitelisted.branches>
<docs.whitelisted.branches>1.0.x,1.1.x,1.2.x,1.3.x,2.0.x
</docs.whitelisted.branches>
<main.basedir>${basedir}/..</main.basedir>
</properties>
<profiles>

View File

@@ -327,4 +327,4 @@ build_docs_if_applicable
retrieve_doc_properties
stash_changes
add_docs_from_target
checkout_previous_branch
checkout_previous_branch

View File

@@ -0,0 +1 @@

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 KiB

After

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

After

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 116 KiB

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 KiB

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

39
pom.xml
View File

@@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -36,8 +36,11 @@
<scm>
<url>https://github.com/spring-cloud/spring-cloud-sleuth</url>
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-sleuth.git</connection>
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-sleuth.git</developerConnection>
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-sleuth.git
</connection>
<developerConnection>
scm:git:ssh://git@github.com/spring-cloud/spring-cloud-sleuth.git
</developerConnection>
<tag>HEAD</tag>
</scm>
@@ -111,14 +114,14 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
@@ -210,7 +213,7 @@
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.1</version>
<!-- not test because we need it in stream -->
<!-- not test because we need it in stream -->
</dependency>
<dependency>
<groupId>commons-logging</groupId>
@@ -254,9 +257,17 @@
<spring-cloud-gateway.version>2.1.1.BUILD-SNAPSHOT</spring-cloud-gateway.version>
<spring-cloud-stream.version>Fishtown.BUILD-SNAPSHOT</spring-cloud-stream.version>
<spring-cloud-netflix.version>2.1.1.BUILD-SNAPSHOT</spring-cloud-netflix.version>
<spring-cloud-openfeign.version>2.1.1.BUILD-SNAPSHOT</spring-cloud-openfeign.version>
<spring-cloud-openfeign.version>2.1.1.BUILD-SNAPSHOT
</spring-cloud-openfeign.version>
<brave.version>5.6.1</brave.version>
<spring-security-boot-autoconfigure.version>2.1.2.RELEASE</spring-security-boot-autoconfigure.version>
<spring-security-boot-autoconfigure.version>2.1.2.RELEASE
</spring-security-boot-autoconfigure.version>
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
<maven-checkstyle-plugin.failsOnViolation>true
</maven-checkstyle-plugin.failsOnViolation>
<maven-checkstyle-plugin.includeTestSourceDirectory>true
</maven-checkstyle-plugin.includeTestSourceDirectory>
</properties>
<profiles>
@@ -376,7 +387,8 @@
</goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
<destFile>${project.build.directory}/jacoco.exec</destFile>
<destFile>${project.build.directory}/jacoco.exec
</destFile>
</configuration>
</execution>
<execution>
@@ -387,7 +399,8 @@
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<dataFile>${project.build.directory}/jacoco.exec
</dataFile>
</configuration>
</execution>
</executions>

View File

@@ -6,4 +6,4 @@ pkill -f SleuthBenchmarkingSpringApp || echo "No apps to kill"
echo "Running JMeter Benchmarks"
./mvnw clean verify --projects benchmarks --also-make -Pbenchmarks,jmeter
echo "Killing the remaining apps - if something went wrong after the tests"
pkill -f SleuthBenchmarkingSpringApp || echo "No apps to kill"
pkill -f SleuthBenchmarkingSpringApp || echo "No apps to kill"

View File

@@ -2,4 +2,4 @@
echo "Running JMH Benchmarks"
./mvnw clean install -DskipTests --projects benchmarks --also-make -Pbenchmarks,jmh
java -Djmh.ignoreLock=true -jar benchmarks/target/benchmarks.jar org.springframework.cloud.sleuth.benchmarks.jmh.* -rf csv -rff jmh-result.csv | tee target/benchmarks.log
java -Djmh.ignoreLock=true -jar benchmarks/target/benchmarks.jar org.springframework.cloud.sleuth.benchmarks.jmh.* -rf csv -rff jmh-result.csv | tee target/benchmarks.log

View File

@@ -15,8 +15,9 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-sleuth-core</artifactId>
@@ -334,10 +335,10 @@
</dependency>
<!-- This forces the guava version to 20 within the test scope, which is required by GRPC -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
<scope>test</scope>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -45,6 +45,14 @@ import org.springframework.core.annotation.AnnotationUtils;
*/
public class DefaultSpanNamer implements SpanNamer {
private static boolean isDefaultToString(Object delegate, String spanName) {
if (delegate instanceof Method) {
return delegate.toString().equals(spanName);
}
return (delegate.getClass().getName() + "@"
+ Integer.toHexString(delegate.hashCode())).equals(spanName);
}
@Override
public String name(Object object, String defaultValue) {
SpanName annotation = annotation(object);
@@ -63,12 +71,4 @@ public class DefaultSpanNamer implements SpanNamer {
return AnnotationUtils.findAnnotation(o.getClass(), SpanName.class);
}
private static boolean isDefaultToString(Object delegate, String spanName) {
if (delegate instanceof Method) {
return delegate.toString().equals(spanName);
}
return (delegate.getClass().getName() + "@"
+ Integer.toHexString(delegate.hashCode())).equals(spanName);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -21,12 +21,13 @@ import brave.Tracer;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
/**
* Sleuth annotation processor
* Sleuth annotation processor.
*
* @author Marcin Grzejszczak
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -31,7 +31,7 @@ import java.lang.annotation.Target;
*/
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Target(value = { ElementType.METHOD })
@Target(ElementType.METHOD)
public @interface ContinueSpan {
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,12 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.annotation;
import brave.SpanCustomizer;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.sleuth.util.SpanNameUtil;
import org.springframework.util.StringUtils;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.annotation;
import java.lang.annotation.ElementType;
@@ -38,7 +39,7 @@ import org.springframework.core.annotation.AliasFor;
*/
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Target(value = { ElementType.METHOD })
@Target(ElementType.METHOD)
public @interface NewSpan {
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -29,9 +29,9 @@ public interface NewSpanParser {
/**
* Override to control the name and tags on an annotation-based span.
* @param methodInvocation
* @param newSpan
* @param span
* @param methodInvocation method invocation annotated with new span
* @param newSpan meta data of the new span
* @param span span to customize
*/
void parse(MethodInvocation methodInvocation, NewSpan newSpan, SpanCustomizer span);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -19,6 +19,7 @@ package org.springframework.cloud.sleuth.annotation;
import brave.Span;
import brave.Tracer;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.util.StringUtils;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -45,10 +45,10 @@ import org.springframework.util.StringUtils;
class ReactorSleuthMethodInvocationProcessor
extends AbstractSleuthMethodInvocationProcessor {
private NonReactorSleuthMethodInvocationProcessor nonReactorSleuthMethodInvocationProcessor;
Tracing tracing;
private NonReactorSleuthMethodInvocationProcessor nonReactorSleuthMethodInvocationProcessor;
Tracing tracing() {
if (this.tracing == null) {
this.tracing = this.beanFactory.getBean(Tracing.class);
@@ -100,6 +100,19 @@ class ReactorSleuthMethodInvocationProcessor
}
}
private boolean isReactorReturnType(Class<?> returnType) {
return Flux.class.equals(returnType) || Mono.class.equals(returnType);
}
private NonReactorSleuthMethodInvocationProcessor nonReactorSleuthMethodInvocationProcessor() {
if (this.nonReactorSleuthMethodInvocationProcessor == null) {
this.nonReactorSleuthMethodInvocationProcessor = new NonReactorSleuthMethodInvocationProcessor();
this.nonReactorSleuthMethodInvocationProcessor
.setBeanFactory(this.beanFactory);
}
return this.nonReactorSleuthMethodInvocationProcessor;
}
private static final class FluxSpan extends FluxOperator<Object, Object> {
final Span span;
@@ -307,17 +320,4 @@ class ReactorSleuthMethodInvocationProcessor
}
private boolean isReactorReturnType(Class<?> returnType) {
return Flux.class.equals(returnType) || Mono.class.equals(returnType);
}
private NonReactorSleuthMethodInvocationProcessor nonReactorSleuthMethodInvocationProcessor() {
if (this.nonReactorSleuthMethodInvocationProcessor == null) {
this.nonReactorSleuthMethodInvocationProcessor = new NonReactorSleuthMethodInvocationProcessor();
this.nonReactorSleuthMethodInvocationProcessor
.setBeanFactory(this.beanFactory);
}
return this.nonReactorSleuthMethodInvocationProcessor;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -19,10 +19,12 @@ package org.springframework.cloud.sleuth.annotation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.PostConstruct;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.IntroductionInterceptor;
import org.springframework.aop.Pointcut;
@@ -87,6 +89,34 @@ class SleuthAdvisorConfig extends AbstractPointcutAdvisor implements BeanFactory
return new AnnotationClassOrMethodOrArgsPointcut();
}
/**
* Checks if a method is properly annotated with a given Sleuth annotation.
*/
private static class AnnotationMethodsResolver {
private final Class<? extends Annotation> annotationType;
AnnotationMethodsResolver(Class<? extends Annotation> annotationType) {
this.annotationType = annotationType;
}
boolean hasAnnotatedMethods(Class<?> clazz) {
final AtomicBoolean found = new AtomicBoolean(false);
ReflectionUtils.doWithMethods(clazz, (method -> {
if (found.get()) {
return;
}
Annotation annotation = AnnotationUtils.findAnnotation(method,
AnnotationMethodsResolver.this.annotationType);
if (annotation != null) {
found.set(true);
}
}));
return found.get();
}
}
/**
* Checks if a class or a method is is annotated with Sleuth related annotations.
*/
@@ -130,34 +160,6 @@ class SleuthAdvisorConfig extends AbstractPointcutAdvisor implements BeanFactory
}
/**
* Checks if a method is properly annotated with a given Sleuth annotation.
*/
private static class AnnotationMethodsResolver {
private final Class<? extends Annotation> annotationType;
AnnotationMethodsResolver(Class<? extends Annotation> annotationType) {
this.annotationType = annotationType;
}
boolean hasAnnotatedMethods(Class<?> clazz) {
final AtomicBoolean found = new AtomicBoolean(false);
ReflectionUtils.doWithMethods(clazz, (method -> {
if (found.get()) {
return;
}
Annotation annotation = AnnotationUtils.findAnnotation(method,
AnnotationMethodsResolver.this.annotationType);
if (annotation != null) {
found.set(true);
}
}));
return found.get();
}
}
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.annotation;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.annotation;
import brave.Tracing;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.annotation.AnnotationUtils;
/**
@@ -32,14 +33,14 @@ import org.springframework.core.annotation.AnnotationUtils;
* @author Christian Schwerdtfeger
* @since 1.2.0
*/
class SleuthAnnotationUtils {
final class SleuthAnnotationUtils {
private static final Log log = LogFactory.getLog(SleuthAnnotationUtils.class);
private SleuthAnnotationUtils() {
}
private static final Log log = LogFactory.getLog(SleuthAnnotationUtils.class);
static boolean isMethodAnnotated(Method method) {
return findAnnotation(method, NewSpan.class) != null
|| findAnnotation(method, ContinueSpan.class) != null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -40,7 +40,7 @@ import org.springframework.core.annotation.AliasFor;
*/
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Target(value = { ElementType.PARAMETER })
@Target(ElementType.PARAMETER)
public @interface SpanTag {
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -24,6 +24,7 @@ import brave.SpanCustomizer;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.util.StringUtils;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -18,6 +18,7 @@ package org.springframework.cloud.sleuth.annotation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -38,7 +38,6 @@ import zipkin2.reporter.InMemoryReporterMetrics;
import zipkin2.reporter.Reporter;
import zipkin2.reporter.ReporterMetrics;
import org.springframework.lang.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -49,6 +48,7 @@ import org.springframework.cloud.sleuth.SpanAdjuster;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -110,66 +110,6 @@ public class TraceAutoConfiguration {
return builder.build();
}
private static class CompositeReporter implements Reporter<zipkin2.Span> {
private static final Log log = LogFactory.getLog(CompositeReporter.class);
private final List<SpanAdjuster> spanAdjusters;
private final Reporter<zipkin2.Span> spanReporter;
private CompositeReporter(List<SpanAdjuster> spanAdjusters,
List<Reporter<Span>> spanReporters) {
this.spanAdjusters = spanAdjusters;
this.spanReporter = spanReporters.size() == 1 ? spanReporters.get(0)
: new ListReporter(spanReporters);
}
private static class ListReporter implements Reporter<zipkin2.Span> {
private final List<Reporter<Span>> spanReporters;
private ListReporter(List<Reporter<Span>> spanReporters) {
this.spanReporters = spanReporters;
}
@Override
public void report(Span span) {
for (Reporter<zipkin2.Span> spanReporter : this.spanReporters) {
try {
spanReporter.report(span);
}
catch (Exception ex) {
log.warn("Exception occurred while trying to report the span "
+ span, ex);
}
}
}
@Override
public String toString() {
return "ListReporter{" + "spanReporters=" + this.spanReporters + '}';
}
}
@Override
public void report(Span span) {
Span spanToAdjust = span;
for (SpanAdjuster spanAdjuster : this.spanAdjusters) {
spanToAdjust = spanAdjuster.adjust(spanToAdjust);
}
this.spanReporter.report(spanToAdjust);
}
@Override
public String toString() {
return "CompositeReporter{" + "spanAdjusters=" + this.spanAdjusters
+ ", spanReporters=" + this.spanReporter + '}';
}
}
@Bean(name = TRACER_BEAN_NAME)
@ConditionalOnMissingBean
Tracer tracer(Tracing tracing) {
@@ -257,4 +197,64 @@ public class TraceAutoConfiguration {
return CurrentSpanCustomizer.create(tracing);
}
private static final class CompositeReporter implements Reporter<zipkin2.Span> {
private static final Log log = LogFactory.getLog(CompositeReporter.class);
private final List<SpanAdjuster> spanAdjusters;
private final Reporter<zipkin2.Span> spanReporter;
private CompositeReporter(List<SpanAdjuster> spanAdjusters,
List<Reporter<Span>> spanReporters) {
this.spanAdjusters = spanAdjusters;
this.spanReporter = spanReporters.size() == 1 ? spanReporters.get(0)
: new ListReporter(spanReporters);
}
@Override
public void report(Span span) {
Span spanToAdjust = span;
for (SpanAdjuster spanAdjuster : this.spanAdjusters) {
spanToAdjust = spanAdjuster.adjust(spanToAdjust);
}
this.spanReporter.report(spanToAdjust);
}
@Override
public String toString() {
return "CompositeReporter{" + "spanAdjusters=" + this.spanAdjusters
+ ", spanReporters=" + this.spanReporter + '}';
}
private static final class ListReporter implements Reporter<zipkin2.Span> {
private final List<Reporter<Span>> spanReporters;
private ListReporter(List<Reporter<Span>> spanReporters) {
this.spanReporters = spanReporters;
}
@Override
public void report(Span span) {
for (Reporter<zipkin2.Span> spanReporter : this.spanReporters) {
try {
spanReporter.report(span);
}
catch (Exception ex) {
log.warn("Exception occurred while trying to report the span "
+ span, ex);
}
}
}
@Override
public String toString() {
return "ListReporter{" + "spanReporters=" + this.spanReporters + '}';
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -48,8 +48,8 @@ public class TraceEnvironmentPostProcessor implements EnvironmentPostProcessor {
// traces in logs without having to configure it.
if (Boolean
.parseBoolean(environment.getProperty("spring.sleuth.enabled", "true"))) {
map.put("logging.pattern.level",
"%5p [${spring.zipkin.service.name:${spring.application.name:-}},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]");
map.put("logging.pattern.level", "%5p [${spring.zipkin.service.name:"
+ "${spring.application.name:-}},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]");
}
addOrReplace(environment.getPropertySources(), map);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -32,10 +32,10 @@ import org.springframework.context.event.SmartApplicationListener;
class ContextRefreshedListener extends AtomicBoolean implements SmartApplicationListener {
private static final Log log = LogFactory.getLog(ContextRefreshedListener.class);
static final Map<BeanFactory, ContextRefreshedListener> CACHE = new ConcurrentHashMap<>();
private static final Log log = LogFactory.getLog(ContextRefreshedListener.class);
ContextRefreshedListener(boolean initialValue) {
super(initialValue);
}
@@ -44,6 +44,10 @@ class ContextRefreshedListener extends AtomicBoolean implements SmartApplication
this(false);
}
static ContextRefreshedListener getBean(BeanFactory beanFactory) {
return CACHE.getOrDefault(beanFactory, new ContextRefreshedListener(false));
}
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
return ContextRefreshedEvent.class.isAssignableFrom(eventType);
@@ -67,8 +71,4 @@ class ContextRefreshedListener extends AtomicBoolean implements SmartApplication
}
}
static ContextRefreshedListener getBean(BeanFactory beanFactory) {
return CACHE.getOrDefault(beanFactory, new ContextRefreshedListener(false));
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -27,7 +27,11 @@ import org.springframework.beans.factory.BeanFactory;
* @author Marcin Grzejszczak
* @since 2.1.0
*/
class ContextUtil {
final class ContextUtil {
private ContextUtil() {
throw new IllegalStateException("Can't instantiate a utility class");
}
private static final Log log = LogFactory.getLog(ContextUtil.class);
@@ -39,4 +43,4 @@ class ContextUtil {
return !contextRefreshed;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -28,7 +28,7 @@ import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.SpanNamer;
/**
* {@link Executor} that wraps {@link Runnable} in a trace representation
* {@link Executor} that wraps {@link Runnable} in a trace representation.
*
* @author Dave Syer
* @since 1.0.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -35,7 +35,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.concurrent.ListenableFuture;
/**
* Trace representation of {@link ThreadPoolTaskExecutor}
* Trace representation of {@link ThreadPoolTaskExecutor}.
*
* @author Marcin Grzejszczak
* @since 1.0.10
@@ -108,11 +108,6 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
this.delegate.setThreadFactory(threadFactory);
}
@Override
public void setThreadNamePrefix(String threadNamePrefix) {
this.delegate.setThreadNamePrefix(threadNamePrefix);
}
@Override
public void setRejectedExecutionHandler(
RejectedExecutionHandler rejectedExecutionHandler) {
@@ -185,8 +180,8 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
}
@Override
public void setThreadPriority(int threadPriority) {
this.delegate.setThreadPriority(threadPriority);
public void setThreadNamePrefix(String threadNamePrefix) {
this.delegate.setThreadNamePrefix(threadNamePrefix);
}
@Override
@@ -195,8 +190,8 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
}
@Override
public void setDaemon(boolean daemon) {
this.delegate.setDaemon(daemon);
public void setThreadPriority(int threadPriority) {
this.delegate.setThreadPriority(threadPriority);
}
@Override
@@ -205,13 +200,13 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
}
@Override
public void setThreadGroupName(String name) {
this.delegate.setThreadGroupName(name);
public void setDaemon(boolean daemon) {
this.delegate.setDaemon(daemon);
}
@Override
public void setThreadGroup(ThreadGroup threadGroup) {
this.delegate.setThreadGroup(threadGroup);
public void setThreadGroupName(String name) {
this.delegate.setThreadGroupName(name);
}
@Override
@@ -220,13 +215,13 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
}
@Override
public Thread createThread(Runnable runnable) {
return this.delegate.createThread(runnable);
public void setThreadGroup(ThreadGroup threadGroup) {
this.delegate.setThreadGroup(threadGroup);
}
@Override
public void setCorePoolSize(int corePoolSize) {
this.delegate.setCorePoolSize(corePoolSize);
public Thread createThread(Runnable runnable) {
return this.delegate.createThread(runnable);
}
@Override
@@ -235,8 +230,8 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
}
@Override
public void setMaxPoolSize(int maxPoolSize) {
this.delegate.setMaxPoolSize(maxPoolSize);
public void setCorePoolSize(int corePoolSize) {
this.delegate.setCorePoolSize(corePoolSize);
}
@Override
@@ -245,8 +240,8 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
}
@Override
public void setKeepAliveSeconds(int keepAliveSeconds) {
this.delegate.setKeepAliveSeconds(keepAliveSeconds);
public void setMaxPoolSize(int maxPoolSize) {
this.delegate.setMaxPoolSize(maxPoolSize);
}
@Override
@@ -254,6 +249,11 @@ public class LazyTraceThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
return this.delegate.getKeepAliveSeconds();
}
@Override
public void setKeepAliveSeconds(int keepAliveSeconds) {
this.delegate.setKeepAliveSeconds(keepAliveSeconds);
}
@Override
public void setQueueCapacity(int queueCapacity) {
this.delegate.setQueueCapacity(queueCapacity);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -24,6 +24,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.util.SpanNameUtil;
import org.springframework.util.ReflectionUtils;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -20,6 +20,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import brave.Tracing;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.util.concurrent.ListenableFuture;
@@ -27,8 +28,8 @@ import org.springframework.util.concurrent.ListenableFuture;
* AsyncListenableTaskExecutor that wraps all Runnable / Callable tasks into their trace
* related representation.
*
* @since 1.0.0
* @author Marcin Grzejszczak
* @since 1.0.0
* @see brave.propagation.CurrentTraceContext#wrap(Runnable)
* @see brave.propagation.CurrentTraceContext#wrap(Callable)
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -22,15 +22,16 @@ import brave.ScopedSpan;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.TraceContext;
import org.springframework.cloud.sleuth.SpanNamer;
/**
* Callable that passes Span between threads. The Span name is taken either from the
* passed value or from the {@link SpanNamer} interface.
*
* @param <V> - return type from callable
* @author Spencer Gibb
* @author Marcin Grzejszczak
* @param <V> - return type from callable
* @since 1.0.0
*/
public class TraceCallable<V> implements Callable<V> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -20,6 +20,7 @@ import brave.ScopedSpan;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.TraceContext;
import org.springframework.cloud.sleuth.SpanNamer;
/**
@@ -33,7 +34,8 @@ import org.springframework.cloud.sleuth.SpanNamer;
public class TraceRunnable implements Runnable {
/**
* Since we don't know the exact operation name we provide a default name for the Span
* Since we don't know the exact operation name we provide a default name for the
* Span.
*/
private static final String DEFAULT_SPAN_NAME = "async";

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.instrument.async;
import java.util.ArrayList;
@@ -31,7 +32,7 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.sleuth.SpanNamer;
/**
* A decorator class for {@link ExecutorService} to support tracing in Executors
* A decorator class for {@link ExecutorService} to support tracing in Executors.
*
* @author Gaurav Rai Mazra
* @since 1.0.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.BeanFactory;
/**
* A decorator class for {@link ScheduledExecutorService} to support tracing in Executors
* A decorator class for {@link ScheduledExecutorService} to support tracing in Executors.
*
* @author Gaurav Rai Mazra
* @since 1.0.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 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.
@@ -22,10 +22,14 @@ import io.grpc.ManagedChannelBuilder;
* Callback interface that can be implemented by beans wishing to further customize the
* {@link io.grpc.ManagedChannelBuilder} via the {@link SpringAwareManagedChannelBuilder}.
*
* @author tyler.vangorder
* @author Tyler Van Gorder
*/
public interface GrpcManagedChannelBuilderCustomizer {
/**
* Customizes the channel builder.
* @param managedChannelBuilder the builder to customize
*/
void customize(ManagedChannelBuilder<?> managedChannelBuilder);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -33,7 +33,7 @@ import io.grpc.inprocess.InProcessChannelBuilder;
* grpc-spring-boot-starter or a new project could be created
* "spring-grpc"/"spring-cloud-grpc"?
*
* @author tyler.vangorder
* @author Tyler Van Gorder
*/
public class SpringAwareManagedChannelBuilder {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -37,7 +37,7 @@ import org.springframework.context.annotation.Bean;
* This configuration is only enabled when both grpc-spring-boot-starter and
* brave-instrumentation-grpc are on the classpath.
*
* @author tyler.vangorder
* @author Tyler Van Gorder
*/
@ConditionalOnClass({ GrpcTracing.class, GRpcGlobalInterceptor.class })
@ConditionalOnProperty(value = "spring.sleuth.grpc.enabled", matchIfMissing = true)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 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.
@@ -20,7 +20,7 @@ import brave.grpc.GrpcTracing;
import io.grpc.ManagedChannelBuilder;
/**
* @author tyler.vangorder
* @author Tyler Van Gorder
*/
public class TracingManagedChannelBuilderCustomizer
implements GrpcManagedChannelBuilderCustomizer {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -18,6 +18,7 @@ package org.springframework.cloud.sleuth.instrument.hystrix;
import brave.Tracing;
import com.netflix.hystrix.HystrixCommand;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -35,6 +35,7 @@ import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
import com.netflix.hystrix.strategy.properties.HystrixProperty;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.sleuth.SpanNamer;
import org.springframework.cloud.sleuth.instrument.async.TraceCallable;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -25,6 +25,7 @@ import java.util.Map;
import brave.propagation.Propagation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.messaging.support.MessageHeaderAccessor;
import org.springframework.messaging.support.NativeMessageHeaderAccessor;
import org.springframework.util.LinkedMultiValueMap;
@@ -121,8 +122,9 @@ enum MessageHeaderPropagation
Object nativeHeaders = accessor
.getHeader(NativeMessageHeaderAccessor.NATIVE_HEADERS);
if (nativeHeaders == null) {
nativeHeaders = new LinkedMultiValueMap<>();
accessor.setHeader(NativeMessageHeaderAccessor.NATIVE_HEADERS,
nativeHeaders = new LinkedMultiValueMap<>());
nativeHeaders);
}
if (nativeHeaders instanceof Map<?, ?>) {
((Map) nativeHeaders).put(key, Collections.singletonList(value));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -19,7 +19,7 @@ package org.springframework.cloud.sleuth.instrument.messaging;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Properties for messaging
* Properties for messaging.
*
* @author Marcin Grzejszczak
* @since 2.0.0
@@ -48,7 +48,7 @@ public class SleuthMessagingProperties {
}
/**
* Properties for Spring Integration
* Properties for Spring Integration.
*
* @author Marcin Grzejszczak
*/
@@ -56,7 +56,7 @@ public class SleuthMessagingProperties {
/**
* An array of patterns against which channel names will be matched.
* @see org.springframework.integration.config.GlobalChannelInterceptor#patterns().
* @see org.springframework.integration.config.GlobalChannelInterceptor#patterns()
* Defaults to any channel name not matching the Hystrix Stream channel name.
*/
private String[] patterns = new String[] { "!hystrixStreamOutput*", "*" };
@@ -145,6 +145,9 @@ public class SleuthMessagingProperties {
}
/**
* RabbitMQ configuration.
*/
public static class Rabbit {
private boolean enabled;
@@ -169,6 +172,9 @@ public class SleuthMessagingProperties {
}
/**
* Kafka configuration.
*/
public static class Kafka {
private boolean enabled;
@@ -193,6 +199,9 @@ public class SleuthMessagingProperties {
}
/**
* JMS configuration.
*/
public static class Jms {
private boolean enabled;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -24,18 +24,36 @@ package org.springframework.cloud.sleuth.instrument.messaging;
* @author Marcin Grzejszczak
* @since 1.0.4
*/
public class TraceMessageHeaders {
public final class TraceMessageHeaders {
/**
* Span ID message header name.
*/
public static final String SPAN_ID_NAME = "spanId";
/**
* Span sampled message header name.
*/
public static final String SAMPLED_NAME = "spanSampled";
/**
* Parent span ID message header name.
*/
public static final String PARENT_ID_NAME = "spanParentSpanId";
/**
* Trace ID message header name.
*/
public static final String TRACE_ID_NAME = "spanTraceId";
/**
* Span name message header name.
*/
public static final String SPAN_NAME_NAME = "spanName";
/**
* Span flags message header name.
*/
public static final String SPAN_FLAGS_NAME = "spanFlags";
private TraceMessageHeaders() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -38,6 +38,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.aop.framework.ProxyFactoryBean;
@@ -148,7 +149,7 @@ public class TraceMessagingAutoConfiguration {
return new TracingConnectionFactoryBeanPostProcessor(beanFactory);
}
/** Setup the tracing endpoint registry */
// Setup the tracing endpoint registry.
@Bean
JmsListenerConfigurer configureTracing(JmsTracing jmsTracing,
CurrentTraceContext current) {
@@ -312,8 +313,9 @@ class MessageListenerMethodInterceptor<T extends MessageListener>
}
catch (RuntimeException | Error e) {
String message = e.getMessage();
if (message == null)
if (message == null) {
message = e.getClass().getSimpleName();
}
span.tag("error", message);
throw e;
}
@@ -322,4 +324,4 @@ class MessageListenerMethodInterceptor<T extends MessageListener>
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -18,6 +18,7 @@ package org.springframework.cloud.sleuth.instrument.messaging;
import brave.Tracing;
import brave.propagation.Propagation;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -26,6 +26,7 @@ import brave.propagation.TraceContext;
import brave.propagation.TraceContextOrSamplingFlags;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.util.SpanNameUtil;
@@ -55,10 +56,18 @@ import org.springframework.util.ClassUtils;
* This implementation uses {@link ThreadLocalSpan} to propagate context between
* callbacks. This is an alternative to {@code ThreadStatePropagationChannelInterceptor}
* which is less sensitive to message manipulation by other interceptors.
*
* @author Marcin Grzejszczak
*/
public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
implements ExecutorChannelInterceptor {
/**
* Name of the class in Spring Cloud Stream that is a direct channel.
*/
public static final String STREAM_DIRECT_CHANNEL = "org.springframework."
+ "cloud.stream.messaging.DirectWithAttributesChannel";
private static final Log log = LogFactory.getLog(TracingChannelInterceptor.class);
/**
@@ -81,8 +90,6 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
*/
private static final String REMOTE_SERVICE_NAME = "broker";
public static final String STREAM_DIRECT_CHANNEL = "org.springframework.cloud.stream.messaging.DirectWithAttributesChannel";
final Tracing tracing;
final Tracer tracer;
@@ -134,6 +141,8 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
* <p>
* This creates a child from identifiers extracted from the message headers, or a new
* span if one couldn't be extracted.
* @param message message to use for span creation
* @return span to be created
*/
public Span nextSpan(Message<?> message) {
MessageHeaderAccessor headers = mutableHeaderAccessor(message);
@@ -329,7 +338,10 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
}
/**
* When an upstream context was not present, lookup keys are unlikely added
* When an upstream context was not present, lookup keys are unlikely added.
* @param message a message to append tags to
* @param result span to customize
* @param channel channel to which a message was sent
*/
void addTags(Message<?> message, SpanCustomizer result, MessageChannel channel) {
// TODO topic etc
@@ -360,12 +372,14 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
void finishSpan(Exception error) {
Span span = this.threadLocalSpan.remove();
if (span == null || span.isNoop())
if (span == null || span.isNoop()) {
return;
}
if (error != null) { // an error occurred, adding error to span
String message = error.getMessage();
if (message == null)
if (message == null) {
message = error.getClass().getSimpleName();
}
span.tag("error", message);
}
span.finish();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -48,7 +48,7 @@ import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager;
import org.springframework.lang.Nullable;
/**
* {@link BeanPostProcessor} wrapping around JMS {@link ConnectionFactory}
* {@link BeanPostProcessor} wrapping around JMS {@link ConnectionFactory}.
*
* @author Adrian Cole
* @since 2.1.0
@@ -134,14 +134,16 @@ class LazyXAConnectionFactory implements XAConnectionFactory {
if (this.jmsTracing != null) {
return this.jmsTracing;
}
return this.jmsTracing = this.beanFactory.getBean(JmsTracing.class);
this.jmsTracing = this.beanFactory.getBean(JmsTracing.class);
return this.jmsTracing;
}
private XAConnectionFactory wrappedDelegate() {
if (this.wrappedDelegate != null) {
return this.wrappedDelegate;
}
return this.wrappedDelegate = jmsTracing().xaConnectionFactory(this.delegate);
this.wrappedDelegate = jmsTracing().xaConnectionFactory(this.delegate);
return this.wrappedDelegate;
}
}
@@ -195,14 +197,16 @@ class LazyConnectionFactory implements ConnectionFactory {
if (this.jmsTracing != null) {
return this.jmsTracing;
}
return this.jmsTracing = this.beanFactory.getBean(JmsTracing.class);
this.jmsTracing = this.beanFactory.getBean(JmsTracing.class);
return this.jmsTracing;
}
private ConnectionFactory wrappedDelegate() {
if (this.wrappedDelegate != null) {
return this.wrappedDelegate;
}
return this.wrappedDelegate = jmsTracing().connectionFactory(this.delegate);
this.wrappedDelegate = jmsTracing().connectionFactory(this.delegate);
return this.wrappedDelegate;
}
}
@@ -229,7 +233,8 @@ class LazyMessageListener implements MessageListener {
if (this.jmsTracing != null) {
return this.jmsTracing;
}
return this.jmsTracing = this.beanFactory.getBean(JmsTracing.class);
this.jmsTracing = this.beanFactory.getBean(JmsTracing.class);
return this.jmsTracing;
}
private MessageListener wrappedDelegate() {
@@ -242,7 +247,7 @@ class LazyMessageListener implements MessageListener {
/**
* This ensures listeners end up continuing the trace from
* {@link MessageConsumer#receive()}
* {@link MessageConsumer#receive()}.
*/
class TracingJmsListenerEndpointRegistry extends JmsListenerEndpointRegistry {
@@ -295,11 +300,14 @@ class TracingJmsListenerEndpointRegistry extends JmsListenerEndpointRegistry {
/**
* This wraps the {@link SimpleJmsListenerEndpoint#getMessageListener()} delegate in a
* new span.
* @param source jms endpoint
* @return wrapped endpoint
*/
SimpleJmsListenerEndpoint trace(SimpleJmsListenerEndpoint source) {
MessageListener delegate = source.getMessageListener();
if (delegate == null)
if (delegate == null) {
return source;
}
source.setMessageListener(this.jmsTracing.messageListener(delegate, false));
return source;
}
@@ -315,6 +323,8 @@ class TracingJmsListenerEndpointRegistry extends JmsListenerEndpointRegistry {
* subtype could hold state we aren't aware of, or change behavior. We can consider
* checking that input is not a subtype, and most conservatively leaving unknown
* subtypes untraced.
* @param source jms endpoint
* @return wrapped endpoint
*/
MethodJmsListenerEndpoint trace(MethodJmsListenerEndpoint source) {
// Skip out rather than incompletely copying the source
@@ -360,7 +370,7 @@ class TracingJmsListenerEndpointRegistry extends JmsListenerEndpointRegistry {
}
/**
* This wraps the message listener in a child span
* This wraps the message listener in a child span.
*/
final class TracingMessagingMessageListenerAdapter
extends MessagingMessageListenerAdapter {
@@ -390,4 +400,4 @@ final class TracingMessagingMessageListenerAdapter
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -17,6 +17,7 @@
package org.springframework.cloud.sleuth.instrument.messaging.websocket;
import brave.Tracing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -68,4 +69,4 @@ public class TraceWebSocketAutoConfiguration
registration.setInterceptors(TracingChannelInterceptor.create(this.tracing));
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
@@ -19,6 +19,7 @@ package org.springframework.cloud.sleuth.instrument.opentracing;
import brave.Tracing;
import brave.opentracing.BraveTracer;
import io.opentracing.Tracer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.

Some files were not shown because too many files have changed in this diff Show More