launchdarkly-server-sdk 6.3.4 → 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 +121 -55
  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 +378 -139
  12. data/lib/ldclient-rb/impl/evaluator_bucketing.rb +40 -41
  13. data/lib/ldclient-rb/impl/evaluator_helpers.rb +50 -0
  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 +64 -0
  25. data/lib/ldclient-rb/impl/model/segment.rb +126 -0
  26. data/lib/ldclient-rb/impl/model/serialization.rb +54 -44
  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 +59 -1
  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 +7 -7
  46. data/lib/ldclient-rb/stream.rb +8 -9
  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 +36 -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: 50934709e1ee8c075c56c149f75753f87498eb9e1f06e39597d2cd4514ea7196
4
- data.tar.gz: e7f153366b7b50c3951f844bf9ce1a0b81093fc733818dbb02e8f0a888d9ac26
3
+ metadata.gz: e189d76d654dbf73dc95e9cea758b81bc0df93d9012ebb6560d0994e6dff227c
4
+ data.tar.gz: fc8bdc8b9affee0e51ef233c217cfa4a3c7fbdbceb4694c38c5a2e90155205ed
5
5
  SHA512:
6
- metadata.gz: 2469e536ca482489eb46f3ff650aeb573eb691ab6c6c2b8ed669b7f8ba799bf65d68d40f6cabc51ec4b051dd56e309430f94e5dc4fbbd70193efa5156d1d1082
7
- data.tar.gz: 454219746c7b296fd8c92ee5e266f96765f72527706b7d6f7360445eb1d245e2acb37e4cb722ed48bf73dce8e307d2121771270ea9bedb71e91d67f9a79b8ea0
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,19 +43,20 @@ 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}.
44
56
  # @option opts [String] :wrapper_version See {#wrapper_version}.
45
57
  # @option opts [#open] :socket_factory See {#socket_factory}.
46
58
  # @option opts [BigSegmentsConfig] :big_segments See {#big_segments}.
59
+ # @option opts [Hash] :application See {#application}
47
60
  #
48
61
  def initialize(opts = {})
49
62
  @base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
@@ -62,14 +75,11 @@ module LaunchDarkly
62
75
  @offline = opts.has_key?(:offline) ? opts[:offline] : Config.default_offline
63
76
  @poll_interval = opts.has_key?(:poll_interval) && opts[:poll_interval] > Config.default_poll_interval ? opts[:poll_interval] : Config.default_poll_interval
64
77
  @all_attributes_private = opts[:all_attributes_private] || false
65
- @private_attribute_names = opts[:private_attribute_names] || []
78
+ @private_attributes = opts[:private_attributes] || opts[:private_attribute_names] || []
66
79
  @send_events = opts.has_key?(:send_events) ? opts[:send_events] : Config.default_send_events
67
- @user_keys_capacity = opts[:user_keys_capacity] || Config.default_user_keys_capacity
68
- @user_keys_flush_interval = opts[:user_keys_flush_interval] || Config.default_user_keys_flush_interval
69
- @inline_users_in_events = opts[:inline_users_in_events] || false
70
- @data_source = opts[:data_source] || opts[:update_processor] || opts[:update_processor_factory]
71
- @update_processor = opts[:update_processor]
72
- @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]
73
83
  @diagnostic_opt_out = opts.has_key?(:diagnostic_opt_out) && opts[:diagnostic_opt_out]
74
84
  @diagnostic_recording_interval = opts.has_key?(:diagnostic_recording_interval) && opts[:diagnostic_recording_interval] > Config.minimum_diagnostic_recording_interval ?
75
85
  opts[:diagnostic_recording_interval] : Config.default_diagnostic_recording_interval
@@ -77,6 +87,7 @@ module LaunchDarkly
77
87
  @wrapper_version = opts[:wrapper_version]
78
88
  @socket_factory = opts[:socket_factory]
79
89
  @big_segments = opts[:big_segments] || BigSegmentsConfig.new(store: nil)
90
+ @application = LaunchDarkly::Impl::Util.validate_application_info(opts[:application] || {}, @logger)
80
91
  end
81
92
 
82
93
  #
@@ -124,7 +135,7 @@ module LaunchDarkly
124
135
  def use_ldd?
125
136
  @use_ldd
126
137
  end
127
-
138
+
128
139
  #
129
140
  # Whether the client should be initialized in offline mode. In offline mode, default values are
