Class: Jaeger::Samplers::GuaranteedThroughputProbabilistic

Inherits:
Object
  • Object
show all
Defined in:
lib/jaeger/samplers/guaranteed_throughput_probabilistic.rb

Overview

A sampler that leverages both Probabilistic sampler and RateLimiting sampler. The RateLimiting is used as a guaranteed lower bound sampler such that every operation is sampled at least once in a time interval defined by the lower_bound. ie a lower_bound of 1.0 / (60 * 10) will sample an operation at least once every 10 minutes.

The Probabilistic sampler is given higher priority when tags are emitted, ie. if is_sampled() for both samplers return true, the tags for Probabilistic sampler will be used.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lower_bound:, rate:, lower_bound_sampler: nil) ⇒ GuaranteedThroughputProbabilistic

Returns a new instance of GuaranteedThroughputProbabilistic.



17
18
19
20
21
22
23
24
# File 'lib/jaeger/samplers/guaranteed_throughput_probabilistic.rb', line 17

def initialize(lower_bound:, rate:, lower_bound_sampler: nil)
  @probabilistic_sampler = Probabilistic.new(rate: rate)
  @lower_bound_sampler = lower_bound_sampler || RateLimiting.new(max_traces_per_second: lower_bound)
  @lower_bound_tags = {
    'sampler.type' => 'lowerbound',
    'sampler.param' => rate
  }
end

Instance Attribute Details

#lower_bound_samplerObject (readonly)

Returns the value of attribute lower_bound_sampler.



15
16
17
# File 'lib/jaeger/samplers/guaranteed_throughput_probabilistic.rb', line 15

def lower_bound_sampler
  @lower_bound_sampler
end

#probabilistic_samplerObject (readonly)

Returns the value of attribute probabilistic_sampler.



15
16
17
# File 'lib/jaeger/samplers/guaranteed_throughput_probabilistic.rb', line 15

def probabilistic_sampler
  @probabilistic_sampler
end

#tagsObject (readonly)

Returns the value of attribute tags.



15
16
17
# File 'lib/jaeger/samplers/guaranteed_throughput_probabilistic.rb', line 15

def tags
  @tags
end

Instance Method Details

#sampleObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jaeger/samplers/guaranteed_throughput_probabilistic.rb', line 33

def sample(...)
  is_sampled, probabilistic_tags = @probabilistic_sampler.sample(...)
  if is_sampled
    # We still call lower_bound_sampler to update the rate limiter budget
    @lower_bound_sampler.sample(...)

    return [is_sampled, probabilistic_tags]
  end

  is_sampled, _tags = @lower_bound_sampler.sample(...)
  [is_sampled, @lower_bound_tags]
end

#update(lower_bound:, rate:) ⇒ Object



26
27
28
29
30
31
# File 'lib/jaeger/samplers/guaranteed_throughput_probabilistic.rb', line 26

def update(lower_bound:, rate:)
  is_updated = @probabilistic_sampler.update(rate: rate)
  is_updated = @lower_bound_sampler.update(max_traces_per_second: lower_bound) || is_updated
  @lower_bound_tags['sampler.param'] = rate
  is_updated
end