Class: Datadog::AppSec::CounterSampler Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/appsec/counter_sampler.rb

Overview

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

Sampler that uses an internal counter to make deterministic sampling decisions.

Each call to #sample? increments the counter and uses it as input to the underlying Knuth multiplicative hash algorithm.

Instance Method Summary collapse

Constructor Details

#initialize(rate = 1.0) ⇒ CounterSampler

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

Returns a new instance of CounterSampler.



14
15
16
17
# File 'lib/datadog/appsec/counter_sampler.rb', line 14

def initialize(rate = 1.0)
  @sampler = Core::KnuthSampler.new(rate)
  @counter = 0
end

Instance Method Details

#sample?Boolean

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

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/datadog/appsec/counter_sampler.rb', line 19

def sample?
  @counter += 1
  @sampler.sample?(@counter)
end