130
141
  # returned for all flags and no remote network requests are made.
@@ -207,28 +218,37 @@ module LaunchDarkly
207
218
  attr_reader :feature_store
208
219
 
209
220
  #
210
- # 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
211
222
  # that the attribute values will not be sent to LaunchDarkly in analytics events and will not
212
223
  # appear on the LaunchDarkly dashboard.
213
224
  # @return [Boolean]
214
- # @see #private_attribute_names
225
+ # @see #private_attributes
215
226
  #
216
227
  attr_reader :all_attributes_private
217
228
 
218
229
  #
219
- # 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
220
231
  # attribute values will not be sent to LaunchDarkly in analytics events and will not appear on
221
232
  # the LaunchDarkly dashboard.
222
233
  #
223
- # You can also specify the same behavior for an individual flag evaluation by storing an array
224
- # of attribute names in the `:privateAttributeNames` property (note camelcase name) of the
225
- # 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
226
238
  #
227
239
  # @return [Array<String>]
228
240
  # @see #all_attributes_private
229
241
  #
230
- attr_reader :private_attribute_names
231
-
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
+
232
252
  #
233
253
  # Whether to send events back to LaunchDarkly. This differs from {#offline?} in that it affects
234
254
  # only the sending of client-side events, not streaming or polling for events from the server.
@@ -237,27 +257,35 @@ module LaunchDarkly
237
257
  attr_reader :send_events
238
258
 
239
259
  #
240
- # The number of user keys that the event processor can remember at any one time. This reduces the
241
- # 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.
242
262
  # @return [Integer]
243
- # @see #user_keys_flush_interval
263
+ # @see #context_keys_flush_interval
244
264
  #
245
- attr_reader :user_keys_capacity
265
+ attr_reader :context_keys_capacity
246
266
 
247
267
  #
248
- # The interval in seconds at which the event processor will reset its set of known user keys.
268
+ # @deprecated Backwards compatibility alias for #context_keys_capacity.
269
+ #
270
+ # @return [Integer]
271
+ # @see #context_keys_flush_interval
272
+ #
273
+ alias :user_keys_capacity :context_keys_capacity
274
+
275
+ #
276
+ # The interval in seconds at which the event processor will reset its set of known context keys.
249
277
  # @return [Float]
250
- # @see #user_keys_capacity
278
+ # @see #context_keys_capacity
251
279
  #
252
- attr_reader :user_keys_flush_interval
280
+ attr_reader :context_keys_flush_interval
253
281
 
254
282
  #
255
- # Whether to include full user details in every analytics event. By default, events will only
256
- # include the user key, except for one "index" event that provides the full details for the user.
257
- # The only reason to change this is if you are using the Analytics Data Stream.
258
- # @return [Boolean]
283
+ # @deprecated Backwards compatibility alias for #context_keys_flush_interval.
284
+ #
285
+ # @return [Integer]
286
+ # @see #context_keys_flush_interval
259
287
  #
260
- attr_reader :inline_users_in_events
288
+ alias :user_keys_flush_interval :context_keys_flush_interval
261
289
 
262
290
  #
263
291
  # An object that is responsible for receiving feature flag data from LaunchDarkly. By default,
@@ -277,18 +305,30 @@ module LaunchDarkly
277
305
  #
278
306
  # Configuration options related to Big Segments.
279
307
  #
280
- # 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
281
309
  # documentation: https://docs.launchdarkly.com/home/users/big-segments
282
310
  #
283
311
  # @return [BigSegmentsConfig]
284
312
  #
285
313
  attr_reader :big_segments
286
314
 
287
- # @deprecated This is replaced by {#data_source}.
288
- attr_reader :update_processor
289
-
290
- # @deprecated This is replaced by {#data_source}.
291
- attr_reader :update_processor_factory
315
+ #
316
+ # An object that allows configuration of application metadata.
317
+ #
318
+ # Application metadata may be used in LaunchDarkly analytics or other product features, but does not affect feature flag evaluations.
319
+ #
320
+ # If you want to set non-default values for any of these fields, provide the appropriately configured hash to the {Config} object.
321
+ #
322
+ # @example Configuring application information
323
+ # opts[:application] = {
324
+ # id: "MY APPLICATION ID",
325
+ # version: "MY APPLICATION VERSION"
326
+ # }
327
+ # config = LDConfig.new(opts)
328
+ #
329
+ # @return [Hash]
330
+ #
331
+ attr_reader :application
292
332
 
