launchdarkly-server-sdk 6.4.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ldclient-rb/config.rb +102 -56
  3. data/lib/ldclient-rb/context.rb +487 -0
  4. data/lib/ldclient-rb/evaluation_detail.rb +20 -20
  5. data/lib/ldclient-rb/events.rb +77 -132
  6. data/lib/ldclient-rb/flags_state.rb +4 -4
  7. data/lib/ldclient-rb/impl/big_segments.rb +17 -17
  8. data/lib/ldclient-rb/impl/context.rb +96 -0
  9. data/lib/ldclient-rb/impl/context_filter.rb +145 -0
  10. data/lib/ldclient-rb/impl/diagnostic_events.rb +9 -10
  11. data/lib/ldclient-rb/impl/evaluator.rb +379 -131
  12. data/lib/ldclient-rb/impl/evaluator_bucketing.rb +40 -41
  13. data/lib/ldclient-rb/impl/evaluator_helpers.rb +28 -31
  14. data/lib/ldclient-rb/impl/evaluator_operators.rb +26 -55
  15. data/lib/ldclient-rb/impl/event_sender.rb +6 -6
  16. data/lib/ldclient-rb/impl/event_summarizer.rb +12 -7
  17. data/lib/ldclient-rb/impl/event_types.rb +18 -30
  18. data/lib/ldclient-rb/impl/integrations/consul_impl.rb +7 -7
  19. data/lib/ldclient-rb/impl/integrations/dynamodb_impl.rb +29 -29
  20. data/lib/ldclient-rb/impl/integrations/file_data_source.rb +8 -8
  21. data/lib/ldclient-rb/impl/integrations/redis_impl.rb +92 -12
  22. data/lib/ldclient-rb/impl/model/clause.rb +39 -0
  23. data/lib/ldclient-rb/impl/model/feature_flag.rb +213 -0
  24. data/lib/ldclient-rb/impl/model/preprocessed_data.rb +8 -121
  25. data/lib/ldclient-rb/impl/model/segment.rb +126 -0
  26. data/lib/ldclient-rb/impl/model/serialization.rb +52 -12
  27. data/lib/ldclient-rb/impl/repeating_task.rb +1 -1
  28. data/lib/ldclient-rb/impl/store_data_set_sorter.rb +2 -2
  29. data/lib/ldclient-rb/impl/unbounded_pool.rb +1 -1
  30. data/lib/ldclient-rb/impl/util.rb +2 -2
  31. data/lib/ldclient-rb/in_memory_store.rb +2 -2
  32. data/lib/ldclient-rb/integrations/consul.rb +1 -1
  33. data/lib/ldclient-rb/integrations/dynamodb.rb +1 -1
  34. data/lib/ldclient-rb/integrations/file_data.rb +3 -3
  35. data/lib/ldclient-rb/integrations/redis.rb +4 -4
  36. data/lib/ldclient-rb/integrations/test_data/flag_builder.rb +218 -62
  37. data/lib/ldclient-rb/integrations/test_data.rb +16 -12
  38. data/lib/ldclient-rb/integrations/util/store_wrapper.rb +9 -9
  39. data/lib/ldclient-rb/interfaces.rb +14 -14
  40. data/lib/ldclient-rb/ldclient.rb +94 -144
  41. data/lib/ldclient-rb/memoized_value.rb +1 -1
  42. data/lib/ldclient-rb/non_blocking_thread_pool.rb +1 -1
  43. data/lib/ldclient-rb/polling.rb +2 -2
  44. data/lib/ldclient-rb/reference.rb +274 -0
  45. data/lib/ldclient-rb/requestor.rb +5 -5
  46. data/lib/ldclient-rb/stream.rb +7 -8
  47. data/lib/ldclient-rb/util.rb +4 -19
  48. data/lib/ldclient-rb/version.rb +1 -1
  49. data/lib/ldclient-rb.rb +2 -3
  50. metadata +34 -17
  51. data/lib/ldclient-rb/file_data_source.rb +0 -23
  52. data/lib/ldclient-rb/newrelic.rb +0 -17
  53. data/lib/ldclient-rb/redis_store.rb +0 -88
  54. data/lib/ldclient-rb/user_filter.rb +0 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 147fe8142bffa0d8e754e86669f524f6d787930e8bc6b8a14d30429933a036e3
