launchdarkly-server-sdk 8.11.2-java → 8.12.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ldclient-rb/config.rb +69 -9
  3. data/lib/ldclient-rb/context.rb +1 -1
  4. data/lib/ldclient-rb/data_system.rb +227 -0
  5. data/lib/ldclient-rb/events.rb +34 -19
  6. data/lib/ldclient-rb/flags_state.rb +1 -1
  7. data/lib/ldclient-rb/impl/big_segments.rb +4 -4
  8. data/lib/ldclient-rb/impl/cache_store.rb +44 -0
  9. data/lib/ldclient-rb/impl/data_source/polling.rb +108 -0
  10. data/lib/ldclient-rb/impl/data_source/requestor.rb +113 -0
  11. data/lib/ldclient-rb/impl/data_source/status_provider.rb +83 -0
  12. data/lib/ldclient-rb/impl/data_source/stream.rb +198 -0
  13. data/lib/ldclient-rb/impl/data_source.rb +3 -3
  14. data/lib/ldclient-rb/impl/data_store/data_kind.rb +108 -0
  15. data/lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb +187 -0
  16. data/lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb +130 -0
  17. data/lib/ldclient-rb/impl/data_store/status_provider.rb +76 -0
  18. data/lib/ldclient-rb/impl/data_store/store.rb +371 -0
  19. data/lib/ldclient-rb/impl/data_store.rb +11 -97
  20. data/lib/ldclient-rb/impl/data_system/data_source_builder_common.rb +77 -0
  21. data/lib/ldclient-rb/impl/data_system/fdv1.rb +20 -7
  22. data/lib/ldclient-rb/impl/data_system/fdv2.rb +472 -0
  23. data/lib/ldclient-rb/impl/data_system/http_config_options.rb +32 -0
  24. data/lib/ldclient-rb/impl/data_system/polling.rb +628 -0
  25. data/lib/ldclient-rb/impl/data_system/protocolv2.rb +264 -0
  26. data/lib/ldclient-rb/impl/data_system/streaming.rb +401 -0
  27. data/lib/ldclient-rb/impl/dependency_tracker.rb +21 -9
  28. data/lib/ldclient-rb/impl/evaluator.rb +3 -2
  29. data/lib/ldclient-rb/impl/event_sender.rb +14 -6
  30. data/lib/ldclient-rb/impl/expiring_cache.rb +79 -0
  31. data/lib/ldclient-rb/impl/integrations/file_data_source.rb +8 -8
  32. data/lib/ldclient-rb/impl/integrations/file_data_source_v2.rb +460 -0
  33. data/lib/ldclient-rb/impl/integrations/test_data/test_data_source_v2.rb +290 -0
  34. data/lib/ldclient-rb/impl/memoized_value.rb +34 -0
  35. data/lib/ldclient-rb/impl/migrations/migrator.rb +2 -1
  36. data/lib/ldclient-rb/impl/migrations/tracker.rb +2 -1
  37. data/lib/ldclient-rb/impl/model/serialization.rb +6 -6
  38. data/lib/ldclient-rb/impl/non_blocking_thread_pool.rb +48 -0
  39. data/lib/ldclient-rb/impl/repeating_task.rb +2 -2
  40. data/lib/ldclient-rb/impl/simple_lru_cache.rb +27 -0
  41. data/lib/ldclient-rb/impl/store_data_set_sorter.rb +1 -1
  42. data/lib/ldclient-rb/impl/util.rb +71 -0
  43. data/lib/ldclient-rb/impl.rb +1 -2
  44. data/lib/ldclient-rb/in_memory_store.rb +1 -18
  45. data/lib/ldclient-rb/integrations/file_data.rb +67 -0
  46. data/lib/ldclient-rb/integrations/test_data/flag_builder.rb +9 -9
  47. data/lib/ldclient-rb/integrations/test_data.rb +11 -11
  48. data/lib/ldclient-rb/integrations/test_data_v2/flag_builder_v2.rb +582 -0
  49. data/lib/ldclient-rb/integrations/test_data_v2.rb +254 -0
  50. data/lib/ldclient-rb/integrations/util/store_wrapper.rb +3 -2
  51. data/lib/ldclient-rb/interfaces/data_system.rb +704 -0
  52. data/lib/ldclient-rb/interfaces/feature_store.rb +5 -2
  53. data/lib/ldclient-rb/ldclient.rb +66 -132
  54. data/lib/ldclient-rb/util.rb +11 -70
  55. data/lib/ldclient-rb/version.rb +1 -1
  56. data/lib/ldclient-rb.rb +9 -17
  57. metadata +41 -19
  58. data/lib/ldclient-rb/cache_store.rb +0 -45
  59. data/lib/ldclient-rb/expiring_cache.rb +0 -77
  60. data/lib/ldclient-rb/memoized_value.rb +0 -32
  61. data/lib/ldclient-rb/non_blocking_thread_pool.rb +0 -46
  62. data/lib/ldclient-rb/polling.rb +0 -102
  63. data/lib/ldclient-rb/requestor.rb +0 -102
  64. data/lib/ldclient-rb/simple_lru_cache.rb +0 -25
  65. data/lib/ldclient-rb/stream.rb +0 -197