293
333
  #
294
334
  # Set to true to opt out of sending diagnostics data.
@@ -426,8 +466,8 @@ module LaunchDarkly
426
466
  #
427
467
  def self.default_logger
428
468
  if defined?(Rails) && Rails.respond_to?(:logger)
429
- Rails.logger
430
- else
469
+ Rails.logger
470
+ else
431
471
  log = ::Logger.new($stdout)
432
472
  log.level = ::Logger::WARN
433
473
  log
@@ -483,21 +523,33 @@ module LaunchDarkly
483
523
  end
484
524
 
485
525
  #
486
- # The default value for {#user_keys_capacity}.
526
+ # The default value for {#context_keys_capacity}.
487
527
  # @return [Integer] 1000
488
528
  #
489
- def self.default_user_keys_capacity
529
+ def self.default_context_keys_capacity
490
530
  1000
491
531
  end
492
532
 
493
533
  #
494
- # The default value for {#user_keys_flush_interval}.
534
+ # The default value for {#context_keys_flush_interval}.
495
535
  # @return [Float] 300
496
536
  #
497
- def self.default_user_keys_flush_interval
537
+ def self.default_context_keys_flush_interval
498
538
  300
499
539
  end
500
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
+
501
553
  #
502
554
  # The default value for {#diagnostic_recording_interval}.
503
555
  # @return [Float] 900
@@ -518,7 +570,7 @@ module LaunchDarkly
518
570
  #
519
571
  # Configuration options related to Big Segments.
520
572
  #
521
- # 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
522
574
  # documentation: https://docs.launchdarkly.com/home/users/big-segments
523
575
  #
524
576
  # If your application uses Big Segments, you will need to create a `BigSegmentsConfig` that at a
@@ -532,8 +584,8 @@ module LaunchDarkly
532
584
  # client = LaunchDarkly::LDClient.new(my_sdk_key, config)
533
585
  #
534
586
  class BigSegmentsConfig
535
- DEFAULT_USER_CACHE_SIZE = 1000
536
- DEFAULT_USER_CACHE_TIME = 5
587
+ DEFAULT_CONTEXT_CACHE_SIZE = 1000
588
+ DEFAULT_CONTEXT_CACHE_TIME = 5
537
589
  DEFAULT_STATUS_POLL_INTERVAL = 5
538
590
  DEFAULT_STALE_AFTER = 2 * 60
539
591
 
@@ -541,15 +593,15 @@ module LaunchDarkly
541
593
  # Constructor for setting Big Segments options.
542
594
  #
543
595
  # @param store [LaunchDarkly::Interfaces::BigSegmentStore] the data store implementation
544
- # @param user_cache_size [Integer] See {#user_cache_size}.
545
- # @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}.
546
598
  # @param status_poll_interval [Float] See {#status_poll_interval}.
547
599
  # @param stale_after [Float] See {#stale_after}.
548
600
  #
549
- 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)
550
602
  @store = store
551
- @user_cache_size = user_cache_size.nil? ? DEFAULT_USER_CACHE_SIZE : user_cache_size
552
- @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
553
605
  @status_poll_interval = status_poll_interval.nil? ? DEFAULT_STATUS_POLL_INTERVAL : status_poll_interval
554
606
  @stale_after = stale_after.nil? ? DEFAULT_STALE_AFTER : stale_after
555
607
  end
@@ -559,14 +611,28 @@ module LaunchDarkly
559
611
  # @return [LaunchDarkly::Interfaces::BigSegmentStore]
560
612
  attr_reader :store
561
613
 
562
- # 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.
563
615
  # @return [Integer]
564
- attr_reader :user_cache_size
616
+ attr_reader :context_cache_size
565
617
 
566
- # The maximum length of time (in seconds) that the Big Segment state for a user will be cached
618
+ #
619
+ # @deprecated Backwards compatibility alias for #context_cache_size
620
+ #
621
+ # @return [Integer]
622
+ #
623
+ alias :user_cache_size :context_cache_size
624
+
625
+ # The maximum length of time (in seconds) that the Big Segment state for a context will be cached
567
626
  # by the SDK.
568
627
  # @return [Float]
569
- 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
570
636
 
571
637
  # The interval (in seconds) at which the SDK will poll the Big Segment store to make sure it is
572
638
  # available and to determine how long ago it was updated.