Class: Jaeger::Samplers::RemoteControlled
- Inherits:
-
Object
- Object
- Jaeger::Samplers::RemoteControlled
- Defined in:
- lib/jaeger/samplers/remote_controlled.rb,
lib/jaeger/samplers/remote_controlled/instructions_fetcher.rb
Defined Under Namespace
Classes: InstructionsFetcher
Constant Summary collapse
- DEFAULT_REFRESH_INTERVAL =
60
- DEFAULT_SAMPLING_HOST =
'localhost'.freeze
- DEFAULT_SAMPLING_PORT =
5778
Instance Attribute Summary collapse
-
#sampler ⇒ Object
readonly
Returns the value of attribute sampler.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ RemoteControlled
constructor
A new instance of RemoteControlled.
- #poll ⇒ Object
- #sample(*args) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ RemoteControlled
Returns a new instance of RemoteControlled.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jaeger/samplers/remote_controlled.rb', line 14 def initialize(opts = {}) @sampler = opts.fetch(:sampler, Probabilistic.new) @logger = opts.fetch(:logger, Logger.new($stdout)) @poll_executor = opts[:poll_executor] || begin refresh_interval = opts.fetch(:refresh_interval, DEFAULT_REFRESH_INTERVAL) RecurringExecutor.new(interval: refresh_interval) end @instructions_fetcher = opts[:instructions_fetcher] || begin service_name = opts.fetch(:service_name) host = opts.fetch(:host, DEFAULT_SAMPLING_HOST) port = opts.fetch(:port, DEFAULT_SAMPLING_PORT) InstructionsFetcher.new(host: host, port: port, service_name: service_name) end end |
Instance Attribute Details
#sampler ⇒ Object (readonly)
Returns the value of attribute sampler.
12 13 14 |
# File 'lib/jaeger/samplers/remote_controlled.rb', line 12 def sampler @sampler end |
Instance Method Details
#poll ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/jaeger/samplers/remote_controlled.rb', line 37 def poll @logger.debug 'Fetching sampling strategy' instructions = @instructions_fetcher.fetch handle_instructions(instructions) rescue InstructionsFetcher::FetchFailed => e @logger.warn "Fetching sampling strategy failed: #{e.}" end |
#sample(*args) ⇒ Object
31 32 33 34 35 |
# File 'lib/jaeger/samplers/remote_controlled.rb', line 31 def sample(*args) @poll_executor.start(&method(:poll)) unless @poll_executor.running? @sampler.sample(*args) end |