launchdarkly-server-sdk 8.19.0 → 8.20.0
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.
- checksums.yaml +4 -4
- data/lib/ldclient-rb/config.rb +14 -4
- data/lib/ldclient-rb/data_system/config_builder.rb +35 -1
- data/lib/ldclient-rb/data_system.rb +4 -4
- data/lib/ldclient-rb/evaluation_detail.rb +37 -4
- data/lib/ldclient-rb/events.rb +24 -16
- data/lib/ldclient-rb/impl/data_store/store.rb +84 -6
- data/lib/ldclient-rb/impl/data_system/fdv1.rb +5 -0
- data/lib/ldclient-rb/impl/data_system/fdv2.rb +84 -0
- data/lib/ldclient-rb/impl/data_system/polling.rb +18 -0
- data/lib/ldclient-rb/impl/data_system/protocolv2.rb +18 -0
- data/lib/ldclient-rb/impl/data_system/streaming.rb +16 -4
- data/lib/ldclient-rb/impl/data_system.rb +13 -0
- data/lib/ldclient-rb/impl/dependency_tracker.rb +1 -1
- data/lib/ldclient-rb/impl/evaluator.rb +62 -18
- data/lib/ldclient-rb/impl/event_summarizer.rb +13 -2
- data/lib/ldclient-rb/impl/event_types.rb +11 -1
- data/lib/ldclient-rb/impl/file_data/document.rb +267 -0
- data/lib/ldclient-rb/impl/file_data/merge.rb +160 -0
- data/lib/ldclient-rb/impl/file_data/poller.rb +87 -0
- data/lib/ldclient-rb/impl/file_data/reloader.rb +578 -0
- data/lib/ldclient-rb/impl/file_data/watcher.rb +519 -0
- data/lib/ldclient-rb/impl/file_data.rb +7 -0
- data/lib/ldclient-rb/impl/integrations/file_override_source.rb +174 -0
- data/lib/ldclient-rb/impl/model/feature_flag.rb +34 -0
- data/lib/ldclient-rb/impl/model/segment.rb +34 -0
- data/lib/ldclient-rb/impl/overrides/layer.rb +133 -0
- data/lib/ldclient-rb/impl/overrides/overlay.rb +71 -0
- data/lib/ldclient-rb/impl/overrides/sink.rb +240 -0
- data/lib/ldclient-rb/impl/overrides.rb +5 -0
- data/lib/ldclient-rb/integrations/file_data.rb +181 -3
- data/lib/ldclient-rb/integrations/test_data/flag_builder.rb +1 -1
- data/lib/ldclient-rb/interfaces/overrides.rb +90 -0
- data/lib/ldclient-rb/interfaces.rb +1 -0
- data/lib/ldclient-rb/ldclient.rb +109 -28
- data/lib/ldclient-rb/version.rb +1 -1
- metadata +14 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e526593c9952a91cdb1fbf5aec1f88d2ab84b2cb0962ebf2b6105302f3842680
|
|
4
|
+
data.tar.gz: 159190cba1b7a029f6f441b051d40001b0b703b9a0cfec1c1d24e690432de995
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36db958ab4bd5d8c22eae2b927c5f3f67967ffe6b0ae845c604931b5d70e716e4d2e178e7b0da3e141e6198bdec5f0aeff891c6e9581fe738e40fe48c526ea15
|
|
7
|
+
data.tar.gz: c2a93c0269dfe443aa41f9d76d77c3ac216e66451ad9ac877f0654e5518dbae091df9794cf6927b324dc7efb0743c1e294316e8cc1a2b7262f25a601f9c347ca
|
data/lib/ldclient-rb/config.rb
CHANGED
|
@@ -468,9 +468,9 @@ module LaunchDarkly
|
|
|
468
468
|
attr_reader :omit_anonymous_contexts
|
|
469
469
|
|
|
470
470
|
#
|
|
471
|
-
# Configuration for the
|
|
472
|
-
#
|
|
473
|
-
#
|
|
471
|
+
# Configuration for the data system, which controls how the SDK gets
|
|
472
|
+
# flag and segment data. When set, it overrides {#feature_store},
|
|
473
|
+
# {#data_source}, {#stream?}, and {#use_ldd?}.
|
|
474
474
|
#
|
|
475
475
|
# @return [DataSystemConfig, nil]
|
|
476
476
|
#
|
|
@@ -736,14 +736,18 @@ module LaunchDarkly
|
|
|
736
736
|
# @param data_store [LaunchDarkly::Interfaces::FeatureStore, nil] The (optional) data store
|
|
737
737
|
# @param fdv1_fallback_synchronizer [#build(String, Config), nil]
|
|
738
738
|
# The (optional) builder for FDv1-compatible fallback synchronizer
|
|
739
|
+
# @param overrides [#build(String, Config), nil] The (optional) builder for an override source.
|
|
740
|
+
# Flag overrides are currently experimental and subject to change.
|
|
739
741
|
#
|
|
740
742
|
def initialize(initializers: nil, synchronizers: nil,
|
|
741
|
-
data_store_mode: LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_ONLY, data_store: nil, fdv1_fallback_synchronizer: nil
|
|
743
|
+
data_store_mode: LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_ONLY, data_store: nil, fdv1_fallback_synchronizer: nil,
|
|
744
|
+
overrides: nil)
|
|
742
745
|
@initializers = initializers
|
|
743
746
|
@synchronizers = synchronizers
|
|
744
747
|
@data_store_mode = data_store_mode
|
|
745
748
|
@data_store = data_store
|
|
746
749
|
@fdv1_fallback_synchronizer = fdv1_fallback_synchronizer
|
|
750
|
+
@overrides = overrides
|
|
747
751
|
end
|
|
748
752
|
|
|
749
753
|
# The initializer builders for the data system. Each builder responds to build(sdk_key, config) and returns an Initializer.
|
|
@@ -765,5 +769,11 @@ module LaunchDarkly
|
|
|
765
769
|
# The FDv1-compatible fallback synchronizer builder. Responds to build(sdk_key, config) and returns a Synchronizer.
|
|
766
770
|
# @return [#build(String, Config), nil]
|
|
767
771
|
attr_reader :fdv1_fallback_synchronizer
|
|
772
|
+
|
|
773
|
+
# The override source builder. Responds to build(sdk_key, config) and returns an
|
|
774
|
+
# {LaunchDarkly::Interfaces::Overrides::OverrideSource}. Flag overrides are currently
|
|
775
|
+
# experimental and subject to change.
|
|
776
|
+
# @return [#build(String, Config), nil]
|
|
777
|
+
attr_reader :overrides
|
|
768
778
|
end
|
|
769
779
|
end
|
|
@@ -23,6 +23,7 @@ module LaunchDarkly
|
|
|
23
23
|
@fdv1_fallback_synchronizer = nil
|
|
24
24
|
@data_store_mode = LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_ONLY
|
|
25
25
|
@data_store = nil
|
|
26
|
+
@overrides = nil
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
#
|
|
@@ -85,6 +86,38 @@ module LaunchDarkly
|
|
|
85
86
|
self
|
|
86
87
|
end
|
|
87
88
|
|
|
89
|
+
#
|
|
90
|
+
# Configures the SDK with an override source. Flag overrides are currently experimental and
|
|
91
|
+
# subject to change.
|
|
92
|
+
#
|
|
93
|
+
# Overrides are flag and segment definitions that take precedence over data received from
|
|
94
|
+
# LaunchDarkly at evaluation time, on a per-key basis. They exist for resilience during an
|
|
95
|
+
# incident. Overrides let an operator force one or more flags to a known state on a running
|
|
96
|
+
# client, whether or not the client can reach LaunchDarkly. Flags not present in the override
|
|
97
|
+
# data are completely unaffected.
|
|
98
|
+
#
|
|
99
|
+
# The override source is not a data source. It has no effect on the client's initialization
|
|
100
|
+
# status, data availability, or data source status. Without a configured source, or while
|
|
101
|
+
# the source supplies no overrides, the SDK behaves as it would without this feature.
|
|
102
|
+
#
|
|
103
|
+
# At most one override source can be configured. A later call replaces an earlier one.
|
|
104
|
+
#
|
|
105
|
+
# When the client is offline, the source is not built or started: no overrides are served,
|
|
106
|
+
# and a configuration error in the source is not reported. The SDK logs a warning instead.
|
|
107
|
+
#
|
|
108
|
+
# @example
|
|
109
|
+
# overrides = LaunchDarkly::Integrations::FileData.override_source(paths: ["/etc/launchdarkly/overrides.json"])
|
|
110
|
+
# config = LaunchDarkly::Config.new(data_system_config: LaunchDarkly::DataSystem.default.overrides(overrides).build)
|
|
111
|
+
#
|
|
112
|
+
# @param source [#build(String, Config), nil] a builder that responds to build(sdk_key, config)
|
|
113
|
+
# and returns a {LaunchDarkly::Interfaces::Overrides::OverrideSource}, or nil to remove one
|
|
114
|
+
# @return [ConfigBuilder] self for chaining
|
|
115
|
+
#
|
|
116
|
+
def overrides(source)
|
|
117
|
+
@overrides = source
|
|
118
|
+
self
|
|
119
|
+
end
|
|
120
|
+
|
|
88
121
|
#
|
|
89
122
|
# Builds the data system configuration.
|
|
90
123
|
#
|
|
@@ -96,7 +129,8 @@ module LaunchDarkly
|
|
|
96
129
|
synchronizers: @synchronizers,
|
|
97
130
|
data_store_mode: @data_store_mode,
|
|
98
131
|
data_store: @data_store,
|
|
99
|
-
fdv1_fallback_synchronizer: @fdv1_fallback_synchronizer
|
|
132
|
+
fdv1_fallback_synchronizer: @fdv1_fallback_synchronizer,
|
|
133
|
+
overrides: @overrides
|
|
100
134
|
)
|
|
101
135
|
end
|
|
102
136
|
end
|
|
@@ -22,17 +22,17 @@ module LaunchDarkly
|
|
|
22
22
|
#
|
|
23
23
|
# # Use the default strategy (recommended)
|
|
24
24
|
# config = LaunchDarkly::Config.new(
|
|
25
|
-
#
|
|
25
|
+
# data_system_config: LaunchDarkly::DataSystem.default.build
|
|
26
26
|
# )
|
|
27
27
|
#
|
|
28
28
|
# # Use streaming only
|
|
29
29
|
# config = LaunchDarkly::Config.new(
|
|
30
|
-
#
|
|
30
|
+
# data_system_config: LaunchDarkly::DataSystem.streaming.build
|
|
31
31
|
# )
|
|
32
32
|
#
|
|
33
33
|
# # Use polling only
|
|
34
34
|
# config = LaunchDarkly::Config.new(
|
|
35
|
-
#
|
|
35
|
+
# data_system_config: LaunchDarkly::DataSystem.polling.build
|
|
36
36
|
# )
|
|
37
37
|
#
|
|
38
38
|
# == Custom Configurations
|
|
@@ -52,7 +52,7 @@ module LaunchDarkly
|
|
|
52
52
|
# .initializers([polling])
|
|
53
53
|
# .synchronizers([streaming, polling])
|
|
54
54
|
#
|
|
55
|
-
# config = LaunchDarkly::Config.new(
|
|
55
|
+
# config = LaunchDarkly::Config.new(data_system_config: data_system.build)
|
|
56
56
|
#
|
|
57
57
|
module DataSystem
|
|
58
58
|
#
|
|
@@ -150,6 +150,15 @@ module LaunchDarkly
|
|
|
150
150
|
# @return [Symbol]
|
|
151
151
|
attr_reader :big_segments_status
|
|
152
152
|
|
|
153
|
+
# True if an override affected this evaluation, directly or transitively. It is true when the
|
|
154
|
+
# evaluated flag came from the SDK's override store. It is also true when a prerequisite flag at
|
|
155
|
+
# any depth, or a segment read during the evaluation, came from the override store. In the JSON
|
|
156
|
+
# representation, the `overrideAffected` property appears only when this is true.
|
|
157
|
+
#
|
|
158
|
+
# Flag overrides are currently experimental and subject to change.
|
|
159
|
+
# @return [Boolean]
|
|
160
|
+
attr_reader :override_affected
|
|
161
|
+
|
|
153
162
|
# Returns an instance whose {#kind} is {#OFF}.
|
|
154
163
|
# @return [EvaluationReason]
|
|
155
164
|
def self.off
|
|
@@ -216,12 +225,14 @@ module LaunchDarkly
|
|
|
216
225
|
if other.is_a? EvaluationReason
|
|
217
226
|
@kind == other.kind && @rule_index == other.rule_index && @rule_id == other.rule_id &&
|
|
218
227
|
@prerequisite_key == other.prerequisite_key && @error_kind == other.error_kind &&
|
|
219
|
-
@big_segments_status == other.big_segments_status
|
|
228
|
+
@big_segments_status == other.big_segments_status &&
|
|
229
|
+
@override_affected == other.override_affected
|
|
220
230
|
elsif other.is_a? Hash
|
|
221
231
|
@kind.to_s == other[:kind] && @rule_index == other[:ruleIndex] && @rule_id == other[:ruleId] &&
|
|
222
232
|
@prerequisite_key == other[:prerequisiteKey] &&
|
|
223
233
|
(other[:errorKind] == @error_kind.nil? ? nil : @error_kind.to_s) &&
|
|
224
|
-
(other[:bigSegmentsStatus] == @big_segments_status.nil? ? nil : @big_segments_status.to_s)
|
|
234
|
+
(other[:bigSegmentsStatus] == @big_segments_status.nil? ? nil : @big_segments_status.to_s) &&
|
|
235
|
+
!!other[:overrideAffected] == @override_affected
|
|
225
236
|
end
|
|
226
237
|
end
|
|
227
238
|
|
|
@@ -286,6 +297,8 @@ module LaunchDarkly
|
|
|
286
297
|
unless @big_segments_status.nil?
|
|
287
298
|
ret[:bigSegmentsStatus] = @big_segments_status
|
|
288
299
|
end
|
|
300
|
+
# The property is written only when true, so the wire format of an ordinary evaluation is unchanged.
|
|
301
|
+
ret[:overrideAffected] = true if @override_affected
|
|
289
302
|
ret
|
|
290
303
|
end
|
|
291
304
|
|
|
@@ -312,6 +325,8 @@ module LaunchDarkly
|
|
|
312
325
|
@error_kind.nil? ? nil : @error_kind.to_s
|
|
313
326
|
when :bigSegmentsStatus
|
|
314
327
|
@big_segments_status.nil? ? nil : @big_segments_status.to_s
|
|
328
|
+
when :overrideAffected
|
|
329
|
+
@override_affected
|
|
315
330
|
else
|
|
316
331
|
nil
|
|
317
332
|
end
|
|
@@ -319,7 +334,24 @@ module LaunchDarkly
|
|
|
319
334
|
|
|
320
335
|
def with_big_segments_status(big_segments_status)
|
|
321
336
|
return self if @big_segments_status == big_segments_status
|
|
322
|
-
EvaluationReason.new(@kind, @rule_index, @rule_id, @prerequisite_key, @error_kind, @in_experiment,
|
|
337
|
+
EvaluationReason.new(@kind, @rule_index, @rule_id, @prerequisite_key, @error_kind, @in_experiment,
|
|
338
|
+
big_segments_status, @override_affected)
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
#
|
|
342
|
+
# Returns a reason that is the same as this one apart from the {#override_affected} indicator.
|
|
343
|
+
# Returns this instance when the indicator already has the given value.
|
|
344
|
+
#
|
|
345
|
+
# Flag overrides are currently experimental and subject to change.
|
|
346
|
+
#
|
|
347
|
+
# @param override_affected [Boolean]
|
|
348
|
+
# @return [EvaluationReason]
|
|
349
|
+
#
|
|
350
|
+
def with_override_affected(override_affected)
|
|
351
|
+
override_affected = !!override_affected
|
|
352
|
+
return self if @override_affected == override_affected
|
|
353
|
+
EvaluationReason.new(@kind, @rule_index, @rule_id, @prerequisite_key, @error_kind, @in_experiment,
|
|
354
|
+
@big_segments_status, override_affected)
|
|
323
355
|
end
|
|
324
356
|
|
|
325
357
|
#
|
|
@@ -327,7 +359,7 @@ module LaunchDarkly
|
|
|
327
359
|
# but should use class methods like {#off} to avoid creating unnecessary instances.
|
|
328
360
|
#
|
|
329
361
|
def initialize(kind, rule_index, rule_id, prerequisite_key, error_kind, in_experiment=nil,
|
|
330
|
-
big_segments_status = nil)
|
|
362
|
+
big_segments_status = nil, override_affected = false)
|
|
331
363
|
@kind = kind.to_sym
|
|
332
364
|
@rule_index = rule_index
|
|
333
365
|
@rule_id = rule_id
|
|
@@ -337,6 +369,7 @@ module LaunchDarkly
|
|
|
337
369
|
@error_kind = error_kind
|
|
338
370
|
@in_experiment = in_experiment
|
|
339
371
|
@big_segments_status = big_segments_status
|
|
372
|
+
@override_affected = !!override_affected
|
|
340
373
|
end
|
|
341
374
|
|
|
342
375
|
private_class_method def self.make_error(error_kind)
|
data/lib/ldclient-rb/events.rb
CHANGED
|
@@ -44,7 +44,8 @@ module LaunchDarkly
|
|
|
44
44
|
debug_until = nil,
|
|
45
45
|
prereq_of = nil,
|
|
46
46
|
sampling_ratio = nil,
|
|
47
|
-
exclude_from_summaries = false
|
|
47
|
+
exclude_from_summaries = false,
|
|
48
|
+
override_affected = false
|
|
48
49
|
)
|
|
49
50
|
end
|
|
50
51
|
|
|
@@ -176,10 +177,11 @@ module LaunchDarkly
|
|
|
176
177
|
debug_until = nil,
|
|
177
178
|
prereq_of = nil,
|
|
178
179
|
sampling_ratio = nil,
|
|
179
|
-
exclude_from_summaries = false
|
|
180
|
+
exclude_from_summaries = false,
|
|
181
|
+
override_affected = false
|
|
180
182
|
)
|
|
181
183
|
post_to_inbox(LaunchDarkly::Impl::EvalEvent.new(timestamp, context, key, version, variation, value, reason,
|
|
182
|
-
default, track_events, debug_until, prereq_of, sampling_ratio, exclude_from_summaries))
|
|
184
|
+
default, track_events, debug_until, prereq_of, sampling_ratio, exclude_from_summaries, override_affected))
|
|
183
185
|
end
|
|
184
186
|
|
|
185
187
|
def record_identify_event(context)
|
|
@@ -328,8 +330,10 @@ module LaunchDarkly
|
|
|
328
330
|
will_add_full_event = false
|
|
329
331
|
debug_event = nil
|
|
330
332
|
if event.is_a?(LaunchDarkly::Impl::EvalEvent)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
+
# An override-affected evaluation appears only in the summary counters. It produces no
|
|
334
|
+
# individual feature event and no debug event, whatever the flag's configuration requests.
|
|
335
|
+
will_add_full_event = event.track_events && !event.override_affected
|
|
336
|
+
if !event.override_affected && should_debug_event(event)
|
|
333
337
|
debug_event = LaunchDarkly::Impl::DebugEvent.new(event)
|
|
334
338
|
end
|
|
335
339
|
else
|
|
@@ -630,18 +634,22 @@ module LaunchDarkly
|
|
|
630
634
|
summary.counters.each do |flagKey, flagInfo|
|
|
631
635
|
counters = []
|
|
632
636
|
flagInfo.versions.each do |version, variations|
|
|
633
|
-
variations.each do |variation,
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
637
|
+
variations.each do |variation, counters_by_marker|
|
|
638
|
+
counters_by_marker.each do |override_affected, counter|
|
|
639
|
+
c = {
|
|
640
|
+
value: counter.value,
|
|
641
|
+
count: counter.count,
|
|
642
|
+
}
|
|
643
|
+
c[:variation] = variation unless variation.nil?
|
|
644
|
+
if version.nil?
|
|
645
|
+
c[:unknown] = true
|
|
646
|
+
else
|
|
647
|
+
c[:version] = version
|
|
648
|
+
end
|
|
649
|
+
# The marker is present only for override-affected counters, like the unknown marker.
|
|
650
|
+
c[:overrideAffected] = true if override_affected
|
|
651
|
+
counters.push(c)
|
|
643
652
|
end
|
|
644
|
-
counters.push(c)
|
|
645
653
|
end
|
|
646
654
|
end
|
|
647
655
|
flags[flagKey] = { default: flagInfo.default, counters: counters, contextKinds: flagInfo.context_kinds.to_a }
|
|
@@ -38,9 +38,14 @@ module LaunchDarkly
|
|
|
38
38
|
# Source of truth for flag evaluations once initialized
|
|
39
39
|
@memory_store = InMemoryFeatureStoreV2.new(logger)
|
|
40
40
|
|
|
41
|
-
# Used to track dependencies between items in the store
|
|
41
|
+
# Used to track dependencies between items in the store. Items are keyed by string,
|
|
42
|
+
# the form in which the data model names prerequisites and segments.
|
|
42
43
|
@dependency_tracker = LaunchDarkly::Impl::DependencyTracker.new(logger)
|
|
43
44
|
|
|
45
|
+
# A second dependency graph, such as the override layer's, whose items may depend on
|
|
46
|
+
# items in this store. Set once when the data system is built, before any data.
|
|
47
|
+
@external_dependencies = nil
|
|
48
|
+
|
|
44
49
|
# Broadcasters for events
|
|
45
50
|
@flag_change_broadcaster = flag_change_broadcaster
|
|
46
51
|
@change_set_broadcaster = change_set_broadcaster
|
|
@@ -179,6 +184,41 @@ module LaunchDarkly
|
|
|
179
184
|
get_active_store.initialized?
|
|
180
185
|
end
|
|
181
186
|
|
|
187
|
+
#
|
|
188
|
+
# Retrieves an item from the active store.
|
|
189
|
+
#
|
|
190
|
+
# @param kind [LaunchDarkly::Impl::DataStore::DataKind]
|
|
191
|
+
# @param key [String, Symbol]
|
|
192
|
+
# @return [Object, nil] the item, or nil if it is unknown or deleted
|
|
193
|
+
#
|
|
194
|
+
def get(kind, key)
|
|
195
|
+
get_active_store.get(kind, key)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
#
|
|
199
|
+
# Retrieves all items of a kind from the active store.
|
|
200
|
+
#
|
|
201
|
+
# @param kind [LaunchDarkly::Impl::DataStore::DataKind]
|
|
202
|
+
# @return [Hash{Symbol => Object}]
|
|
203
|
+
#
|
|
204
|
+
def all(kind)
|
|
205
|
+
get_active_store.all(kind)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
#
|
|
209
|
+
# Registers a second dependency graph whose items may depend on items in this store. A
|
|
210
|
+
# change to an item in this store then also notifies the external items that depend on
|
|
211
|
+
# it, directly or through any chain of dependencies in either graph.
|
|
212
|
+
#
|
|
213
|
+
# @param dependencies [#add_affected_items, nil] a graph answering `add_affected_items(items_out, { kind:, key: })`
|
|
214
|
+
# @return [void]
|
|
215
|
+
#
|
|
216
|
+
def set_external_dependencies(dependencies)
|
|
217
|
+
@lock.synchronize do
|
|
218
|
+
@external_dependencies = dependencies
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
182
222
|
#
|
|
183
223
|
# Get the data store status provider for the persistent store, if configured.
|
|
184
224
|
#
|
|
@@ -254,9 +294,9 @@ module LaunchDarkly
|
|
|
254
294
|
|
|
255
295
|
collections.each do |kind, collection|
|
|
256
296
|
collection.each do |key, item|
|
|
257
|
-
@dependency_tracker.update_dependencies_from(kind, key, item)
|
|
297
|
+
@dependency_tracker.update_dependencies_from(kind, key.to_s, item)
|
|
258
298
|
if has_listeners
|
|
259
|
-
|
|
299
|
+
add_affected_items(affected_items, { kind: kind, key: key })
|
|
260
300
|
end
|
|
261
301
|
end
|
|
262
302
|
end
|
|
@@ -338,7 +378,45 @@ module LaunchDarkly
|
|
|
338
378
|
@dependency_tracker.reset
|
|
339
379
|
all_data.each do |kind, items|
|
|
340
380
|
items.each do |key, item|
|
|
341
|
-
@dependency_tracker.update_dependencies_from(kind, key, item)
|
|
381
|
+
@dependency_tracker.update_dependencies_from(kind, key.to_s, item)
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
#
|
|
387
|
+
# Adds the item and everything that depends on it to the set, following this store's own
|
|
388
|
+
# dependency graph and the external one. Every item reached through either graph is
|
|
389
|
+
# expanded through both, so a dependency chain may cross between them any number of
|
|
390
|
+
# times. Keys are compared as strings, so a change keyed by symbol reaches the same
|
|
391
|
+
# dependents as one keyed by string. Without an external graph, the store's own tracker
|
|
392
|
+
# expands the item in one traversal, as it did before external graphs existed.
|
|
393
|
+
#
|
|
394
|
+
# @param items_out [Set<Hash>] Set of {kind:, key:} hashes
|
|
395
|
+
# @param initial_modified_item [Hash] {kind:, key:} hash
|
|
396
|
+
# @return [void]
|
|
397
|
+
#
|
|
398
|
+
private def add_affected_items(items_out, initial_modified_item)
|
|
399
|
+
start = { kind: initial_modified_item[:kind], key: initial_modified_item[:key].to_s }
|
|
400
|
+
if @external_dependencies.nil?
|
|
401
|
+
@dependency_tracker.add_affected_items(items_out, start)
|
|
402
|
+
return
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
pending = [start]
|
|
406
|
+
until pending.empty?
|
|
407
|
+
current = pending.pop
|
|
408
|
+
# Each graph gets its own working set: a tracker does not expand an item that is
|
|
409
|
+
# already present, so a shared set would stop the second graph at the start.
|
|
410
|
+
via_store = Set.new
|
|
411
|
+
@dependency_tracker.add_affected_items(via_store, current)
|
|
412
|
+
via_external = Set.new
|
|
413
|
+
@external_dependencies&.add_affected_items(via_external, current)
|
|
414
|
+
(via_store | via_external).each do |reached|
|
|
415
|
+
item = { kind: reached[:kind], key: reached[:key].to_s }
|
|
416
|
+
next if items_out.include?(item)
|
|
417
|
+
|
|
418
|
+
items_out.add(item)
|
|
419
|
+
pending << item
|
|
342
420
|
end
|
|
343
421
|
end
|
|
344
422
|
end
|
|
@@ -380,9 +458,9 @@ module LaunchDarkly
|
|
|
380
458
|
|
|
381
459
|
# If either is missing or versions differ, it's a change
|
|
382
460
|
if old_item.nil? || new_item.nil?
|
|
383
|
-
|
|
461
|
+
add_affected_items(affected_items, { kind: kind, key: key })
|
|
384
462
|
elsif old_item[:version] != new_item[:version]
|
|
385
|
-
|
|
463
|
+
add_affected_items(affected_items, { kind: kind, key: key })
|
|
386
464
|
end
|
|
387
465
|
end
|
|
388
466
|
end
|
|
@@ -101,6 +101,11 @@ module LaunchDarkly
|
|
|
101
101
|
@store_wrapper
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
+
# (see DataSystem#override_items)
|
|
105
|
+
def override_items(_kind)
|
|
106
|
+
{}
|
|
107
|
+
end
|
|
108
|
+
|
|
104
109
|
# (see DataSystem#set_diagnostic_accumulator)
|
|
105
110
|
def set_diagnostic_accumulator(diagnostic_accumulator)
|
|
106
111
|
@diagnostic_accumulator = diagnostic_accumulator
|
|
@@ -8,7 +8,9 @@ require "ldclient-rb/impl/data_store/feature_store_client_wrapper"
|
|
|
8
8
|
require "ldclient-rb/impl/data_source/status_provider"
|
|
9
9
|
require "ldclient-rb/impl/data_store/status_provider"
|
|
10
10
|
require "ldclient-rb/impl/broadcaster"
|
|
11
|
+
require "ldclient-rb/impl/overrides"
|
|
11
12
|
require "ldclient-rb/impl/repeating_task"
|
|
13
|
+
require "ldclient-rb/impl/util"
|
|
12
14
|
require "ldclient-rb/interfaces/data_system"
|
|
13
15
|
|
|
14
16
|
module LaunchDarkly
|
|
@@ -118,6 +120,28 @@ module LaunchDarkly
|
|
|
118
120
|
# Track configuration
|
|
119
121
|
@configured_with_data_sources = (@data_system_config.initializers && !@data_system_config.initializers.empty?) ||
|
|
120
122
|
!@synchronizer_builders.empty?
|
|
123
|
+
|
|
124
|
+
# The following are nil unless an override source is configured. The layer holds override
|
|
125
|
+
# entries. The overlay serves them in preference to the store's data at the store read
|
|
126
|
+
# boundary. The source populates the layer at runtime. The override system is separate
|
|
127
|
+
# from the initializer and synchronizer pipeline and never affects data availability.
|
|
128
|
+
@override_layer = nil
|
|
129
|
+
@overlay = nil
|
|
130
|
+
@override_source = nil
|
|
131
|
+
@override_sink = nil
|
|
132
|
+
if @data_system_config.overrides && @disabled
|
|
133
|
+
@logger.warn { "[LDClient] Offline mode is enabled; the override source is not started and no overrides are served" }
|
|
134
|
+
elsif @data_system_config.overrides
|
|
135
|
+
# An invalid override source configuration raises here, so LDClient.new reports it
|
|
136
|
+
# the same way as other invalid component configuration.
|
|
137
|
+
@override_source = @data_system_config.overrides.build(@sdk_key, @config)
|
|
138
|
+
@override_layer = LaunchDarkly::Impl::Overrides::Layer.new
|
|
139
|
+
@overlay = LaunchDarkly::Impl::Overrides::Overlay.new(@store, @override_layer)
|
|
140
|
+
# A LaunchDarkly change to a flag or segment that an override entry depends on must
|
|
141
|
+
# notify that entry's flag as well. The store reaches those entries through the
|
|
142
|
+
# layer's dependency graph.
|
|
143
|
+
@store.set_external_dependencies(@override_layer)
|
|
144
|
+
end
|
|
121
145
|
end
|
|
122
146
|
|
|
123
147
|
# (see DataSystem#start)
|
|
@@ -131,6 +155,10 @@ module LaunchDarkly
|
|
|
131
155
|
@stop_event.reset
|
|
132
156
|
@ready_event.reset
|
|
133
157
|
|
|
158
|
+
# The override source starts before the run loop, so a source that loads synchronously has
|
|
159
|
+
# its overrides in place before the client begins evaluating.
|
|
160
|
+
start_override_source if @override_source
|
|
161
|
+
|
|
134
162
|
# Start the main coordination thread
|
|
135
163
|
main_thread = Thread.new { run_main_loop }
|
|
136
164
|
main_thread.name = "FDv2-main"
|
|
@@ -141,6 +169,14 @@ module LaunchDarkly
|
|
|
141
169
|
|
|
142
170
|
# (see DataSystem#stop)
|
|
143
171
|
def stop
|
|
172
|
+
if @override_source
|
|
173
|
+
# The sink stops accepting snapshots first, so a snapshot that the source supplies while
|
|
174
|
+
# it stops cannot update the layer or notify listeners while the system shuts down. The
|
|
175
|
+
# sink does not exist if the system was never started.
|
|
176
|
+
@override_sink&.close
|
|
177
|
+
stop_override_source("Error stopping override source")
|
|
178
|
+
end
|
|
179
|
+
|
|
144
180
|
@stop_event.set
|
|
145
181
|
|
|
146
182
|
@lock.synchronize do
|
|
@@ -175,9 +211,18 @@ module LaunchDarkly
|
|
|
175
211
|
|
|
176
212
|
# (see DataSystem#store)
|
|
177
213
|
def store
|
|
214
|
+
return @overlay if @overlay
|
|
215
|
+
|
|
178
216
|
@store.get_active_store
|
|
179
217
|
end
|
|
180
218
|
|
|
219
|
+
# (see DataSystem#override_items)
|
|
220
|
+
def override_items(kind)
|
|
221
|
+
return {} if @override_layer.nil?
|
|
222
|
+
|
|
223
|
+
@override_layer.all(kind)
|
|
224
|
+
end
|
|
225
|
+
|
|
181
226
|
# (see DataSystem#data_source_status_provider)
|
|
182
227
|
def data_source_status_provider
|
|
183
228
|
@data_source_status_provider
|
|
@@ -215,6 +260,45 @@ module LaunchDarkly
|
|
|
215
260
|
|
|
216
261
|
private
|
|
217
262
|
|
|
263
|
+
#
|
|
264
|
+
# Starts the override source. The source has no effect on initialization, and a source that
|
|
265
|
+
# fails to start does not prevent the client from operating: the failure is logged, the
|
|
266
|
+
# source is stopped, and the client runs without overrides. The SDK's own file-based source
|
|
267
|
+
# does not raise from start; it logs a failed load and retries it. A custom source could
|
|
268
|
+
# raise, and an application in an incident is better served by a client that runs without
|
|
269
|
+
# its overrides than by one that does not start.
|
|
270
|
+
#
|
|
271
|
+
def start_override_source
|
|
272
|
+
@override_sink = LaunchDarkly::Impl::Overrides::Sink.new(@override_layer, @store, @flag_change_broadcaster, @logger)
|
|
273
|
+
begin
|
|
274
|
+
@override_source.start(@override_sink)
|
|
275
|
+
rescue StandardError, ScriptError => e
|
|
276
|
+
# ScriptError covers the NotImplementedError that the interface's default start raises
|
|
277
|
+
# for a source that does not implement it.
|
|
278
|
+
LaunchDarkly::Impl::Util.log_exception(@logger, "Unable to start the override source; the client runs without overrides", e)
|
|
279
|
+
stop_override_source("Error stopping override source after it failed to start")
|
|
280
|
+
# The source may have supplied a snapshot before it failed. Clearing the layer removes
|
|
281
|
+
# it, so the client runs without overrides as logged, and a late snapshot from the
|
|
282
|
+
# stopped source is ignored.
|
|
283
|
+
@override_sink.close_and_clear
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
#
|
|
288
|
+
# Stops the override source and forgets it. A custom source can raise from stop, including
|
|
289
|
+
# the NotImplementedError of the interface's default stop; that is logged and not raised,
|
|
290
|
+
# so the rest of the system still stops, or still starts after a failed start.
|
|
291
|
+
#
|
|
292
|
+
def stop_override_source(failure_message)
|
|
293
|
+
source = @override_source
|
|
294
|
+
@override_source = nil
|
|
295
|
+
begin
|
|
296
|
+
source.stop
|
|
297
|
+
rescue StandardError, ScriptError => e
|
|
298
|
+
@logger.error { "[LDClient] #{failure_message}: #{e.message}" }
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
218
302
|
#
|
|
219
303
|
# Main coordination loop that manages initializers and synchronizers.
|
|
220
304
|
#
|
|
@@ -497,6 +497,15 @@ module LaunchDarkly
|
|
|
497
497
|
builder.start(server_intent.payload.code)
|
|
498
498
|
|
|
499
499
|
when LaunchDarkly::Interfaces::DataSystem::EventName::PUT_OBJECT
|
|
500
|
+
unless event[:data].is_a?(Hash)
|
|
501
|
+
return LaunchDarkly::Result.fail("Invalid payload: 'put-object' data must be an object")
|
|
502
|
+
end
|
|
503
|
+
unless event[:data][:kind].is_a?(String)
|
|
504
|
+
return LaunchDarkly::Result.fail("Invalid payload: 'put-object' kind must be a string")
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
next if LaunchDarkly::Impl::DataSystem::ProtocolV2.unsupported_kind?(event[:data])
|
|
508
|
+
|
|
500
509
|
begin
|
|
501
510
|
put = LaunchDarkly::Impl::DataSystem::ProtocolV2::PutObject.from_h(event[:data])
|
|
502
511
|
rescue ArgumentError => e
|
|
@@ -506,6 +515,15 @@ module LaunchDarkly
|
|
|
506
515
|
builder.add_put(put.kind, put.key, put.version, put.object)
|
|
507
516
|
|
|
508
517
|
when LaunchDarkly::Interfaces::DataSystem::EventName::DELETE_OBJECT
|
|
518
|
+
unless event[:data].is_a?(Hash)
|
|
519
|
+
return LaunchDarkly::Result.fail("Invalid payload: 'delete-object' data must be an object")
|
|
520
|
+
end
|
|
521
|
+
unless event[:data][:kind].is_a?(String)
|
|
522
|
+
return LaunchDarkly::Result.fail("Invalid payload: 'delete-object' kind must be a string")
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
next if LaunchDarkly::Impl::DataSystem::ProtocolV2.unsupported_kind?(event[:data])
|
|
526
|
+
|
|
509
527
|
begin
|
|
510
528
|
delete_object = LaunchDarkly::Impl::DataSystem::ProtocolV2::DeleteObject.from_h(event[:data])
|
|
511
529
|
rescue ArgumentError => e
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'json'
|
|
2
|
+
require 'ldclient-rb/interfaces/data_system'
|
|
2
3
|
|
|
3
4
|
module LaunchDarkly
|
|
4
5
|
module Impl
|
|
@@ -9,6 +10,23 @@ module LaunchDarkly
|
|
|
9
10
|
# LaunchDarkly data system version 2 (FDv2).
|
|
10
11
|
#
|
|
11
12
|
|
|
13
|
+
SUPPORTED_KINDS = [
|
|
14
|
+
LaunchDarkly::Interfaces::DataSystem::ObjectKind::FLAG,
|
|
15
|
+
LaunchDarkly::Interfaces::DataSystem::ObjectKind::SEGMENT,
|
|
16
|
+
].freeze
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# Returns true if put-object or delete-object data names a kind this SDK
|
|
20
|
+
# does not support. Such objects are ignored so that payloads carrying
|
|
21
|
+
# newer kinds can still be applied.
|
|
22
|
+
#
|
|
23
|
+
# @param data [Hash] The hash representation of the event data, with a String kind
|
|
24
|
+
# @return [Boolean]
|
|
25
|
+
#
|
|
26
|
+
def self.unsupported_kind?(data)
|
|
27
|
+
!SUPPORTED_KINDS.include?(data[:kind])
|
|
28
|
+
end
|
|
29
|
+
|
|
12
30
|
#
|
|
13
31
|
# DeleteObject specifies the deletion of a particular object.
|
|
14
32
|
#
|
|
@@ -246,13 +246,25 @@ module LaunchDarkly
|
|
|
246
246
|
nil
|
|
247
247
|
|
|
248
248
|
when LaunchDarkly::Interfaces::DataSystem::EventName::PUT_OBJECT
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
data = JSON.parse(message.data, symbolize_names: true)
|
|
250
|
+
raise ArgumentError, "put-object data must be an object" unless data.is_a?(Hash)
|
|
251
|
+
raise ArgumentError, "put-object kind must be a string" unless data[:kind].is_a?(String)
|
|
252
|
+
|
|
253
|
+
unless LaunchDarkly::Impl::DataSystem::ProtocolV2.unsupported_kind?(data)
|
|
254
|
+
put = LaunchDarkly::Impl::DataSystem::ProtocolV2::PutObject.from_h(data)
|
|
255
|
+
change_set_builder.add_put(put.kind, put.key, put.version, put.object)
|
|
256
|
+
end
|
|
251
257
|
nil
|
|
252
258
|
|
|
253
259
|
when LaunchDarkly::Interfaces::DataSystem::EventName::DELETE_OBJECT
|
|
254
|
-
|
|
255
|
-
|
|
260
|
+
data = JSON.parse(message.data, symbolize_names: true)
|
|
261
|
+
raise ArgumentError, "delete-object data must be an object" unless data.is_a?(Hash)
|
|
262
|
+
raise ArgumentError, "delete-object kind must be a string" unless data[:kind].is_a?(String)
|
|
263
|
+
|
|
264
|
+
unless LaunchDarkly::Impl::DataSystem::ProtocolV2.unsupported_kind?(data)
|
|
265
|
+
delete_object = LaunchDarkly::Impl::DataSystem::ProtocolV2::DeleteObject.from_h(data)
|
|
266
|
+
change_set_builder.add_delete(delete_object.kind, delete_object.key, delete_object.version)
|
|
267
|
+
end
|
|
256
268
|
nil
|
|
257
269
|
|
|
258
270
|
when LaunchDarkly::Interfaces::DataSystem::EventName::GOODBYE
|