@@ -1,4 +1,5 @@
1
1
  require 'ldclient-rb/impl/integrations/file_data_source'
2
+ require 'ldclient-rb/impl/integrations/file_data_source_v2'
2
3
 
3
4
  module LaunchDarkly
4
5
  module Integrations
@@ -103,6 +104,72 @@ module LaunchDarkly
103
104
  lambda { |sdk_key, config|
104
105
  Impl::Integrations::FileDataSourceImpl.new(config.feature_store, config.data_source_update_sink, config.logger, options) }
105
106
  end
107
+
108
+ #
109
+ # Returns a builder for the FDv2-compatible file data source.
110
+ #
111
+ # This method is not stable, and not subject to any backwards compatibility guarantees or semantic versioning.
112
+ # It is in early access. If you want access to this feature please join the EAP. https://launchdarkly.com/docs/sdk/features/data-saving-mode
113
+ #
114
+ # This method returns a builder proc that can be used with the FDv2 data system
115
+ # configuration as both an Initializer and a Synchronizer. When used as an Initializer
116
+ # (via `fetch`), it reads files once. When used as a Synchronizer (via `sync`), it
117
+ # watches for file changes and automatically updates when files are modified.
118
+ #
119
+ # @param options [Hash] the configuration options
120
+ # @option options [Array<String>, String] :paths The paths of the source files for loading flag data. These
121
+ # may be absolute paths or relative to the current working directory. (Required)
122
+ # @option options [Float] :poll_interval The minimum interval, in seconds, between checks for
123
+ # file modifications - used only if the native file-watching mechanism from 'listen' is not
124
+ # being used. The default value is 1 second.
125
+ # @return [FileDataSourceV2Builder] a builder that can be used as an FDv2 initializer or synchronizer
126
+ #
127
+ # @example Using as an initializer
128
+ # file_source = LaunchDarkly::Integrations::FileData.data_source_v2(paths: ['flags.json'])
129
+ # data_system_config = LaunchDarkly::DataSystemConfig.new(
130
+ # initializers: [file_source]
131
+ # )
132
+ # config = LaunchDarkly::Config.new(data_system: data_system_config)
133
+ #
134
+ # @example Using as a synchronizer
135
+ # file_source = LaunchDarkly::Integrations::FileData.data_source_v2(paths: ['flags.json'])
136
+ # data_system_config = LaunchDarkly::DataSystemConfig.new(
137
+ # synchronizers: [file_source]
138
+ # )
139
+ # config = LaunchDarkly::Config.new(data_system: data_system_config)
140
+ #
141
+ # @example Using as both initializer and synchronizer
142
+ # file_source = LaunchDarkly::Integrations::FileData.data_source_v2(paths: ['flags.json'])
143
+ # data_system_config = LaunchDarkly::DataSystemConfig.new(
144
+ # initializers: [file_source],
145
+ # synchronizers: [file_source]
146
+ # )
147
+ # config = LaunchDarkly::Config.new(data_system: data_system_config)
148
+ #
149
+ def self.data_source_v2(options = {})
150
+ paths = options[:paths] || []
151
+ poll_interval = options[:poll_interval] || 1
152
+
153
+ FileDataSourceV2Builder.new(paths, poll_interval)
154
+ end
155
+ end
156
+
157
+ #
158
+ # Builder for FileDataSourceV2.
159
+ #
160
+ class FileDataSourceV2Builder
161
+ def initialize(paths, poll_interval)
162
+ @paths = paths
163
+ @poll_interval = poll_interval
164
+ end
165
+
166
+ def build(_sdk_key, config)
167
+ Impl::Integrations::FileDataSourceV2.new(
168
+ config.logger,
169
+ paths: @paths,
170
+ poll_interval: @poll_interval
171
+ )
172
+ end
106
173
  end
107
174
  end
108
175
  end
@@ -12,14 +12,14 @@ module LaunchDarkly
12
12
  class FlagBuilder
13
13
  attr_reader :key
14
14
 
15
- # @private
15
+ # @api private
16
16
  def initialize(key)
17
17
  @key = key
18
18
  @on = true
19
19
  @variations = []
20
20
  end
21
21
 
22
- # @private
22
+ # @api private
23
23
  def initialize_copy(other)
24
24
  super(other)
25
25
  @variations = @variations.clone
@@ -357,7 +357,7 @@ module LaunchDarkly
357
357
  self
358
358
  end
359
359
 
360
- # @private
360
+ # @api private
361
361
  def add_rule(rule)
362
362
  if @rules.nil?
363
363
  @rules = Array.new
@@ -386,7 +386,7 @@ module LaunchDarkly
386
386
  end
387
387
  end
388
388
 
