Class: LaunchDarkly::Impl::Migrations::OpTracker Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Migrations::OpTracker
- Defined in:
- lib/ldclient-rb/impl/migrations/tracker.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.
Instance Method Summary collapse
- #build ⇒ Object private
- #consistent(is_consistent) ⇒ Object private
- #error(origin) ⇒ Object private
-
#initialize(logger, key, flag, context, detail, default_stage) ⇒ OpTracker
constructor
private
A new instance of OpTracker.
- #invoked(origin) ⇒ Object private
- #latency(origin, duration) ⇒ Object private
- #operation(operation) ⇒ Object private
Constructor Details
#initialize(logger, key, flag, context, detail, default_stage) ⇒ OpTracker
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 OpTracker.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ldclient-rb/impl/migrations/tracker.rb', line 20 def initialize(logger, key, flag, context, detail, default_stage) @logger = logger @key = key @flag = flag @context = context @detail = detail @default_stage = default_stage @sampler = LaunchDarkly::Impl::Sampler.new(Random.new) @mutex = Mutex.new # @type [Symbol, nil] @operation = nil # @type [Set<Symbol>] @invoked = Set.new # @type [Boolean, nil] @consistent = nil # @type [Int] @consistent_ratio = @flag&.migration_settings&.check_ratio @consistent_ratio = 1 if @consistent_ratio.nil? # @type [Set<Symbol>] @errors = Set.new # @type [Hash<Symbol, Float>] @latencies = Hash.new end |
Instance Method Details
#build ⇒ Object
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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/ldclient-rb/impl/migrations/tracker.rb', line 95 def build @mutex.synchronize do return "operation cannot contain an empty key" if @key.empty? return "operation not provided" if @operation.nil? return "no origins were invoked" if @invoked.empty? return "provided context was invalid" unless @context.valid? result = check_invoked_consistency return result unless result == true LaunchDarkly::Impl::MigrationOpEvent.new( LaunchDarkly::Impl::Util.current_time_millis, @context, @key, @flag, @operation, @default_stage, @detail, @invoked, @consistent, @consistent_ratio, @errors, @latencies ) end end |
#consistent(is_consistent) ⇒ Object
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.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ldclient-rb/impl/migrations/tracker.rb', line 65 def consistent(is_consistent) @mutex.synchronize do if @sampler.sample(@consistent_ratio) begin @consistent = is_consistent.call rescue => e Impl::Util.log_exception(@logger, "Exception raised during consistency check; failed to record measurement", e) end end end end |
#error(origin) ⇒ Object
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.
77 78 79 80 81 82 83 |
# File 'lib/ldclient-rb/impl/migrations/tracker.rb', line 77 def error(origin) return unless LaunchDarkly::Migrations::VALID_ORIGINS.include? origin @mutex.synchronize do @errors.add(origin) end end |
#invoked(origin) ⇒ Object
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.
57 58 59 60 61 62 63 |
# File 'lib/ldclient-rb/impl/migrations/tracker.rb', line 57 def invoked(origin) return unless LaunchDarkly::Migrations::VALID_ORIGINS.include? origin @mutex.synchronize do @invoked.add(origin) end end |
#latency(origin, duration) ⇒ Object
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.
85 86 87 88 89 90 91 92 93 |
# File 'lib/ldclient-rb/impl/migrations/tracker.rb', line 85 def latency(origin, duration) return unless LaunchDarkly::Migrations::VALID_ORIGINS.include? origin return unless duration.is_a? Numeric return if duration < 0 @mutex.synchronize do @latencies[origin] = duration end end |
#operation(operation) ⇒ Object
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.
49 50 51 52 53 54 55 |
# File 'lib/ldclient-rb/impl/migrations/tracker.rb', line 49 def operation(operation) return unless LaunchDarkly::Migrations::VALID_OPERATIONS.include? operation @mutex.synchronize do @operation = operation end end |