Module: RedisQueuedLocks::Instrument
- Defined in:
- lib/redis_queued_locks/instrument.rb
Overview
Defined Under Namespace
Modules: ActiveSupport, Sampler, VoidNotifier
Class Method Summary collapse
- .should_instrument?(instr_sampling_enabled, instr_sample_this, instr_sampling_percent, instr_sampler) ⇒ Boolean private
- .valid_interface?(instrumenter) ⇒ Boolean
- .valid_sampler?(sampler) ⇒ Boolean private
Class Method Details
.should_instrument?(instr_sampling_enabled, instr_sample_this, instr_sampling_percent, instr_sampler) ⇒ 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.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/redis_queued_locks/instrument.rb', line 20 def should_instrument?( instr_sampling_enabled, instr_sample_this, instr_sampling_percent, instr_sampler ) return true unless instr_sampling_enabled return true if instr_sample_this instr_sampler.sampling_happened?(instr_sampling_percent) end |
.valid_interface?(instrumenter) ⇒ Boolean
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/redis_queued_locks/instrument.rb', line 75 def valid_interface?(instrumenter) if instrumenter == RedisQueuedLocks::Instrument::ActiveSupport # NOTE: active_support should be required in your app !!defined?(::ActiveSupport::Notifications) elsif instrumenter.respond_to?(:notify) # NOTE: the method signature should be (event, payload). Supported variants: # => [[:req, :event], [:req, :payload]] # => [[:req, :event], [:opt, :payload]] # => [[:opt, :event], [:opt, :payload]] # @type var m_obj: Method m_obj = instrumenter.method(:notify) m_sig = m_obj.parameters if m_sig.size == 2 f_prm = m_sig[0][0] s_prm = m_sig[1][0] # rubocop:disable Layout/MultilineOperationIndentation # NOTE: check the signature vairants f_prm == :req && s_prm == :req || f_prm == :req && s_prm == :opt || f_prm == :opt && s_prm == :opt # rubocop:enable Layout/MultilineOperationIndentation else # NOTE: incompatible signature false end else # NOTE: no required method :notify false end end |
.valid_sampler?(sampler) ⇒ 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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/redis_queued_locks/instrument.rb', line 36 def valid_sampler?(sampler) return false unless sampler.respond_to?(:sampling_happened?) # @type var m_obj: Method m_obj = sampler.method(:sampling_happened?) m_sig = m_obj.parameters # NOTE: # Required method signature (sampling_percent) # => [[:req, :sampling_percent]] # => [[:opt, :sampling_percent]] # => [[:req, :sampling_percent], [:block, :block]] # => [[:opt, :sampling_percent], [:block, :block]] case m_sig.size when 1 # => [[:req, :sampling_percent]] # => [[:opt, :sampling_percent]] prm = m_sig[0][0] prm == :req || prm == :opt when 2 # => [[:req, :sampling_percent], [:block, :block]] # => [[:opt, :sampling_percent], [:block, :block]] f_prm = m_sig[0][0] s_prm = m_sig[1][0] # rubocop:disable Layout/MultilineOperationIndentation f_prm == :req && s_prm == :block || f_prm == :opt && s_prm == :block # rubocop:enable Layout/MultilineOperationIndentation else false end end |