Class: Datadog::AppSec::CounterSampler Private
- Inherits:
-
Object
- Object
- Datadog::AppSec::CounterSampler
- 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
-
#initialize(rate = 1.0) ⇒ CounterSampler
constructor
private
A new instance of CounterSampler.
- #sample? ⇒ Boolean private
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.
19 20 21 22 |
# File 'lib/datadog/appsec/counter_sampler.rb', line 19 def sample? @counter += 1 @sampler.sample?(@counter) end |