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:
Marcin Grzejszczak
2016-01-20 13:05:29 +01:00
parent e948855d98
commit 3c5625a9de
7 changed files with 10 additions and 10 deletions

View File

@@ -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();
}

View File

@@ -23,7 +23,7 @@ import org.springframework.cloud.sleuth.Sampler;
*/
public class AlwaysSampler implements Sampler {
@Override
public boolean next() {
public boolean isSampled() {
return true;
}
}

View File

@@ -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();
}
}

View File

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

View File

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

View File

@@ -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();
}
}
}

View File

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