389
- # @private
389
+ # @api private
390
390
  def build(version)
391
391
  res = { key: @key,
392
392
  version: version,
@@ -486,16 +486,16 @@ module LaunchDarkly
486
486
  # Finally, call {#then_return} to finish defining the rule.
487
487
  #
488
488
  class FlagRuleBuilder
489
- # @private
489
+ # @api private
490
490
  FlagRuleClause = Struct.new(:contextKind, :attribute, :op, :values, :negate, keyword_init: true) # rubocop:disable Naming/MethodName:
491
491
 
492
- # @private
492
+ # @api private
493
493
  def initialize(flag_builder)
494
494
  @flag_builder = flag_builder
495
495
  @clauses = Array.new
496
496
  end
497
497
 
498
- # @private
498
+ # @api private
499
499
  def intialize_copy(other)
500
500
  super(other)
501
501
  @clauses = @clauses.clone
@@ -612,7 +612,7 @@ module LaunchDarkly
612
612
  end
613
613
  end
614
614
 
615
- # @private
615
+ # @api private
616
616
  def build(ri)
617
617
  {
618
618
  id: 'rule' + ri.to_s,
@@ -622,7 +622,7 @@ module LaunchDarkly
622
622
  end
623
623
  end
624
624
 
625
- # @private
625
+ # @api private
626
626
  def variation_for_boolean(variation)
627
627
  variation ? TRUE_VARIATION_INDEX : FALSE_VARIATION_INDEX
628
628
  end
@@ -42,7 +42,7 @@ module LaunchDarkly
42
42
  self.new
43
43
  end
44
44
 
45
- # @private
45
+ # @api private
46
46
  def initialize
47
47
  @flag_builders = Hash.new
48
48
  @current_flags = Hash.new
@@ -56,7 +56,7 @@ module LaunchDarkly
56
56
  # Called internally by the SDK to determine what arguments to pass to call
57
57
  # You do not need to call this method.
58
58
  #
59
- # @private
59
+ # @api private
60
60
  def arity
61
61
  2
62
62
  end
@@ -65,7 +65,7 @@ module LaunchDarkly
65
65
  # Called internally by the SDK to associate this test data source with an {@code LDClient} instance.
66
66
  # You do not need to call this method.
67
67
  #
68
- # @private
68
+ # @api private
69
69
  def call(_, config)
70
70
  impl = LaunchDarkly::Impl::Integrations::TestData::TestDataSource.new(config.feature_store, self)
71
71
  @instances_lock.with_write_lock { @instances.push(impl) }
@@ -121,10 +121,10 @@ module LaunchDarkly
121
121
  if @current_flags[flag_key]
122
122
  version = @current_flags[flag_key][:version]
123
123
  end
124
- new_flag = Impl::Model.deserialize(FEATURES, flag_builder.build(version+1))
124
+ new_flag = LaunchDarkly::Impl::Model.deserialize(LaunchDarkly::Impl::DataStore::FEATURES, flag_builder.build(version+1))
125
125
  @current_flags[flag_key] = new_flag
126
126
  end
127
- update_item(FEATURES, new_flag)
127
+ update_item(LaunchDarkly::Impl::DataStore::FEATURES, new_flag)
128
128
  self
129
129
  end
130
130
 
@@ -147,7 +147,7 @@ module LaunchDarkly
147
147
  # @return [TestData] the TestData instance
148
148
  #
149
149
  def use_preconfigured_flag(flag)
150
- use_preconfigured_item(FEATURES, flag, @current_flags)
150
+ use_preconfigured_item(LaunchDarkly::Impl::DataStore::FEATURES, flag, @current_flags)
151
151
  end
152
152
 
153
153
  #
@@ -167,7 +167,7 @@ module LaunchDarkly
167
167
  # @return [TestData] the TestData instance
168
168
  #
169
169
  def use_preconfigured_segment(segment)
170
- use_preconfigured_item(SEGMENTS, segment, @current_segments)
170
+ use_preconfigured_item(LaunchDarkly::Impl::DataStore::SEGMENTS, segment, @current_segments)
171
171
  end
172
172
 
173
173
  private def use_preconfigured_item(kind, item, current)
@@ -194,17 +194,17 @@ module LaunchDarkly
194
194
  end
195
195
  end
196
196
 
197
- # @private
197
+ # @api private
198
198
  def make_init_data
199
199
  @lock.with_read_lock do
200
200
  {
201
- FEATURES => @current_flags.clone,
202
- SEGMENTS => @current_segments.clone,
201
+ LaunchDarkly::Impl::DataStore::FEATURES => @current_flags.clone,
202
+ LaunchDarkly::Impl::DataStore::SEGMENTS => @current_segments.clone,
203
203
  }
204
204
  end
205
205
  end
206
206
 
207
- # @private
207
+ # @api private
208
208
  def closed_instance(instance)
209
209
  @instances_lock.with_write_lock { @instances.delete(instance) }
210
210
  end