4
- data.tar.gz: e4a404cb7bc911f7c156c3fe5059ee9a4a9d7ebfeacba4c52f44ceb116276835
3
+ metadata.gz: e189d76d654dbf73dc95e9cea758b81bc0df93d9012ebb6560d0994e6dff227c
4
+ data.tar.gz: fc8bdc8b9affee0e51ef233c217cfa4a3c7fbdbceb4694c38c5a2e90155205ed
5
5
  SHA512:
6
- metadata.gz: '039348a1a0c9284e79e641b69f11bdc4e8ba57c4cad3320eea6f8bb8caf8fc0f52a02c427a2b4f26584945e5750b7728706855cfaf6bdc22a1863b55bcf934a6'
7
- data.tar.gz: 452c574e6ff6323a74dfdcf6a5c936ff38bfaa0efc3b58ff190068322ea82e25b15dc20868eb22bf93361d3daa699bd51fa362e97f30f4fc6bcf402f9f5597d9
6
+ metadata.gz: 7fb89d48c3185f7019cd170f36f571b1ca2f7de130c624d6301fbfd30d46a0ae7a986494393ab290fa23b66511ce676b660533e1ad23d3a9e01fb037e20db6c4
7
+ data.tar.gz: 7e706747d2fcd1ab299a76eca7bf26908dbe97972b8c1ea74cfae6bc6aaffe866ddfc157b26675eb44fb22044c74efff88e7c5c4bf8dc0e75fa93dfe0ddbea8a
@@ -13,6 +13,18 @@ module LaunchDarkly
13
13
  #
14
14
  # Constructor for creating custom LaunchDarkly configurations.
15
15
  #
16
+ # `user_keys_capacity` and `user_keys_flush_interval` are deprecated
17
+ # configuration options. They exist to maintain backwards compatibility
18
+ # with previous configurations. Newer code should prefer their replacement
19
+ # options -- `context_keys_capacity` and `context_keys_flush_interval`.
20
+ #
21
+ # In the event both the user and context variations are provided, the
22
+ # context specific configuration option will take precedence.
23
+ #
24
+ # Similarly, `private_attribute_names` is deprecated. Newer code should
25
+ # prefer `private_attributes`. If both are provided, `private_attributes`
26
+ # will take precedence.
27
+ #
16
28
  # @param opts [Hash] the configuration options
17
29
  # @option opts [Logger] :logger See {#logger}.
18
30
  # @option opts [String] :base_uri ("https://sdk.launchdarkly.com") See {#base_uri}.
@@ -31,13 +43,13 @@ module LaunchDarkly
31
43
  # @option opts [Boolean] :stream (true) See {#stream?}.
32
44
  # @option opts [Boolean] all_attributes_private (false) See {#all_attributes_private}.
33
45
  # @option opts [Array] :private_attribute_names See {#private_attribute_names}.
46
+ # @option opts [Array] :private_attributes See {#private_attributes}.
34
47
  # @option opts [Boolean] :send_events (true) See {#send_events}.
35
48
  # @option opts [Integer] :user_keys_capacity (1000) See {#user_keys_capacity}.
49
+ # @option opts [Integer] :context_keys_capacity (1000) See {#context_keys_capacity}.
36
50
  # @option opts [Float] :user_keys_flush_interval (300) See {#user_keys_flush_interval}.
37
- # @option opts [Boolean] :inline_users_in_events (false) See {#inline_users_in_events}.
51
+ # @option opts [Float] :context_keys_flush_interval (300) See {#context_keys_flush_interval}.
38
52
  # @option opts [Object] :data_source See {#data_source}.
39
- # @option opts [Object] :update_processor Obsolete synonym for `data_source`.
40
- # @option opts [Object] :update_processor_factory Obsolete synonym for `data_source`.
41
53
  # @option opts [Boolean] :diagnostic_opt_out (false) See {#diagnostic_opt_out?}.
42
54
  # @option opts [Float] :diagnostic_recording_interval (900) See {#diagnostic_recording_interval}.
43
55
  # @option opts [String] :wrapper_name See {#wrapper_name}.
@@ -63,14 +75,11 @@ module LaunchDarkly
63
75
  @offline = opts.has_key?(:offline) ? opts[:offline] : Config.default_offline
64
76
  @poll_interval = opts.has_key?(:poll_interval) && opts[:poll_interval] > Config.default_poll_interval ? opts[:poll_interval] : Config.default_poll_interval
