Merge branch 'master' into 2.0.x

This commit is contained in:
Marcin Grzejszczak
2017-08-25 12:04:41 +02:00
36 changed files with 92 additions and 94 deletions

View File

@@ -635,15 +635,15 @@ public class Span implements SpanContext {
private String name;
private long traceIdHigh;
private long traceId;
private ArrayList<Long> parents = new ArrayList<>();
private final ArrayList<Long> parents = new ArrayList<>();
private long spanId;
private boolean remote;
private boolean exportable = true;
private String processId;
private Span savedSpan;
private List<Log> logs = new ArrayList<>();
private Map<String, String> tags = new LinkedHashMap<>();
private Map<String, String> baggage = new LinkedHashMap<>();
private final List<Log> logs = new ArrayList<>();
private final Map<String, String> tags = new LinkedHashMap<>();
private final Map<String, String> baggage = new LinkedHashMap<>();
SpanBuilder() {
}

View File

@@ -139,7 +139,7 @@ class SleuthAdvisorConfig extends AbstractPointcutAdvisor implements BeanFactor
*/
private static class AnnotationMethodsResolver {
private Class<? extends Annotation> annotationType;
private final Class<? extends Annotation> annotationType;
public AnnotationMethodsResolver(Class<? extends Annotation> annotationType) {
this.annotationType = annotationType;

View File

@@ -24,11 +24,9 @@ package org.springframework.cloud.sleuth.annotation;
*/
class SleuthAnnotatedParameter {
int parameterIndex;
SpanTag annotation;
Object argument;
final int parameterIndex;
final SpanTag annotation;
final Object argument;
SleuthAnnotatedParameter(int parameterIndex, SpanTag annotation,
Object argument) {

View File

@@ -98,6 +98,7 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor {
return factory.getObject();
}
@SuppressWarnings("unchecked")
Object createProxy(Object bean, boolean cglibProxy, Executor executor) {
ProxyFactoryBean factory = new ProxyFactoryBean();
factory.setProxyTargetClass(cglibProxy);

View File

@@ -37,7 +37,7 @@ import org.springframework.cloud.sleuth.Tracer;
* @since 1.0.0
*/
public class TraceableExecutorService implements ExecutorService {
ExecutorService delegate;
final ExecutorService delegate;
Tracer tracer;
private final String spanName;
TraceKeys traceKeys;

View File

@@ -16,6 +16,12 @@
package org.springframework.cloud.sleuth.instrument.hystrix;
import java.lang.invoke.MethodHandles;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.HystrixPlugins;
@@ -33,12 +39,6 @@ import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.Tracer;
import java.lang.invoke.MethodHandles;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* A {@link HystrixConcurrencyStrategy} that wraps a {@link Callable} in a
* {@link Callable} that either starts a new span or continues one if the tracing was
@@ -146,10 +146,10 @@ public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
private static final Log log = LogFactory.getLog(MethodHandles.lookup().lookupClass());
private Tracer tracer;
private TraceKeys traceKeys;
private Callable<S> callable;
private Span parent;
private final Tracer tracer;
private final TraceKeys traceKeys;
private final Callable<S> callable;
private final Span parent;
public HystrixTraceCallable(Tracer tracer, TraceKeys traceKeys,
Callable<S> callable) {

View File

@@ -43,7 +43,7 @@ abstract class AbstractTraceChannelInterceptor extends ChannelInterceptorAdapter
private MessagingSpanTextMapExtractor spanExtractor;
private MessagingSpanTextMapInjector spanInjector;
private ErrorParser errorParser;
private BeanFactory beanFactory;
private final BeanFactory beanFactory;
protected AbstractTraceChannelInterceptor(BeanFactory beanFactory) {
this.beanFactory = beanFactory;

View File

@@ -83,9 +83,9 @@ class SleuthRxJavaSchedulersHook extends RxJavaSchedulersHook {
static class TraceAction implements Action0 {
private final Action0 actual;
private Tracer tracer;
private TraceKeys traceKeys;
private Span parent;
private final Tracer tracer;
private final TraceKeys traceKeys;
private final Span parent;
private final List<String> threadsToIgnore;
public TraceAction(Tracer tracer, TraceKeys traceKeys, Action0 actual,

View File

@@ -103,7 +103,7 @@ public class TraceFilter extends GenericFilterBean {
private ErrorParser errorParser;
private final BeanFactory beanFactory;
private UrlPathHelper urlPathHelper = new UrlPathHelper();
private final UrlPathHelper urlPathHelper = new UrlPathHelper();
public TraceFilter(BeanFactory beanFactory) {
this(beanFactory, skipPattern(beanFactory));

View File

@@ -67,6 +67,7 @@ import java.util.concurrent.Callable;
* @see org.springframework.cloud.sleuth.Tracer
* @see org.springframework.cloud.sleuth.instrument.web.TraceFilter
*/
@SuppressWarnings("ArgNamesWarningsInspection")
@Aspect
public class TraceWebAspect {

View File

@@ -24,12 +24,14 @@ class TraceFeignContext extends FeignContext {
}
@Override
@SuppressWarnings("unchecked")
public <T> T getInstance(String name, Class<T> type) {
T object = this.delegate.getInstance(name, type);
return (T) this.traceFeignObjectWrapper.wrap(object);
}
@Override
@SuppressWarnings("unchecked")
public <T> Map<String, T> getInstances(String name, Class<T> type) {
Map<String, T> instances = this.delegate.getInstances(name, type);
if (instances == null) {

View File

@@ -52,7 +52,7 @@ class TraceZuulHandlerMappingBeanPostProcessor implements BeanPostProcessor {
}
ZuulHandlerMapping zuulHandlerMapping = (ZuulHandlerMapping) bean;
zuulHandlerMapping.setInterceptors(
new Object[] { new TraceHandlerInterceptor(this.beanFactory) });
new TraceHandlerInterceptor(this.beanFactory));
}
return bean;
}

View File

@@ -30,7 +30,7 @@ import org.springframework.cloud.sleuth.SpanAccessor;
*/
public class IsTracingSampler implements Sampler {
private SpanAccessor accessor;
private final SpanAccessor accessor;
public IsTracingSampler(SpanAccessor accessor) {
this.accessor = accessor;

View File

@@ -112,9 +112,9 @@ class SpanContextHolder {
}
private static class SpanContext {
Span span;
boolean autoClose;
SpanContext parent;
final Span span;
final boolean autoClose;
final SpanContext parent;
public SpanContext(Span span, boolean autoClose) {
this.span = span;

View File

@@ -64,8 +64,8 @@ public class ListOfSpansAssert extends AbstractAssert<ListOfSpansAssert, ListOfS
isNotNull();
printSpans();
List<Span> matchingSpans = this.actual.spans.stream()
.filter(span -> span.getName().equals(name) && span.logs().stream().filter(entry ->
entry.getEvent().equals(Span.CLIENT_SEND)).findAny().isPresent()).collect(toList());
.filter(span -> span.getName().equals(name) && span.logs().stream().anyMatch(entry ->
entry.getEvent().equals(Span.CLIENT_SEND))).collect(toList());
assertThat(matchingSpans).isNotEmpty();
List<Map<String, String>> matchingSpansTags = matchingSpans.stream().map(Span::tags).collect(
toList());

View File

@@ -159,7 +159,7 @@ public class SpanAssert extends AbstractAssert<SpanAssert, Span> {
public SpanAssert hasLoggedAnEvent(String event) {
isNotNull();
if (!this.actual.logs().stream().map(org.springframework.cloud.sleuth.Log::getEvent)
.filter(s -> s.equals(event)).findAny().isPresent()) {
.anyMatch(s -> s.equals(event))) {
String message = String.format("Expected span to have the event with event value <%s>. "
+ "Found logs are <%s>", event, this.actual.logs());
log.error(message);
@@ -171,7 +171,7 @@ public class SpanAssert extends AbstractAssert<SpanAssert, Span> {
public SpanAssert hasNotLoggedAnEvent(String event) {
isNotNull();
if (this.actual.logs().stream().map(org.springframework.cloud.sleuth.Log::getEvent)
.filter(s -> s.equals(event)).findAny().isPresent()) {
.anyMatch(s -> s.equals(event))) {
String message = String.format("Expected span NOT to have the event with event value <%s>. "
+ "Found logs are <%s>", event, this.actual.logs());
log.error(message);

View File

@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015-2016 The OpenZipkin Authors
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except

View File

@@ -91,7 +91,7 @@ public class SpanSubscriberTests {
}
@Test public void should_not_trace_scalar_flows() {
Span span = this.tracer.createSpan("foo");
this.tracer.createSpan("foo");
final AtomicReference<Subscription> spanInOperation = new AtomicReference<>();
log.info("Hello");

View File

@@ -42,7 +42,7 @@ public class HttpTraceKeysInjectorUnitTests {
headers.add(Span.SPAN_ID_NAME, "763261a53162f330");
headers.add(Span.SAMPLED_NAME,"1");
headers.add(Span.SPAN_NAME_NAME, "http:/");
this.traceKeys.getHttp().setHeaders(Arrays.asList("Accept", "User-Agent", "Content-Type"));;
this.traceKeys.getHttp().setHeaders(Arrays.asList("Accept", "User-Agent", "Content-Type"));
this.injector.addRequestTags(url.toString(), url.getHost(), url.getPath(), HttpMethod.GET.name(), headers );

View File

@@ -2,12 +2,10 @@
package org.springframework.cloud.sleuth.instrument.web;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.BDDAssertions.then;
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
import java.util.concurrent.atomic.AtomicReference;
import org.assertj.core.api.BDDAssertions;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

View File

@@ -123,11 +123,11 @@ public class WebClientExceptionTests {
}
Object[] parametersForShouldCloseSpanUponException() {
return $(
return new Object[] {
(ResponseEntityProvider) (tests) -> tests.testFeignInterfaceWithException
.shouldFailToConnect(),
(ResponseEntityProvider) (tests) -> tests.template
.getForEntity("http://exceptionservice/", Map.class));
.getForEntity("http://exceptionservice/", Map.class) };
}
@FeignClient("exceptionservice")

View File

@@ -118,8 +118,12 @@ public class FeignRetriesTests {
throw new IOException();
} else {
// with the second retry (first retry) we send back good result
return Response.create(200, "OK", new HashMap<>(),
"OK", Charset.defaultCharset());
return Response.builder()
.status(200)
.reason("OK")
.headers(new HashMap<>())
.body("OK", Charset.defaultCharset())
.build();
}
};
TestInterface api =

View File

@@ -108,8 +108,7 @@ class ServiceTestController {
@RequestMapping("/ok")
public String ok() throws InterruptedException, ExecutionException {
String result = "I'm OK";
return result;
return "I'm OK";
}
@RequestMapping("/not-ok")

View File

@@ -217,8 +217,7 @@ class ServiceTestController {
@RequestMapping("/ok")
public String ok() throws InterruptedException, ExecutionException {
String result = "I'm OK";
return result;
return "I'm OK";
}
@RequestMapping("/not-ok")
@@ -237,13 +236,11 @@ class SleuthTestController {
@RequestMapping("/test-ok")
public String ok() throws InterruptedException, ExecutionException {
String result = myFeignClient.ok();
return result;
return myFeignClient.ok();
}
@RequestMapping("/test-not-ok")
public String notOk() throws InterruptedException, ExecutionException {
String result = myFeignClient.exp();
return result;
return myFeignClient.exp();
}
}

View File

@@ -77,7 +77,6 @@ import com.netflix.loadbalancer.Server;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import static junitparams.JUnitParamsRunner.$;
import static org.assertj.core.api.Assertions.fail;
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
@@ -130,7 +129,7 @@ public class WebClientTests {
}
Object[] parametersForShouldCreateANewSpanWithClientSideTagsWhenNoPreviousTracingWasPresent() {
return $(
return new Object[] {
(ResponseEntityProvider) (tests) -> tests.testFeignInterface.getNoTrace(),
(ResponseEntityProvider) (tests) -> tests.testFeignInterface.getNoTrace(),
(ResponseEntityProvider) (tests) -> tests.testFeignInterface.getNoTrace(),
@@ -146,7 +145,8 @@ public class WebClientTests {
(ResponseEntityProvider) (tests) -> tests.template.getForEntity("http://fooservice/notrace", String.class),
(ResponseEntityProvider) (tests) -> tests.template.getForEntity("http://fooservice/notrace", String.class),
(ResponseEntityProvider) (tests) -> tests.template.getForEntity("http://fooservice/notrace", String.class),
(ResponseEntityProvider) (tests) -> tests.template.getForEntity("http://fooservice/notrace", String.class));
(ResponseEntityProvider) (tests) -> tests.template.getForEntity("http://fooservice/notrace", String.class)
};
}
@Test
@@ -166,9 +166,10 @@ public class WebClientTests {
}
Object[] parametersForShouldPropagateNotSamplingHeader() {
return $((ResponseEntityProvider) (tests) -> tests.testFeignInterface.headers(),
return new Object[] {
(ResponseEntityProvider) (tests) -> tests.testFeignInterface.headers(),
(ResponseEntityProvider) (tests) -> tests.template
.getForEntity("http://fooservice/", Map.class));
.getForEntity("http://fooservice/", Map.class) };
}
@Test
@@ -206,9 +207,10 @@ public class WebClientTests {
}
Object[] parametersForShouldAttachTraceIdWhenCallingAnotherService() {
return $((ResponseEntityProvider) (tests) -> tests.testFeignInterface.headers(),
return new Object[] {
(ResponseEntityProvider) (tests) -> tests.testFeignInterface.headers(),
(ResponseEntityProvider) (tests) -> tests.template
.getForEntity("http://fooservice/traceid", String.class));
.getForEntity("http://fooservice/traceid", String.class) };
}
@Test
@@ -229,11 +231,12 @@ public class WebClientTests {
}
Object[] parametersForShouldAttachTraceIdWhenUsingFeignClientWithoutResponseBody() {
return $(
(ResponseEntityProvider) (tests) -> tests.testFeignInterface
.noResponseBody(),
(ResponseEntityProvider) (tests) -> tests.template
.getForEntity("http://fooservice/noresponse", String.class));
return new Object[] {
(ResponseEntityProvider) (tests) ->
tests.testFeignInterface.noResponseBody(),
(ResponseEntityProvider) (tests) ->
tests.template.getForEntity("http://fooservice/noresponse", String.class)
};
}
@Test

View File

@@ -31,9 +31,8 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class SampleController {
private Zipkin zipkin;
private Random random = new Random();
private final Zipkin zipkin;
private final Random random = new Random();
@Autowired
public SampleController(Zipkin zipkin) {

View File

@@ -34,7 +34,7 @@ import zipkin.Span;
@EnableFeignClients
public class SampleFeignApplication {
private static Log logger = LogFactory.getLog(SampleFeignApplication.class);
private static final Log logger = LogFactory.getLog(SampleFeignApplication.class);
public static void main(String[] args) {
SpringApplication.run(SampleFeignApplication.class, args);

View File

@@ -37,7 +37,7 @@ import zipkin.Span;
@EnableZuulProxy
public class SampleRibbonApplication {
private static Log logger = LogFactory.getLog(SampleRibbonApplication.class);
private static final Log logger = LogFactory.getLog(SampleRibbonApplication.class);
public static void main(String[] args) {
SpringApplication.run(SampleRibbonApplication.class, args);

View File

@@ -49,7 +49,7 @@ public class SampleController
@Autowired
private SampleBackground controller;
private Random random = new Random();
final private Random random = new Random();
private int port;
@RequestMapping("/")

View File

@@ -31,8 +31,6 @@ import org.springframework.web.client.RestTemplate;
@EnableAsync
public class SampleSleuthApplication {
public static final String CLIENT_NAME = "testApp";
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();

View File

@@ -53,7 +53,7 @@ public abstract class AbstractIntegrationTest {
protected static final int POLL_INTERVAL = 1;
protected static final int TIMEOUT = 20;
protected RestTemplate restTemplate = new AssertingRestTemplate();
protected final RestTemplate restTemplate = new AssertingRestTemplate();
@Before
public void clearSpanBefore() {

View File

@@ -48,7 +48,7 @@ public class SampleController
@Autowired
private SampleBackground controller;
private Random random = new Random();
private final Random random = new Random();
private int port;
@RequestMapping("/")

View File

@@ -31,8 +31,6 @@ import org.springframework.web.client.RestTemplate;
@EnableAsync
public class SampleSleuthApplication {
public static final String CLIENT_NAME = "testApp";
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();

View File

@@ -46,7 +46,7 @@ import org.springframework.core.io.support.PropertiesLoaderUtils;
public class StreamEnvironmentPostProcessor implements EnvironmentPostProcessor {
private static final String PROPERTY_SOURCE_NAME = "defaultProperties";
static String[] headers = new String[] { TraceMessageHeaders.SPAN_ID_NAME,
static final String[] HEADERS = new String[] { TraceMessageHeaders.SPAN_ID_NAME,
TraceMessageHeaders.TRACE_ID_NAME, TraceMessageHeaders.PARENT_ID_NAME, TraceMessageHeaders.PROCESS_ID_NAME,
TraceMessageHeaders.SAMPLED_NAME, TraceMessageHeaders.SPAN_NAME_NAME };
@@ -82,7 +82,7 @@ public class StreamEnvironmentPostProcessor implements EnvironmentPostProcessor
}
private int findStartIndex(ConfigurableEnvironment environment, String binder) {
String prefix = "spring.cloud.stream." + binder + ".binder.headers";
String prefix = "spring.cloud.stream." + binder + ".binder.HEADERS";
int i = 0;
while (environment.getProperty(prefix + "[" + i + "]")!=null) {
i++;
@@ -127,10 +127,10 @@ public class StreamEnvironmentPostProcessor implements EnvironmentPostProcessor
private void addHeaders(Map<String, Object> map, MutablePropertySources propertySources,
String binder, int startIndex) {
String stem = "spring.cloud.stream." + binder + ".binder.headers";
for (int i = 0; i < headers.length; i++) {
if (!hasTracingHeadersValue(propertySources, headers[i])) {
map.put(stem + "[" + (i + startIndex) + "]", headers[i]);
String stem = "spring.cloud.stream." + binder + ".binder.HEADERS";
for (int i = 0; i < HEADERS.length; i++) {
if (!hasTracingHeadersValue(propertySources, HEADERS[i])) {
map.put(stem + "[" + (i + startIndex) + "]", HEADERS[i]);
}
}
}

View File

@@ -42,18 +42,18 @@ public class StreamEnvironmentPostProcessorTests {
public void should_append_tracing_headers() {
postProcess();
assertThat(this.environment
.getProperty("spring.cloud.stream.test.binder.headers[0]"))
.getProperty("spring.cloud.stream.test.binder.HEADERS[0]"))
.isEqualTo(TraceMessageHeaders.SPAN_ID_NAME);
}
@Test
public void should_append_tracing_headers_to_existing_ones() {
EnvironmentTestUtils.addEnvironment(this.environment,
"spring.cloud.stream.test.binder.headers[0]=X-Custom",
"spring.cloud.stream.test.binder.headers[1]=X-Mine");
"spring.cloud.stream.test.binder.HEADERS[0]=X-Custom",
"spring.cloud.stream.test.binder.HEADERS[1]=X-Mine");
postProcess();
assertThat(this.environment
.getProperty("spring.cloud.stream.test.binder.headers[2]"))
.getProperty("spring.cloud.stream.test.binder.HEADERS[2]"))
.isEqualTo(TraceMessageHeaders.SPAN_ID_NAME);
}
@@ -71,9 +71,9 @@ public class StreamEnvironmentPostProcessorTests {
assertThat(traceIds).hasSize(1);
assertThat(defaultPropertiesSource().keySet().stream()
.filter(input -> input
.startsWith("spring.cloud.stream.test.binder.headers"))
.startsWith("spring.cloud.stream.test.binder.HEADERS"))
.collect(Collectors.toList()))
.hasSize(StreamEnvironmentPostProcessor.headers.length);
.hasSize(StreamEnvironmentPostProcessor.HEADERS.length);
}
private void postProcess() {

View File

@@ -16,6 +16,11 @@
package org.springframework.cloud.sleuth.zipkin;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.springframework.cloud.commons.util.IdUtils;
import org.springframework.cloud.sleuth.Log;
import org.springframework.cloud.sleuth.Span;
@@ -28,11 +33,6 @@ import zipkin.BinaryAnnotation;
import zipkin.Constants;
import zipkin.Endpoint;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* Listener of Sleuth events. Reports to Zipkin via {@link ZipkinSpanReporter}.
*
@@ -60,7 +60,7 @@ public class ZipkinSpanListener implements SpanReporter {
* the service name from discovery.
*/
// Visible for testing
EndpointLocator endpointLocator;
final EndpointLocator endpointLocator;
public ZipkinSpanListener(ZipkinSpanReporter reporter, EndpointLocator endpointLocator,
Environment environment, List<SpanAdjuster> spanAdjusters) {