Class: OpenCensus::Trace::Samplers::MaxQPS
- Inherits:
-
Object
- Object
- OpenCensus::Trace::Samplers::MaxQPS
- Defined in:
- lib/opencensus/trace/samplers/max_qps.rb
Overview
The MaxQPS sampler delays a minimum amount of time between each sample, enforcing a maximum QPS across traces that use this sampler.
Instance Method Summary collapse
-
#call(_opts = {}) ⇒ boolean
Implements the sampler contract.
-
#initialize(qps = 0.1) ⇒ MaxQPS
constructor
Create a sampler for the given QPS.
Constructor Details
#initialize(qps = 0.1) ⇒ MaxQPS
Create a sampler for the given QPS.
28 29 30 31 |
# File 'lib/opencensus/trace/samplers/max_qps.rb', line 28 def initialize qps = 0.1 @delay_secs = 1.0 / qps @last_time = ::Time.now.to_f - @delay_secs end |
Instance Method Details
#call(_opts = {}) ⇒ boolean
Implements the sampler contract. Checks to see whether a sample should be taken at this time.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/opencensus/trace/samplers/max_qps.rb', line 39 def call _opts = {} time = ::Time.now.to_f delays = (time - @last_time) / @delay_secs if delays >= 2.0 @last_time = time - @delay_secs true elsif delays >= 1.0 @last_time += @delay_secs true else false end end |