65
77
  @all_attributes_private = opts[:all_attributes_private] || false
66
- @private_attribute_names = opts[:private_attribute_names] || []
78
+ @private_attributes = opts[:private_attributes] || opts[:private_attribute_names] || []
67
79
  @send_events = opts.has_key?(:send_events) ? opts[:send_events] : Config.default_send_events
68
- @user_keys_capacity = opts[:user_keys_capacity] || Config.default_user_keys_capacity
69
- @user_keys_flush_interval = opts[:user_keys_flush_interval] || Config.default_user_keys_flush_interval
70
- @inline_users_in_events = opts[:inline_users_in_events] || false
71
- @data_source = opts[:data_source] || opts[:update_processor] || opts[:update_processor_factory]
72
- @update_processor = opts[:update_processor]
73
- @update_processor_factory = opts[:update_processor_factory]
80
+ @context_keys_capacity = opts[:context_keys_capacity] || opts[:user_keys_capacity] || Config.default_context_keys_capacity
81
+ @context_keys_flush_interval = opts[:context_keys_flush_interval] || opts[:user_keys_flush_interval] || Config.default_user_keys_flush_interval
82
+ @data_source = opts[:data_source]
74
83
  @diagnostic_opt_out = opts.has_key?(:diagnostic_opt_out) && opts[:diagnostic_opt_out]
75
84
  @diagnostic_recording_interval = opts.has_key?(:diagnostic_recording_interval) && opts[:diagnostic_recording_interval] > Config.minimum_diagnostic_recording_interval ?
76
85
  opts[:diagnostic_recording_interval] : Config.default_diagnostic_recording_interval
@@ -126,7 +135,7 @@ module LaunchDarkly
126
135
  def use_ldd?
127
136
  @use_ldd
128
137
  end
129
-
138
+
130
139
  #
131
140
  # Whether the client should be initialized in offline mode. In offline mode, default values are
132
141
  # returned for all flags and no remote network requests are made.
@@ -209,28 +218,37 @@ module LaunchDarkly
209
218
  attr_reader :feature_store
210
219
 
211
220
  #
212
- # True if all user attributes (other than the key) should be considered private. This means
221
+ # True if all context attributes (other than the key) should be considered private. This means
213
222
  # that the attribute values will not be sent to LaunchDarkly in analytics events and will not
214
223
  # appear on the LaunchDarkly dashboard.
215
224
  # @return [Boolean]
216
- # @see #private_attribute_names
225
+ # @see #private_attributes
217
226
  #
218
227
  attr_reader :all_attributes_private
219
228
 
220
229
  #
221
- # A list of user attribute names that should always be considered private. This means that the
230
+ # A list of context attribute names that should always be considered private. This means that the
222
231
  # attribute values will not be sent to LaunchDarkly in analytics events and will not appear on
223
232
  # the LaunchDarkly dashboard.
224
233
  #
225
- # You can also specify the same behavior for an individual flag evaluation by storing an array
226
- # of attribute names in the `:privateAttributeNames` property (note camelcase name) of the
227
- # user object.
234
+ # You can also specify the same behavior for an individual flag evaluation
235
+ # by providing the context object with a list of private attributes.
236
+ #
237
+ # @see https://docs.launchdarkly.com/sdk/features/user-context-config#using-private-attributes
228
238
  #
229
239
  # @return [Array<String>]
230
240
  # @see #all_attributes_private
231
241
  #
232
- attr_reader :private_attribute_names
233
-
242
+ attr_reader :private_attributes
243
+
244
+ #
245
+ # @deprecated Backwards compatibility alias for #private_attributes.
246
+ #
247
+ # @return [Integer]
248
+ # @see #private_attributes
249
+ #
250
+ alias :private_attribute_names :private_attributes
251
+
234
252
  #
235
253
  # Whether to send events back to LaunchDarkly. This differs from {#offline?} in that it affects
236
254
  # only the sending of client-side events, not streaming or polling for events from the server.
@@ -239,27 +257,35 @@ module LaunchDarkly
239
257
  attr_reader :send_events
240
258
 
241
259
  #
