Merge pull request #116 from spring-cloud/issues_#86_sampler_param
[#86] Removes the sampler param. Fixed #86
This commit is contained in:
@@ -45,5 +45,5 @@ package org.springframework.cloud.sleuth;
|
||||
* This would trace 50% of all gets, 75% of all puts and would not trace any other requests.
|
||||
*/
|
||||
public interface Sampler<T> {
|
||||
boolean next(T info);
|
||||
boolean next();
|
||||
}
|
||||
|
||||
@@ -77,12 +77,10 @@ public interface TraceManager extends TraceAccessor {
|
||||
/**
|
||||
* Start a new span if the sampler allows it or if we are already tracing in this
|
||||
* thread. A sampler can be used to limit the number of traces created.
|
||||
*
|
||||
* @param name the name of the span
|
||||
* @param name the name of the span
|
||||
* @param sampler a sampler to decide whether to create the span or not
|
||||
* @param info the samplers context information
|
||||
*/
|
||||
<T> Trace startSpan(String name, Sampler<T> sampler, T info);
|
||||
<T> Trace startSpan(String name, Sampler<T> sampler);
|
||||
|
||||
/**
|
||||
* Pick up an existing span from another thread.
|
||||
|
||||
@@ -62,7 +62,7 @@ public class TraceChannelInterceptor extends AbstractTraceChannelInterceptor {
|
||||
return traceManager.startSpan(name, span);
|
||||
}
|
||||
if (message.getHeaders().containsKey(Trace.NOT_SAMPLED_NAME)) {
|
||||
return traceManager.startSpan(name, IsTracingSampler.INSTANCE, null);
|
||||
return traceManager.startSpan(name, IsTracingSampler.INSTANCE);
|
||||
}
|
||||
return this.traceManager.startSpan(name);
|
||||
}
|
||||
|
||||
@@ -144,8 +144,8 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
}
|
||||
else {
|
||||
if (skip) {
|
||||
trace = this.traceManager.startSpan(name, IsTracingSampler.INSTANCE,
|
||||
null);
|
||||
trace = this.traceManager.startSpan(name, IsTracingSampler.INSTANCE
|
||||
);
|
||||
}
|
||||
else {
|
||||
trace = this.traceManager.startSpan(name);
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.cloud.sleuth.Sampler;
|
||||
*/
|
||||
public class AlwaysSampler implements Sampler<Void> {
|
||||
@Override
|
||||
public boolean next(Void info) {
|
||||
public boolean next() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class IsTracingSampler implements Sampler<Void> {
|
||||
public static IsTracingSampler INSTANCE = new IsTracingSampler();
|
||||
|
||||
@Override
|
||||
public boolean next(Void info) {
|
||||
public boolean next() {
|
||||
return TraceContextHolder.isTracing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class PercentageBasedSampler implements Sampler<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next(Void info) {
|
||||
public boolean next() {
|
||||
Span currentSpan = traceAccessor.getCurrentSpan();
|
||||
long threshold = Math.abs(Long.MAX_VALUE * (int) (configuration.getPercentage() * 100)); // drops fractional percentage.
|
||||
if (currentSpan == null || threshold == 0L) {
|
||||
|
||||
@@ -68,13 +68,13 @@ public class DefaultTraceManager implements TraceManager {
|
||||
|
||||
@Override
|
||||
public Trace startSpan(String name) {
|
||||
return this.startSpan(name, this.defaultSampler, null);
|
||||
return this.startSpan(name, this.defaultSampler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Trace startSpan(String name, Sampler<T> s, T info) {
|
||||
public <T> Trace startSpan(String name, Sampler<T> s) {
|
||||
Span span = null;
|
||||
if (isTracing() || s.next(info)) {
|
||||
if (isTracing() || s.next()) {
|
||||
span = createChild(getCurrentSpan(), name);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DefaultTraceManagerTests {
|
||||
|
||||
DefaultTraceManager traceManager = new DefaultTraceManager(new IsTracingSampler(), new Random(), publisher);
|
||||
|
||||
Trace trace = traceManager.startSpan(CREATE_SIMPLE_TRACE, new AlwaysSampler(), null);
|
||||
Trace trace = traceManager.startSpan(CREATE_SIMPLE_TRACE, new AlwaysSampler());
|
||||
try {
|
||||
importantWork1(traceManager);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ abstract class AbstractTraceStompIntegrationTests {
|
||||
}
|
||||
|
||||
Trace givenALocallyStartedSpan() {
|
||||
return traceManager.startSpan("testSendMessage", sampler, null);
|
||||
return traceManager.startSpan("testSendMessage", sampler);
|
||||
}
|
||||
|
||||
Message<?> givenMessageToBeSampled() {
|
||||
|
||||
@@ -137,7 +137,7 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
@Test
|
||||
public void headerCreation() {
|
||||
Trace trace = this.traceManager.startSpan("testSendMessage",
|
||||
new AlwaysSampler(), null);
|
||||
new AlwaysSampler());
|
||||
this.channel.send(MessageBuilder.withPayload("hi").build());
|
||||
this.traceManager.close(trace);
|
||||
assertNotNull("message was null", this.message);
|
||||
@@ -154,7 +154,7 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
@Test
|
||||
public void headerCreationViaMessagingTemplate() {
|
||||
Trace trace = this.traceManager.startSpan("testSendMessage",
|
||||
new AlwaysSampler(), null);
|
||||
new AlwaysSampler());
|
||||
this.messagingTemplate.send(MessageBuilder.withPayload("hi").build());
|
||||
this.traceManager.close(trace);
|
||||
assertNotNull("message was null", this.message);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class TraceContextPropagationChannelInterceptorTests {
|
||||
@Test
|
||||
public void testSpanPropagation() {
|
||||
|
||||
Trace trace = this.traceManager.startSpan("testSendMessage", new AlwaysSampler(), null);
|
||||
Trace trace = this.traceManager.startSpan("testSendMessage", new AlwaysSampler());
|
||||
this.channel.send(MessageBuilder.withPayload("hi").build());
|
||||
Long expectedSpanId = trace.getSpan().getSpanId();
|
||||
this.traceManager.close(trace);
|
||||
|
||||
@@ -179,8 +179,8 @@ public class TraceFilterTests {
|
||||
|
||||
private class DelegateSampler implements Sampler<Void> {
|
||||
@Override
|
||||
public boolean next(Void info) {
|
||||
return TraceFilterTests.this.sampler.next(info);
|
||||
public boolean next() {
|
||||
return TraceFilterTests.this.sampler.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,8 @@ import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.util.JdkIdGenerator;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PercentageBasedSamplerTests {
|
||||
|
||||
@@ -23,7 +21,7 @@ public class PercentageBasedSamplerTests {
|
||||
this.samplerConfiguration.setPercentage(1f);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor).next(null)).isTrue();
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor).next()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,7 +31,7 @@ public class PercentageBasedSamplerTests {
|
||||
this.samplerConfiguration.setPercentage(0f);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor).next(null)).isFalse();
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor).next()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +49,7 @@ public class PercentageBasedSamplerTests {
|
||||
private int countNumberOfSampledElements(int numberOfIterations) {
|
||||
int passedCounter = 0;
|
||||
for (int i = 0; i < numberOfIterations; i++) {
|
||||
boolean passed = new PercentageBasedSampler(this.samplerConfiguration, traceReturningSpanWithUuid()).next(null);
|
||||
boolean passed = new PercentageBasedSampler(this.samplerConfiguration, traceReturningSpanWithUuid()).next();
|
||||
passedCounter = passedCounter + (passed ? 1 : 0);
|
||||
}
|
||||
return passedCounter;
|
||||
|
||||
@@ -95,7 +95,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
Trace trace = this.traceManager.startSpan("customTraceEndpoint",
|
||||
new AlwaysSampler(), null);
|
||||
new AlwaysSampler());
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -95,7 +95,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
Trace trace = this.traceManager.startSpan("customTraceEndpoint",
|
||||
new AlwaysSampler(), null);
|
||||
new AlwaysSampler());
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -95,7 +95,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
Trace trace = this.traceManager.startSpan("customTraceEndpoint",
|
||||
new AlwaysSampler(), null);
|
||||
new AlwaysSampler());
|
||||
int millis = random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -100,7 +100,7 @@ public class StreamSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void nullSpanName() {
|
||||
Trace context = this.traceManager.startSpan(null, null);
|
||||
Trace context = this.traceManager.startSpan(null, (Sampler) null);
|
||||
this.application.publishEvent(new ClientSentEvent(this, context.getSpan()));
|
||||
this.traceManager.close(context);
|
||||
assertEquals(1, this.test.spans.size());
|
||||
|
||||
Reference in New Issue
Block a user