Changed sampler method to be consistent with open tracing API
https://github.com/opentracing/opentracing-python/blob/master/example/zipkin_like/sampler.py#L36
This commit is contained in:
@@ -20,5 +20,5 @@ package org.springframework.cloud.sleuth;
|
||||
* Extremely simple callback to determine the frequency that an action should be
|
||||
*/
|
||||
public interface Sampler {
|
||||
boolean next();
|
||||
boolean isSampled();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.cloud.sleuth.Sampler;
|
||||
*/
|
||||
public class AlwaysSampler implements Sampler {
|
||||
@Override
|
||||
public boolean next() {
|
||||
public boolean isSampled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class IsTracingSampler implements Sampler {
|
||||
public static IsTracingSampler INSTANCE = new IsTracingSampler();
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
public boolean isSampled() {
|
||||
return SpanContextHolder.isTracing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PercentageBasedSampler implements Sampler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
public boolean isSampled() {
|
||||
Span currentSpan = this.traceAccessor.getCurrentSpan();
|
||||
long threshold = Math.abs(Long.MAX_VALUE * (int) (this.configuration.getPercentage() * 100)); // drops fractional percentage.
|
||||
if (currentSpan == null || threshold == 0L) {
|
||||
|
||||
@@ -72,7 +72,7 @@ public class DefaultTracer implements Tracer {
|
||||
@Override
|
||||
public Span startTrace(String name, Sampler s) {
|
||||
Span span;
|
||||
if (isTracing() || s.next()) {
|
||||
if (isTracing() || s.isSampled()) {
|
||||
span = createChild(getCurrentSpan(), name);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -216,8 +216,8 @@ public class TraceFilterTests {
|
||||
|
||||
private class DelegateSampler implements Sampler {
|
||||
@Override
|
||||
public boolean next() {
|
||||
return TraceFilterTests.this.sampler.next();
|
||||
public boolean isSampled() {
|
||||
return TraceFilterTests.this.sampler.isSampled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class PercentageBasedSamplerTests {
|
||||
this.samplerConfiguration.setPercentage(1f);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor).next()).isTrue();
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor).isSampled()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class PercentageBasedSamplerTests {
|
||||
this.samplerConfiguration.setPercentage(0f);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor).next()).isFalse();
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor).isSampled()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,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();
|
||||
boolean passed = new PercentageBasedSampler(this.samplerConfiguration, traceReturningSpanWithUuid()).isSampled();
|
||||
passedCounter = passedCounter + (passed ? 1 : 0);
|
||||
}
|
||||
return passedCounter;
|
||||
|
||||
Reference in New Issue
Block a user