Module: RedisQueuedLocks::Instrument::Sampler

Defined in:
lib/redis_queued_locks/instrument/sampler.rb

Overview

Since:

  • 1.6.0

Constant Summary collapse

SAMPLING_PERCENT_RANGE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns:

  • (Range)

Since:

  • 1.6.0

(0..100)

Class Method Summary collapse

Class Method Details

.sampling_happened?(sampling_percent) ⇒ Boolean

Super simple probalistic function based on the weight of / values. Requires the parameter as the required percent of values sampled.

Parameters:

  • sampling_percent (Integer) —
    • percent of values in range of 0..100;

Returns:

  • (Boolean) —
    • for <sampling_percent>% of invocations (and for the rest invocations)

Since:

  • 1.6.0



23
24
25
# File 'lib/redis_queued_locks/instrument/sampler.rb', line 23

def sampling_happened?(sampling_percent)
  sampling_percent >= SecureRandom.rand(SAMPLING_PERCENT_RANGE)
end