242
- # The number of user keys that the event processor can remember at any one time. This reduces the
243
- # amount of duplicate user details sent in analytics events.
260
+ # The number of context keys that the event processor can remember at any one time. This reduces the
261
+ # amount of duplicate context details sent in analytics events.
262
+ # @return [Integer]
263
+ # @see #context_keys_flush_interval
264
+ #
265
+ attr_reader :context_keys_capacity
266
+
267
+ #
268
+ # @deprecated Backwards compatibility alias for #context_keys_capacity.
269
+ #
244
270
  # @return [Integer]
245
- # @see #user_keys_flush_interval
271
+ # @see #context_keys_flush_interval
246
272
  #
247
- attr_reader :user_keys_capacity
273
+ alias :user_keys_capacity :context_keys_capacity
248
274
 
249
275
  #
250
- # The interval in seconds at which the event processor will reset its set of known user keys.
276
+ # The interval in seconds at which the event processor will reset its set of known context keys.
251
277
  # @return [Float]
252
- # @see #user_keys_capacity
278
+ # @see #context_keys_capacity
253
279
  #
254
- attr_reader :user_keys_flush_interval
280
+ attr_reader :context_keys_flush_interval
255
281
 
256
282
  #
257
- # Whether to include full user details in every analytics event. By default, events will only
258
- # include the user key, except for one "index" event that provides the full details for the user.
259
- # The only reason to change this is if you are using the Analytics Data Stream.
260
- # @return [Boolean]
283
+ # @deprecated Backwards compatibility alias for #context_keys_flush_interval.
261
284
  #
262
- attr_reader :inline_users_in_events
285
+ # @return [Integer]
286
+ # @see #context_keys_flush_interval
287
+ #
288
+ alias :user_keys_flush_interval :context_keys_flush_interval
263
289
 
264
290
  #
265
291
  # An object that is responsible for receiving feature flag data from LaunchDarkly. By default,
@@ -279,7 +305,7 @@ module LaunchDarkly
279
305
  #
280
306
  # Configuration options related to Big Segments.
281
307
  #
282
- # Big Segments are a specific type of user segments. For more information, read the LaunchDarkly
308
+ # Big Segments are a specific type of segments. For more information, read the LaunchDarkly
283
309
  # documentation: https://docs.launchdarkly.com/home/users/big-segments
284
310
  #
285
311
  # @return [BigSegmentsConfig]
@@ -304,12 +330,6 @@ module LaunchDarkly
304
330
  #
305
331
  attr_reader :application
306
332
 
307
- # @deprecated This is replaced by {#data_source}.
308
- attr_reader :update_processor
309
-
310
- # @deprecated This is replaced by {#data_source}.
311
- attr_reader :update_processor_factory
312
-
313
333
  #
314
334
  # Set to true to opt out of sending diagnostics data.
315
335
  #
@@ -446,8 +466,8 @@ module LaunchDarkly
446
466
  #
447
467
  def self.default_logger
448
468
  if defined?(Rails) && Rails.respond_to?(:logger)
449
- Rails.logger
450
- else
469
+ Rails.logger
470
+ else
451
471
  log = ::Logger.new($stdout)
452
472
  log.level = ::Logger::WARN
453
473
  log
@@ -503,21 +523,33 @@ module LaunchDarkly
503
523
  end
504
524
 
505
525
  #
506
- # The default value for {#user_keys_capacity}.
526
+ # The default value for {#context_keys_capacity}.
507
527
  # @return [Integer] 1000
508
528
  #
509
- def self.default_user_keys_capacity
529
+ def self.default_context_keys_capacity
510
530
  1000
511
531
  end
512
532
 
513
533
  #
514
- # The default value for {#user_keys_flush_interval}.
534
+ # The default value for {#context_keys_flush_interval}.
515
535
  # @return [Float] 300
516
536
  #
517
- def self.default_user_keys_flush_interval
537
+ def self.default_context_keys_flush_interval
518
538
  300
519
539
  end
520
540
 
541
+ class << self
542
+ #
543
+ # @deprecated Backwards compatibility alias for #default_context_keys_capacity
544
+ #
545
+ alias :default_user_keys_capacity :default_context_keys_capacity
546
+
547
+ #
548
+ # @deprecated Backwards compatibility alias for #default_context_keys_flush_interval
549
+ #
550
+ alias :default_user_keys_flush_interval :default_context_keys_flush_interval
551
+ end
552
+
521
553
  #
522
554
  # The default value for {#diagnostic_recording_interval}.
523
555
  # @return [Float] 900
