Sha256: 849c2d8fdf7e2e7f9ef5eb114555085415a5db1f7816eff4b0c2920f584d9994

Contents?: true

Size: 805 Bytes

Versions: 7

Compression:

Stored size: 805 Bytes

Contents

# frozen_string_literal: true

# @api public
# @since 1.5.0
module RedisQueuedLocks::Logging::Sampler
  # @return [Range]
  #
  # @api private
  # @since 1.6.0
  SAMPLING_PERCENT_RANGE = (0..100)

  class << self
    # Super simple probalistic function based on the `weight` of <true>/<false> values.
    # Requires the <percent> parameter as the required percent of <true> values sampled.
    #
    # @param sampling_percent [Integer]
    #   - percent of <true> values in range of 0..100;
    # @return [Boolean]
    #   - <true> for <sampling_percent>% of invocations (and <false> for the rest invocations)
    #
    # @api public
    # @since 1.5.0
    # @version 1.6.0
    def sampling_happened?(sampling_percent)
      sampling_percent >= SecureRandom.rand(SAMPLING_PERCENT_RANGE)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
redis_queued_locks-1.12.1 lib/redis_queued_locks/logging/sampler.rb
redis_queued_locks-1.12.0 lib/redis_queued_locks/logging/sampler.rb
redis_queued_locks-1.11.0 lib/redis_queued_locks/logging/sampler.rb
redis_queued_locks-1.10.0 lib/redis_queued_locks/logging/sampler.rb
redis_queued_locks-1.9.0 lib/redis_queued_locks/logging/sampler.rb
redis_queued_locks-1.8.0 lib/redis_queued_locks/logging/sampler.rb
redis_queued_locks-1.7.0 lib/redis_queued_locks/logging/sampler.rb