launchdarkly-server-sdk 8.8.3-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 (70) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +13 -0
  3. data/README.md +61 -0
  4. data/lib/launchdarkly-server-sdk.rb +1 -0
  5. data/lib/ldclient-rb/cache_store.rb +45 -0
  6. data/lib/ldclient-rb/config.rb +658 -0
  7. data/lib/ldclient-rb/context.rb +565 -0
  8. data/lib/ldclient-rb/evaluation_detail.rb +387 -0
  9. data/lib/ldclient-rb/events.rb +642 -0
  10. data/lib/ldclient-rb/expiring_cache.rb +77 -0
  11. data/lib/ldclient-rb/flags_state.rb +88 -0
  12. data/lib/ldclient-rb/impl/big_segments.rb +117 -0
  13. data/lib/ldclient-rb/impl/broadcaster.rb +78 -0
  14. data/lib/ldclient-rb/impl/context.rb +96 -0
  15. data/lib/ldclient-rb/impl/context_filter.rb +166 -0
  16. data/lib/ldclient-rb/impl/data_source.rb +188 -0
  17. data/lib/ldclient-rb/impl/data_store.rb +109 -0
  18. data/lib/ldclient-rb/impl/dependency_tracker.rb +102 -0
  19. data/lib/ldclient-rb/impl/diagnostic_events.rb +129 -0
  20. data/lib/ldclient-rb/impl/evaluation_with_hook_result.rb +34 -0
  21. data/lib/ldclient-rb/impl/evaluator.rb +539 -0
  22. data/lib/ldclient-rb/impl/evaluator_bucketing.rb +86 -0
  23. data/lib/ldclient-rb/impl/evaluator_helpers.rb +50 -0
  24. data/lib/ldclient-rb/impl/evaluator_operators.rb +131 -0
  25. data/lib/ldclient-rb/impl/event_sender.rb +100 -0
  26. data/lib/ldclient-rb/impl/event_summarizer.rb +68 -0
  27. data/lib/ldclient-rb/impl/event_types.rb +136 -0
  28. data/lib/ldclient-rb/impl/flag_tracker.rb +58 -0
  29. data/lib/ldclient-rb/impl/integrations/consul_impl.rb +170 -0
  30. data/lib/ldclient-rb/impl/integrations/dynamodb_impl.rb +300 -0
  31. data/lib/ldclient-rb/impl/integrations/file_data_source.rb +229 -0
  32. data/lib/ldclient-rb/impl/integrations/redis_impl.rb +306 -0
  33. data/lib/ldclient-rb/impl/integrations/test_data/test_data_source.rb +40 -0
  34. data/lib/ldclient-rb/impl/migrations/migrator.rb +287 -0
  35. data/lib/ldclient-rb/impl/migrations/tracker.rb +136 -0
  36. data/lib/ldclient-rb/impl/model/clause.rb +45 -0
  37. data/lib/ldclient-rb/impl/model/feature_flag.rb +254 -0
  38. data/lib/ldclient-rb/impl/model/preprocessed_data.rb +64 -0
  39. data/lib/ldclient-rb/impl/model/segment.rb +132 -0
  40. data/lib/ldclient-rb/impl/model/serialization.rb +72 -0
  41. data/lib/ldclient-rb/impl/repeating_task.rb +46 -0
  42. data/lib/ldclient-rb/impl/sampler.rb +25 -0
  43. data/lib/ldclient-rb/impl/store_client_wrapper.rb +141 -0
  44. data/lib/ldclient-rb/impl/store_data_set_sorter.rb +55 -0
  45. data/lib/ldclient-rb/impl/unbounded_pool.rb +34 -0
  46. data/lib/ldclient-rb/impl/util.rb +95 -0
  47. data/lib/ldclient-rb/impl.rb +13 -0
  48. data/lib/ldclient-rb/in_memory_store.rb +100 -0
  49. data/lib/ldclient-rb/integrations/consul.rb +45 -0
  50. data/lib/ldclient-rb/integrations/dynamodb.rb +92 -0
  51. data/lib/ldclient-rb/integrations/file_data.rb +108 -0
  52. data/lib/ldclient-rb/integrations/redis.rb +98 -0
  53. data/lib/ldclient-rb/integrations/test_data/flag_builder.rb +663 -0
  54. data/lib/ldclient-rb/integrations/test_data.rb +213 -0
  55. data/lib/ldclient-rb/integrations/util/store_wrapper.rb +246 -0
  56. data/lib/ldclient-rb/integrations.rb +6 -0
  57. data/lib/ldclient-rb/interfaces.rb +974 -0
  58. data/lib/ldclient-rb/ldclient.rb +822 -0
  59. data/lib/ldclient-rb/memoized_value.rb +32 -0
  60. data/lib/ldclient-rb/migrations.rb +230 -0
  61. data/lib/ldclient-rb/non_blocking_thread_pool.rb +46 -0
  62. data/lib/ldclient-rb/polling.rb +102 -0
  63. data/lib/ldclient-rb/reference.rb +295 -0
  64. data/lib/ldclient-rb/requestor.rb +102 -0
  65. data/lib/ldclient-rb/simple_lru_cache.rb +25 -0
  66. data/lib/ldclient-rb/stream.rb +196 -0
  67. data/lib/ldclient-rb/util.rb +132 -0
  68. data/lib/ldclient-rb/version.rb +3 -0
  69. data/lib/ldclient-rb.rb +27 -0
  70. metadata +400 -0
