SamplingFlags isSampled() { return sampler.isSampled(0L) // counting sampler ignores the input ? SamplingFlags.SAMPLED : SamplingFlags.NOT_SAMPLED; } }
/** * Returns a sampler, given a rate expressed as a percentage. * * <p>The sampler returned is good for low volumes of traffic (<100K requests), as it is precise. * If you have high volumes of traffic, consider {@link BoundarySampler}. * * @param rate minimum sample rate is 0.01, or 1% of traces */ public static Sampler create(float rate) { return CountingSampler.create(rate); } }
public static <M> DeclarativeSampler<M> create(RateForMethod<M> rateForMethod) { return new DeclarativeSampler<>(rateForMethod); }
public SamplingFlags sample(@Nullable M method) { if (method == null) return SamplingFlags.EMPTY; Sampler sampler = methodsToSamplers.get(method); if (sampler == NULL_SENTINEL) return SamplingFlags.EMPTY; if (sampler != null) return sample(sampler); Float rate = rateForMethod.get(method); if (rate == null) { methodsToSamplers.put(method, NULL_SENTINEL); return SamplingFlags.EMPTY; } sampler = CountingSampler.create(rate); Sampler previousSampler = methodsToSamplers.putIfAbsent(method, sampler); if (previousSampler != null) sampler = previousSampler; // lost race, use the existing counter return sample(sampler); }
RateLimitingSampler(int tracesPerSecond) { this.maxFunction = tracesPerSecond < 10 ? new LessThan10(tracesPerSecond) : new AtLeast10(tracesPerSecond); long now = System.nanoTime(); this.nextReset = new AtomicLong(now + NANOS_PER_SECOND); }
HttpRuleSampler(List<MethodAndPathRule> rules) { this.sampler = ParameterizedSampler.create(rules); }
/** * @param rate 0 means never sample, 1 means always sample. Otherwise minimum sample rate is 0.01, * or 1% of traces */ public static Sampler create(final float rate) { if (rate == 0) return NEVER_SAMPLE; if (rate == 1.0) return ALWAYS_SAMPLE; if (rate < 0.01f || rate > 1) { throw new IllegalArgumentException("rate should be between 0.01 and 1: was " + rate); } return new CountingSampler(rate); }
/** * Fills a bitset with decisions according to the supplied rate with the supplied {@link Random}. */ CountingSampler(float rate, Random random) { counter = new AtomicInteger(); int outOf100 = (int) (rate * 100.0f); this.sampleDecisions = randomBitSet(100, outOf100, random); }
public static Sampler create(int tracesPerSecond) { if (tracesPerSecond < 0) throw new IllegalArgumentException("tracesPerSecond < 0"); if (tracesPerSecond == 0) return Sampler.NEVER_SAMPLE; return new RateLimitingSampler(tracesPerSecond); }
/** * @param rate 0 means never sample, 1 means always sample. Otherwise minimum sample rate is * 0.0001, or 0.01% of traces */ public static Sampler create(float rate) { if (rate == 0) return Sampler.NEVER_SAMPLE; if (rate == 1.0) return ALWAYS_SAMPLE; if (rate < 0.0001f || rate > 1) { throw new IllegalArgumentException("rate should be between 0.0001 and 1: was " + rate); } final long boundary = (long) (rate * 10000); // safe cast as less <= 1 return new BoundarySampler(boundary); }
public static <P> ParameterizedSampler<P> create(List<? extends Rule<P>> rules) { if (rules == null) throw new NullPointerException("rules == null"); return new ParameterizedSampler<>(rules); }
@Override public boolean isSampled(long traceId) { Boolean decision = sample(method).sampled(); return decision != null ? decision : false; } };
private SamplingFlags sample(Sampler sampler) { return sampler.isSampled(0L) // counting sampler ignores the input ? SamplingFlags.SAMPLED : SamplingFlags.NOT_SAMPLED; }
/** * @param rate percentage of requests to start traces for. 1.0 is 100% */ protected Rule(float rate) { sampler = CountingSampler.create(rate); }
@Override public boolean isSampled(long traceId) { return this.sampler.isSampled(traceId); }
@Override public boolean isSampled(long traceId) { Boolean decision = trySample(adapter, request); if (decision == null) return delegate.isSampled(traceId); return decision; } };
@Benchmark public boolean sampler_counting(Args args) { return SAMPLER_RATE.isSampled(args.traceId); }
@Benchmark public boolean sampler_rateLimited_1(Args args) { return SAMPLER_RATE_LIMITED.isSampled(args.traceId); }