@@ -538,7 +570,7 @@ module LaunchDarkly
538
570
  #
539
571
  # Configuration options related to Big Segments.
540
572
  #
541
- # Big Segments are a specific type of user segments. For more information, read the LaunchDarkly
573
+ # Big Segments are a specific type of segments. For more information, read the LaunchDarkly
542
574
  # documentation: https://docs.launchdarkly.com/home/users/big-segments
543
575
  #
544
576
  # If your application uses Big Segments, you will need to create a `BigSegmentsConfig` that at a
@@ -552,8 +584,8 @@ module LaunchDarkly
552
584
  # client = LaunchDarkly::LDClient.new(my_sdk_key, config)
553
585
  #
554
586
  class BigSegmentsConfig
555
- DEFAULT_USER_CACHE_SIZE = 1000
556
- DEFAULT_USER_CACHE_TIME = 5
587
+ DEFAULT_CONTEXT_CACHE_SIZE = 1000
588
+ DEFAULT_CONTEXT_CACHE_TIME = 5
557
589
  DEFAULT_STATUS_POLL_INTERVAL = 5
558
590
  DEFAULT_STALE_AFTER = 2 * 60
559
591
 
@@ -561,15 +593,15 @@ module LaunchDarkly
561
593
  # Constructor for setting Big Segments options.
562
594
  #
563
595
  # @param store [LaunchDarkly::Interfaces::BigSegmentStore] the data store implementation
564
- # @param user_cache_size [Integer] See {#user_cache_size}.
565
- # @param user_cache_time [Float] See {#user_cache_time}.
596
+ # @param context_cache_size [Integer] See {#context_cache_size}.
597
+ # @param context_cache_time [Float] See {#context_cache_time}.
566
598
  # @param status_poll_interval [Float] See {#status_poll_interval}.
567
599
  # @param stale_after [Float] See {#stale_after}.
568
600
  #
569
- def initialize(store:, user_cache_size: nil, user_cache_time: nil, status_poll_interval: nil, stale_after: nil)
601
+ def initialize(store:, context_cache_size: nil, context_cache_time: nil, status_poll_interval: nil, stale_after: nil)
570
602
  @store = store
571
- @user_cache_size = user_cache_size.nil? ? DEFAULT_USER_CACHE_SIZE : user_cache_size
572
- @user_cache_time = user_cache_time.nil? ? DEFAULT_USER_CACHE_TIME : user_cache_time
603
+ @context_cache_size = context_cache_size.nil? ? DEFAULT_CONTEXT_CACHE_SIZE : context_cache_size
604
+ @context_cache_time = context_cache_time.nil? ? DEFAULT_CONTEXT_CACHE_TIME : context_cache_time
573
605
  @status_poll_interval = status_poll_interval.nil? ? DEFAULT_STATUS_POLL_INTERVAL : status_poll_interval
574
606
  @stale_after = stale_after.nil? ? DEFAULT_STALE_AFTER : stale_after
575
607
  end
@@ -579,14 +611,28 @@ module LaunchDarkly
579
611
  # @return [LaunchDarkly::Interfaces::BigSegmentStore]
580
612
  attr_reader :store
581
613
 
582
- # The maximum number of users whose Big Segment state will be cached by the SDK at any given time.
614
+ # The maximum number of contexts whose Big Segment state will be cached by the SDK at any given time.
615
+ # @return [Integer]
616
+ attr_reader :context_cache_size
617
+
618
+ #
619
+ # @deprecated Backwards compatibility alias for #context_cache_size
620
+ #
583
621
  # @return [Integer]
584
- attr_reader :user_cache_size
622
+ #
623
+ alias :user_cache_size :context_cache_size
585
624
 
586
- # The maximum length of time (in seconds) that the Big Segment state for a user will be cached
625
+ # The maximum length of time (in seconds) that the Big Segment state for a context will be cached
587
626
  # by the SDK.
588
627
  # @return [Float]
589
- attr_reader :user_cache_time
628
+ attr_reader :context_cache_time
629
+
630
+ #
631
+ # @deprecated Backwards compatibility alias for #context_cache_time
632
+ #
633
+ # @return [Float]
634
+ #
635
+ alias :user_cache_time :context_cache_time
590
636
 
591
637
  # The interval (in seconds) at which the SDK will poll the Big Segment store to make sure it is
592
638
  # available and to determine how long ago it was updated.