@@ -0,0 +1,658 @@
1
+ require "logger"
2
+
3
+ module LaunchDarkly
4
+ #
5
+ # This class exposes advanced configuration options for the LaunchDarkly
6
+ # client library. Most users will not need to use a custom configuration--
7
+ # the default configuration sets sane defaults for most use cases.
8
+ #
9
+ #
10
+ class Config
11
+ # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
12
+
13
+ #
14
+ # Constructor for creating custom LaunchDarkly configurations.
15
+ #
16
+ # @param opts [Hash] the configuration options
17
+ # @option opts [Logger] :logger See {#logger}.
18
+ # @option opts [String] :base_uri ("https://sdk.launchdarkly.com") See {#base_uri}.
19
+ # @option opts [String] :stream_uri ("https://stream.launchdarkly.com") See {#stream_uri}.
20
+ # @option opts [String] :events_uri ("https://events.launchdarkly.com") See {#events_uri}.
21
+ # @option opts [Integer] :capacity (10000) See {#capacity}.
22
+ # @option opts [Float] :flush_interval (30) See {#flush_interval}.
23
+ # @option opts [Float] :read_timeout (10) See {#read_timeout}.
24
+ # @option opts [Float] :initial_reconnect_delay (1) See {#initial_reconnect_delay}.
25
+ # @option opts [Float] :connect_timeout (2) See {#connect_timeout}.
26
+ # @option opts [Object] :cache_store See {#cache_store}.
27
+ # @option opts [Object] :feature_store See {#feature_store}.
28
+ # @option opts [Boolean] :use_ldd (false) See {#use_ldd?}.
29
+ # @option opts [Boolean] :offline (false) See {#offline?}.
30
+ # @option opts [Float] :poll_interval (30) See {#poll_interval}.
31
+ # @option opts [Boolean] :stream (true) See {#stream?}.
32
+ # @option opts [Boolean] all_attributes_private (false) See {#all_attributes_private}.
33
+ # @option opts [Array] :private_attributes See {#private_attributes}.
34
+ # @option opts [Boolean] :send_events (true) See {#send_events}.
35
+ # @option opts [Integer] :context_keys_capacity (1000) See {#context_keys_capacity}.
36
+ # @option opts [Float] :context_keys_flush_interval (300) See {#context_keys_flush_interval}.
37
+ # @option opts [Object] :data_source See {#data_source}.
38
+ # @option opts [Boolean] :diagnostic_opt_out (false) See {#diagnostic_opt_out?}.
39
+ # @option opts [Float] :diagnostic_recording_interval (900) See {#diagnostic_recording_interval}.
40
+ # @option opts [String] :wrapper_name See {#wrapper_name}.
41
+ # @option opts [String] :wrapper_version See {#wrapper_version}.
42
+ # @option opts [#open] :socket_factory See {#socket_factory}.
43
+ # @option opts [BigSegmentsConfig] :big_segments See {#big_segments}.
44
+ # @option opts [Hash] :application See {#application}
45
+ # @option opts [String] :payload_filter_key See {#payload_filter_key}
46
+ # @option opts [Boolean] :omit_anonymous_contexts See {#omit_anonymous_contexts}
47
+ # @option hooks [Array<Interfaces::Hooks::Hook]
48
+ #
49
+ def initialize(opts = {})
50
+ @base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
51
+ @stream_uri = (opts[:stream_uri] || Config.default_stream_uri).chomp("/")
52
+ @events_uri = (opts[:events_uri] || Config.default_events_uri).chomp("/")
53
+ @capacity = opts[:capacity] || Config.default_capacity
54
+ @logger = opts[:logger] || Config.default_logger
55
+ @cache_store = opts[:cache_store] || Config.default_cache_store
56
+ @flush_interval = opts[:flush_interval] || Config.default_flush_interval
57
+ @connect_timeout = opts[:connect_timeout] || Config.default_connect_timeout
58
+ @read_timeout = opts[:read_timeout] || Config.default_read_timeout
59
+ @initial_reconnect_delay = opts[:initial_reconnect_delay] || Config.default_initial_reconnect_delay
60
+ @feature_store = opts[:feature_store] || Config.default_feature_store
61
+ @stream = opts.has_key?(:stream) ? opts[:stream] : Config.default_stream
62
+ @use_ldd = opts.has_key?(:use_ldd) ? opts[:use_ldd] : Config.default_use_ldd
63
+ @offline = opts.has_key?(:offline) ? opts[:offline] : Config.default_offline
64
+ @poll_interval = opts.has_key?(:poll_interval) && opts[:poll_interval] > Config.default_poll_interval ? opts[:poll_interval] : Config.default_poll_interval
65
+ @all_attributes_private = opts[:all_attributes_private] || false
66
+ @private_attributes = opts[:private_attributes] || []
67
+ @send_events = opts.has_key?(:send_events) ? opts[:send_events] : Config.default_send_events
68
+ @compress_events = opts.has_key?(:compress_events) ? opts[:compress_events] : Config.default_compress_events
69
+ @context_keys_capacity = opts[:context_keys_capacity] || Config.default_context_keys_capacity
70
+ @context_keys_flush_interval = opts[:context_keys_flush_interval] || Config.default_context_keys_flush_interval
71
+ @data_source = opts[:data_source]
72
+ @diagnostic_opt_out = opts.has_key?(:diagnostic_opt_out) && opts[:diagnostic_opt_out]
73
+ @diagnostic_recording_interval = opts.has_key?(:diagnostic_recording_interval) && opts[:diagnostic_recording_interval] > Config.minimum_diagnostic_recording_interval ?
74
+ opts[:diagnostic_recording_interval] : Config.default_diagnostic_recording_interval
75
+ @wrapper_name = opts[:wrapper_name]
76
+ @wrapper_version = opts[:wrapper_version]
77
+ @socket_factory = opts[:socket_factory]
78
+ @big_segments = opts[:big_segments] || BigSegmentsConfig.new(store: nil)
79
+ @application = LaunchDarkly::Impl::Util.validate_application_info(opts[:application] || {}, @logger)
80
+ @payload_filter_key = LaunchDarkly::Impl::Util.validate_payload_filter_key(opts[:payload_filter_key] , @logger)
81
+ @hooks = (opts[:hooks] || []).keep_if { |hook| hook.is_a? Interfaces::Hooks::Hook }
82
+ @omit_anonymous_contexts = opts.has_key?(:omit_anonymous_contexts) && opts[:omit_anonymous_contexts]
83
+ @data_source_update_sink = nil
84
+ end
85
+
86
+ #
87
+ # Returns the component that allows a data source to push data into the SDK.
88
+ #
89
+ # This property should only be set by the SDK. Long term access of this
90
+ # property is not supported; it is temporarily being exposed to maintain
91
+ # backwards compatibility while the SDK structure is updated.
92
+ #
93
+ # Custom data source implementations should integrate with this sink if
94
+ # they want to provide support for data source status listeners.
95
+ #
96
+ # @private
97
+ #
98
+ attr_accessor :data_source_update_sink
99
+
100
+ #
101
+ # The base URL for the LaunchDarkly server. This is configurable mainly for testing
102
+ # purposes; most users should use the default value.
103
+ # @return [String]
104
+ #
105
+ attr_reader :base_uri
106
+
107
+ #
108
+ # The base URL for the LaunchDarkly streaming server. This is configurable mainly for testing
109
+ # purposes; most users should use the default value.
110
+ # @return [String]
111
+ #
112
+ attr_reader :stream_uri
113
+
114
+ #
115
+ # The base URL for the LaunchDarkly events server. This is configurable mainly for testing
116
+ # purposes; most users should use the default value.
117
+ # @return [String]
118
+ #
119
+ attr_reader :events_uri
120
+
121
+ #
122
+ # Whether streaming mode should be enabled. Streaming mode asynchronously updates
123
+ # feature flags in real-time using server-sent events. Streaming is enabled by default, and
124
+ # should only be disabled on the advice of LaunchDarkly support.
125
+ # @return [Boolean]
126
+ #
127
+ def stream?
128
+ @stream
129
+ end
130
+
131
+ #
132
+ # Whether to use the LaunchDarkly relay proxy in daemon mode. In this mode, the client does not
133
+ # use polling or streaming to get feature flag updates from the server, but instead reads them
134
+ # from the {#feature_store feature store}, which is assumed to be a database that is populated by
135
+ # a LaunchDarkly relay proxy. For more information, see ["The relay proxy"](https://docs.launchdarkly.com/home/relay-proxy)
136
+ # and ["Using a persistent data stores"](https://docs.launchdarkly.com/sdk/concepts/data-stores).
137
+ #
138
+ # All other properties related to streaming or polling are ignored if this option is set to true.
139
+ #
140
+ # @return [Boolean]
141
+ #
142
+ def use_ldd?
143
+ @use_ldd
144
+ end
145
+
146
+ #
147
+ # Whether the client should be initialized in offline mode. In offline mode, default values are
148
+ # returned for all flags and no remote network requests are made.
149
+ # @return [Boolean]
150
+ #
151
+ def offline?
152
+ @offline
153
+ end
154
+
155
+ #
156
+ # The number of seconds between flushes of the event buffer. Decreasing the flush interval means
157
+ # that the event buffer is less likely to reach capacity.
158
+ # @return [Float]
159
+ #
160
+ attr_reader :flush_interval
161
+
162
+ #
163
+ # The number of seconds to wait before polling for feature flag updates. This option has no
164
+ # effect unless streaming is disabled.
165
+ # @return [Float]
166
+ #
167
+ attr_reader :poll_interval
168
+
169
+ #
170
+ # The configured logger for the LaunchDarkly client. The client library uses the log to
171
+ # print warning and error messages. If not specified, this defaults to the Rails logger
172
+ # in a Rails environment, or stdout otherwise.
173
+ # @return [Logger]
174
+ #
175
+ attr_reader :logger
176
+
177
+ #
178
+ # The capacity of the events buffer. The client buffers up to this many
179
+ # events in memory before flushing. If the capacity is exceeded before
180
+ # the buffer is flushed, events will be discarded.
181
+ # Increasing the capacity means that events are less likely to be discarded,
182
+ # at the cost of consuming more memory.
183
+ # @return [Integer]
184
+ #
185
+ attr_reader :capacity
186
+
187
+ #
188
+ # A store for HTTP caching (used only in polling mode). This must support the semantics used by
189
+ # the [`faraday-http-cache`](https://github.com/plataformatec/faraday-http-cache) gem, although
190
+ # the SDK no longer uses Faraday. Defaults to the Rails cache in a Rails environment, or a
191
+ # thread-safe in-memory store otherwise.
192
+ # @return [Object]
193
+ #
194
+ attr_reader :cache_store
195
+
196
+ #
197
+ # The read timeout for network connections in seconds. This does not apply to the streaming
198
+ # connection, which uses a longer timeout since the server does not send data constantly.
199
+ # @return [Float]
200
+ #
201
+ attr_reader :read_timeout
202
+
203
+ #
204
+ # The initial delay before reconnecting after an error in the SSE client.
205
+ # This only applies to the streaming connection.
206
+ # @return [Float]
207
+ #
208
+ attr_reader :initial_reconnect_delay
209
+
210
+ #
211
+ # The connect timeout for network connections in seconds.
212
+ # @return [Float]
213
+ #
214
+ attr_reader :connect_timeout
215
+
216
+ #
217
+ # A store for feature flags and related data. The client uses it to store all data received
218
+ # from LaunchDarkly, and uses the last stored data when evaluating flags. Defaults to
219
+ # {InMemoryFeatureStore}; for other implementations, see {LaunchDarkly::Integrations}.
220
+ #
221
+ # For more information, see ["Persistent data stores"](https://docs.launchdarkly.com/sdk/concepts/data-stores).
222
+ #
223
+ # @return [LaunchDarkly::Interfaces::FeatureStore]
224
+ #
225
+ attr_reader :feature_store
226
+
227
+ #
228
+ # True if all context attributes (other than the key) should be considered private. This means
229
+ # that the attribute values will not be sent to LaunchDarkly in analytics events and will not
230
+ # appear on the LaunchDarkly dashboard.
231
+ # @return [Boolean]
232
+ # @see #private_attributes
233
+ #
234
+ attr_reader :all_attributes_private
235
+
236
+ #
237
+ # A list of context attribute names that should always be considered private. This means that the
238
+ # attribute values will not be sent to LaunchDarkly in analytics events and will not appear on
239
+ # the LaunchDarkly dashboard.
240
+ #
241
+ # You can also specify the same behavior for an individual flag evaluation
242
+ # by providing the context object with a list of private attributes.
243
+ #
244
+ # @see https://docs.launchdarkly.com/sdk/features/user-context-config#using-private-attributes
245
+ #
246
+ # @return [Array<String>]
247
+ # @see #all_attributes_private
248
+ #
249
+ attr_reader :private_attributes
250
+
251
+ #
252
+ # Whether to send events back to LaunchDarkly. This differs from {#offline?} in that it affects
253
+ # only the sending of client-side events, not streaming or polling for events from the server.
254
+ # @return [Boolean]
255
+ #
256
+ attr_reader :send_events
257
+
258
+ #
259
+ # Should the event payload sent to LaunchDarkly use gzip compression. By default this is false to prevent backward
260
+ # breaking compatibility issues with older versions of the relay proxy.
261
+ #
262
+ # Customers not using the relay proxy are strongly encouraged to enable this feature to reduce egress bandwidth
263
+ # cost.
264
+ #
265
+ # @return [Boolean]
266
+ #
267
+ attr_reader :compress_events
268
+
269
+ #
270
+ # The number of context keys that the event processor can remember at any one time. This reduces the
271
+ # amount of duplicate context details sent in analytics events.
272
+ # @return [Integer]
273
+ # @see #context_keys_flush_interval
274
+ #
275
+ attr_reader :context_keys_capacity
276
+
277
+ #
278
+ # The interval in seconds at which the event processor will reset its set of known context keys.
279
+ # @return [Float]
280
+ # @see #context_keys_capacity
281
+ #
282
+ attr_reader :context_keys_flush_interval
283
+
284
+ #
285
+ # An object that is responsible for receiving feature flag data from LaunchDarkly. By default,
286
+ # the client uses its standard polling or streaming implementation; this is customizable for
287
+ # testing purposes.
288
+ #
289
+ # This may be set to either an object that conforms to {LaunchDarkly::Interfaces::DataSource},
290
+ # or a lambda (or Proc) that takes two parameters-- SDK key and {Config}-- and returns such an
291
+ # object.
292
+ #
293
+ # @return [LaunchDarkly::Interfaces::DataSource|lambda]
294
+ # @see LaunchDarkly::Integrations::FileData
295
+ # @see LaunchDarkly::Integrations::TestData
296
+ #
297
+ attr_reader :data_source
298
+
299
+ #
300
+ # Configuration options related to Big Segments.
301
+ #
302
+ # Big Segments are a specific type of segments. For more information, read the LaunchDarkly
303
+ # documentation: https://docs.launchdarkly.com/home/users/big-segments
304
+ #
305
+ # @return [BigSegmentsConfig]
306
+ #
307
+ attr_reader :big_segments
308
+
309
+ #
310
+ # An object that allows configuration of application metadata.
311
+ #
312
+ # Application metadata may be used in LaunchDarkly analytics or other product features, but does not affect feature flag evaluations.
313
+ #
314
+ # If you want to set non-default values for any of these fields, provide the appropriately configured hash to the {Config} object.
315
+ #
316
+ # @example Configuring application information
317
+ # opts[:application] = {
318
+ # id: "MY APPLICATION ID",
319
+ # version: "MY APPLICATION VERSION"
320
+ # }
321
+ # config = LDConfig.new(opts)
322
+ #
323
+ # @return [Hash]
324
+ #
325
+ attr_reader :application
326
+
327
+ #
328
+ # LaunchDarkly Server SDKs historically downloaded all flag configuration and segments for a particular environment
329
+ # during initialization.
330
+ #
331
+ # For some customers, this is an unacceptably large amount of data, and has contributed to performance issues within
332
+ # their products.
333
+ #
334
+ # Filtered environments aim to solve this problem. By allowing customers to specify subsets of an environment's
335
+ # flags using a filter key, SDKs will initialize faster and use less memory.
336
+ #
337
+ # This payload filter key only applies to the default streaming and polling data sources. It will not affect TestData or FileData
338
+ # data sources, nor will it be applied to any data source provided through the {#data_source} config property.
339
+ #
340
+ attr_reader :payload_filter_key
341
+
342
+ #
343
+ # Set to true to opt out of sending diagnostics data.
344
+ #
345
+ # Unless `diagnostic_opt_out` is set to true, the client will send some diagnostics data to the LaunchDarkly servers
346
+ # in order to assist in the development of future SDK improvements. These diagnostics consist of an initial payload
347
+ # containing some details of the SDK in use, the SDK's configuration, and the platform the SDK is being run on, as
348
+ # well as periodic information on irregular occurrences such as dropped events.
349
+ # @return [Boolean]
350
+ #
351
+ def diagnostic_opt_out?
352
+ @diagnostic_opt_out
353
+ end
354
+
355
+ #
356
+ # The interval at which periodic diagnostic data is sent, in seconds.
357
+ #
358
+ # The default is 900 (every 15 minutes) and the minimum value is 60 (every minute).
359
+ # @return [Float]
360
+ #
361
+ attr_reader :diagnostic_recording_interval
362
+
363
+ #
364
+ # For use by wrapper libraries to set an identifying name for the wrapper being used.
365
+ #
366
+ # This will be sent in User-Agent headers during requests to the LaunchDarkly servers to allow recording
367
+ # metrics on the usage of these wrapper libraries.
368
+ # @return [String]
369
+ #
370
+ attr_reader :wrapper_name
371
+
372
+ #
373
+ # For use by wrapper libraries to report the version of the library in use.
374
+ #
375
+ # If `wrapper_name` is not set, this field will be ignored. Otherwise the version string will be included in
376
+ # the User-Agent headers along with the `wrapper_name` during requests to the LaunchDarkly servers.
377
+ # @return [String]
378
+ #
379
+ attr_reader :wrapper_version
380
+
381
+ #
382
+ # The factory used to construct sockets for HTTP operations. The factory must
383
+ # provide the method `open(uri, timeout)`. The `open` method must return a
384
+ # connected stream that implements the `IO` class, such as a `TCPSocket`.
385
+ #
386
+ # Defaults to nil.
387
+ # @return [#open]
388
+ #
389
+ attr_reader :socket_factory
390
+
391
+ #
392
+ # Initial set of hooks for the client.
393
+ #
394
+ # Hooks provide entrypoints which allow for observation of SDK functions.
395
+ #
396
+ # LaunchDarkly provides integration packages, and most applications will not
397
+ # need to implement their own hooks. Refer to the `launchdarkly-server-sdk-otel` gem
398
+ # for instrumentation.
399
+ #
400
+ attr_reader :hooks
401
+
402
+ #
403
+ # Sets whether anonymous contexts should be omitted from index and identify events.
404
+ #
405
+ # The default value is false. Anonymous contexts will be included in index and identify events.
406
+ # @return [Boolean]
407
+ #
408
+ attr_reader :omit_anonymous_contexts
409
+
410
+
411
+ #
412
+ # The default LaunchDarkly client configuration. This configuration sets
413
+ # reasonable defaults for most users.
414
+ # @return [Config] The default LaunchDarkly configuration.
415
+ #
416
+ def self.default
417
+ Config.new
418
+ end
419
+
420
+ #
421
+ # The default value for {#capacity}.
422
+ # @return [Integer] 10000
423
+ #
424
+ def self.default_capacity
425
+ 10000
426
+ end
427
+
428
+ #
429
+ # The default value for {#base_uri}.
430
+ # @return [String] "https://sdk.launchdarkly.com"
431
+ #
432
+ def self.default_base_uri
433
+ "https://sdk.launchdarkly.com"
434
+ end
435
+
436
+ #
437
+ # The default value for {#stream_uri}.
438
+ # @return [String] "https://stream.launchdarkly.com"
439
+ #
440
+ def self.default_stream_uri
441
+ "https://stream.launchdarkly.com"
442
+ end
443
+
444
+ #
445
+ # The default value for {#events_uri}.
446
+ # @return [String] "https://events.launchdarkly.com"
447
+ #
448
+ def self.default_events_uri
449
+ "https://events.launchdarkly.com"
450
+ end
451
+
452
+ #
453
+ # The default value for {#cache_store}.
454
+ # @return [Object] the Rails cache if in Rails, or a simple in-memory implementation otherwise
455
+ #
456
+ def self.default_cache_store
457
+ defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new
458
+ end
459
+
460
+ #
461
+ # The default value for {#flush_interval}.
462
+ # @return [Float] 10
463
+ #
464
+ def self.default_flush_interval
465
+ 10
466
+ end
467
+
468
+ #
469
+ # The default value for {#read_timeout}.
470
+ # @return [Float] 10
471
+ #
472
+ def self.default_read_timeout
473
+ 10
474
+ end
475
+
476
+ #
477
+ # The default value for {#initial_reconnect_delay}.
478
+ # @return [Float] 1
479
+ #
480
+ def self.default_initial_reconnect_delay
481
+ 1
482
+ end
483
+
484
+ #
485
+ # The default value for {#connect_timeout}.
486
+ # @return [Float] 2
487
+ #
488
+ def self.default_connect_timeout
489
+ 2
490
+ end
491
+
492
+ #
493
+ # The default value for {#logger}.
494
+ # @return [Logger] the Rails logger if in Rails, or a default Logger at WARN level otherwise
495
+ #
496
+ def self.default_logger
497
+ if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
498
+ Rails.logger
499
+ else
500
+ log = ::Logger.new($stdout)
501
+ log.level = ::Logger::WARN
502
+ log
503
+ end
504
+ end
505
+
506
+ #
507
+ # The default value for {#stream?}.
508
+ # @return [Boolean] true
509
+ #
510
+ def self.default_stream
511
+ true
512
+ end
513
+
514
+ #
515
+ # The default value for {#use_ldd?}.
516
+ # @return [Boolean] false
517
+ #
518
+ def self.default_use_ldd
519
+ false
520
+ end
521
+
522
+ #
523
+ # The default value for {#feature_store}.
524
+ # @return [LaunchDarkly::Interfaces::FeatureStore] an {InMemoryFeatureStore}
525
+ #
526
+ def self.default_feature_store
527
+ InMemoryFeatureStore.new
528
+ end
529
+
530
+ #
531
+ # The default value for {#offline?}.
532
+ # @return [Boolean] false
533
+ #
534
+ def self.default_offline
535
+ false
536
+ end
537
+
538
+ #
539
+ # The default value for {#poll_interval}.
540
+ # @return [Float] 30
541
+ #
542
+ def self.default_poll_interval
543
+ 30
544
+ end
545
+
546
+ #
547
+ # The default value for {#send_events}.
548
+ # @return [Boolean] true
549
+ #
550
+ def self.default_send_events
551
+ true
552
+ end
553
+
554
+ #
555
+ # The default value for {#compress_events}.
556
+ # @return [Boolean] false
557
+ #
558
+ def self.default_compress_events
559
+ false
560
+ end
561
+
562
+ #
563
+ # The default value for {#context_keys_capacity}.
564
+ # @return [Integer] 1000
565
+ #
566
+ def self.default_context_keys_capacity
567
+ 1000
568
+ end
569
+
570
+ #
571
+ # The default value for {#context_keys_flush_interval}.
572
+ # @return [Float] 300
573
+ #
574
+ def self.default_context_keys_flush_interval
575
+ 300
576
+ end
577
+
578
+ #
579
+ # The default value for {#diagnostic_recording_interval}.
580
+ # @return [Float] 900
581
+ #
582
+ def self.default_diagnostic_recording_interval
583
+ 900
584
+ end
585
+
586
+ #
587
+ # The minimum value for {#diagnostic_recording_interval}.
588
+ # @return [Float] 60
589
+ #
590
+ def self.minimum_diagnostic_recording_interval
591
+ 60
592
+ end
593
+ end
594
+
595
+ #
596
+ # Configuration options related to Big Segments.
597
+ #
598
+ # Big Segments are a specific type of segments. For more information, read the LaunchDarkly
599
+ # documentation: https://docs.launchdarkly.com/home/users/big-segments
600
+ #
601
+ # If your application uses Big Segments, you will need to create a `BigSegmentsConfig` that at a
602
+ # minimum specifies what database integration to use, and then pass the `BigSegmentsConfig`
603
+ # object as the `big_segments` parameter when creating a {Config}.
604
+ #
605
+ # @example Configuring Big Segments with Redis
606
+ # store = LaunchDarkly::Integrations::Redis::new_big_segments_store(redis_url: "redis://my-server")
607
+ # config = LaunchDarkly::Config.new(big_segments:
608
+ # LaunchDarkly::BigSegmentsConfig.new(store: store))
609
+ # client = LaunchDarkly::LDClient.new(my_sdk_key, config)
610
+ #
611
+ class BigSegmentsConfig
612
+ DEFAULT_CONTEXT_CACHE_SIZE = 1000
613
+ DEFAULT_CONTEXT_CACHE_TIME = 5
614
+ DEFAULT_STATUS_POLL_INTERVAL = 5
615
+ DEFAULT_STALE_AFTER = 2 * 60
616
+
617
+ #
618
+ # Constructor for setting Big Segments options.
619
+ #
620
+ # @param store [LaunchDarkly::Interfaces::BigSegmentStore] the data store implementation
621
+ # @param context_cache_size [Integer] See {#context_cache_size}.
622
+ # @param context_cache_time [Float] See {#context_cache_time}.
623
+ # @param status_poll_interval [Float] See {#status_poll_interval}.
624
+ # @param stale_after [Float] See {#stale_after}.
625
+ #
626
+ def initialize(store:, context_cache_size: nil, context_cache_time: nil, status_poll_interval: nil, stale_after: nil)
627
+ @store = store
628
+ @context_cache_size = context_cache_size.nil? ? DEFAULT_CONTEXT_CACHE_SIZE : context_cache_size
629
+ @context_cache_time = context_cache_time.nil? ? DEFAULT_CONTEXT_CACHE_TIME : context_cache_time
630
+ @status_poll_interval = status_poll_interval.nil? ? DEFAULT_STATUS_POLL_INTERVAL : status_poll_interval
631
+ @stale_after = stale_after.nil? ? DEFAULT_STALE_AFTER : stale_after
632
+ end
633
+
634
+ # The implementation of {LaunchDarkly::Interfaces::BigSegmentStore} that will be used to
635
+ # query the Big Segments database.
636
+ # @return [LaunchDarkly::Interfaces::BigSegmentStore]
637
+ attr_reader :store
638
+
639
+ # The maximum number of contexts whose Big Segment state will be cached by the SDK at any given time.
640
+ # @return [Integer]
641
+ attr_reader :context_cache_size
642
+
643
+ # The maximum length of time (in seconds) that the Big Segment state for a context will be cached
644
+ # by the SDK.
645
+ # @return [Float]
646
+ attr_reader :context_cache_time
647
+
648
+ # The interval (in seconds) at which the SDK will poll the Big Segment store to make sure it is
649
+ # available and to determine how long ago it was updated.
650
+ # @return [Float]
651
+ attr_reader :status_poll_interval
652
+
653
+ # The maximum length of time between updates of the Big Segments data before the data is
654
+ # considered out of date.
655
+ # @return [Float]
656
+ attr_reader :stale_after
657
+ end
658
+ end