This commit is contained in:
Marcin Grzejszczak
2017-08-25 11:52:14 +02:00
parent 126101f0ab
commit b83caf4ac0
37 changed files with 96 additions and 101 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

@@ -96,14 +96,14 @@ public class TraceFilter extends GenericFilterBean {
private Tracer tracer;
private TraceKeys traceKeys;
private Pattern skipPattern;
private final Pattern skipPattern;
private SpanReporter spanReporter;
private HttpSpanExtractor spanExtractor;
private HttpTraceKeysInjector httpTraceKeysInjector;
private ErrorParser errorParser;
private BeanFactory beanFactory;
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

@@ -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

@@ -16,17 +16,15 @@
package org.springframework.cloud.sleuth.instrument.web;
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
import java.util.Collection;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.PostConstruct;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.awaitility.Awaitility;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,7 +53,7 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import org.awaitility.Awaitility;
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
/**
* @author Marcin Grzejszczak
@@ -141,7 +139,6 @@ class SampleRecords {
private final ReservationRepository reservationRepository;
@Autowired
public SampleRecords(ReservationRepository reservationRepository) {
this.reservationRepository = reservationRepository;
}

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