I am adapting the boundary sampler for a use case of mine. In my case, the input is not the long traceid value, instead a list of alphanumeric Strings (UUIDs). I implemented the following, is this a right way to sample requests?
public boolean isSampled(List<String> samplingStrings) {
if (samplingStrings.isEmpty()) {
return random.nextDouble() > probability;
}
long hashId = Math.abs(Objects.hash(samplingStrings.toArray()));
return hashId % 10000 <= boundary;
}
The original implementation from https://github.com/openzipkin/brave/blob/master/brave/src/main/java/brave/sampler/BoundarySampler.java
public boolean isSampled(long traceId) {
long t = Math.abs(traceId ^ SALT);
return t % 10000 <= boundary;
}
boundary is defined as follows:
final long boundary = (long) (probability * 10000);
probability should be between 0.0001 to 1.0
I also require the sampling to be idempotent. For the same set of Strings, require the same result all the time.
Will my implementation provide me the proper sampling based on the probability. Is there a better way to achieve it?
Aucun commentaire:
Enregistrer un commentaire