Skip to content

Commit 368aa3c

Browse files
authored
chore: Support synchronizer lists in data system config (#362)
1 parent e60474c commit 368aa3c

13 files changed

Lines changed: 181 additions & 263 deletions

File tree

.github/actions/check/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ runs:
5151
test_service_port: 9000
5252
enable_persistence_tests: true
5353
token: ${{ inputs.token }}
54-
version: v3.0.0-alpha.2
54+
version: v3.0.0-alpha.3

contract-tests/client_entity.rb

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,13 @@ def initialize(log, config)
3737
data_system.initializers(initializers)
3838
end
3939

40-
sync_config = data_system_config[:synchronizers]
41-
if sync_config
42-
primary = sync_config[:primary]
43-
secondary = sync_config[:secondary]
40+
sync_configs = data_system_config[:synchronizers]
41+
if sync_configs && !sync_configs.empty?
42+
synchronizer_builders = sync_configs.map { |sync_config| build_synchronizer_builder(sync_config) }.compact
43+
data_system.synchronizers(synchronizer_builders) unless synchronizer_builders.empty?
4444

45-
primary_builder = build_synchronizer_builder(primary)
46-
secondary_builder = build_synchronizer_builder(secondary)
47-
48-
data_system.synchronizers(primary_builder, secondary_builder) if primary_builder
49-
50-
if primary_builder || secondary_builder
51-
fallback_builder = build_fdv1_fallback_builder(primary, secondary)
52-
data_system.fdv1_compatible_synchronizer(fallback_builder)
53-
end
45+
fallback_builder = build_fdv1_fallback_builder(sync_configs)
46+
data_system.fdv1_compatible_synchronizer(fallback_builder)
5447
end
5548

5649
if data_system_config[:payloadFilter]
@@ -327,17 +320,16 @@ def close
327320
end
328321

329322
#
330-
# Builds an FDv1 fallback polling data source builder using the first available config.
323+
# Builds an FDv1 fallback polling data source builder using the first available polling config.
331324
#
332-
# @param primary [Hash, nil] The primary synchronizer configuration
333-
# @param secondary [Hash, nil] The secondary synchronizer configuration
325+
# @param sync_configs [Array<Hash>] Array of synchronizer configurations
334326
# @return [Object] Returns the configured FDv1 fallback builder
335327
#
336-
private def build_fdv1_fallback_builder(primary, secondary)
328+
private def build_fdv1_fallback_builder(sync_configs)
337329
builder = LaunchDarkly::DataSystem.fdv1_fallback_ds_builder
338330

339331
# Use the first available polling config for the fallback base_uri
340-
polling_config = primary&.dig(:polling) || secondary&.dig(:polling)
332+
polling_config = sync_configs.lazy.map { |c| c[:polling] }.detect { |p| p }
341333
if polling_config
342334
builder.base_uri(polling_config[:baseUri]) if polling_config[:baseUri]
343335
builder.poll_interval(polling_config[:pollIntervalMs] / 1_000.0) if polling_config[:pollIntervalMs]

lib/ldclient-rb/config.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -703,34 +703,28 @@ def initialize(store:, context_cache_size: nil, context_cache_time: nil, status_
703703
class DataSystemConfig
704704
#
705705
# @param initializers [Array<#build(String, Config)>, nil] The (optional) array of builders
706-
# @param primary_synchronizer [#build(String, Config), nil] The (optional) builder for primary synchronizer
707-
# @param secondary_synchronizer [#build(String, Config), nil] The (optional) builder for secondary synchronizer
706+
# @param synchronizers [Array<#build(String, Config)>, nil] The (optional) array of synchronizer builders
708707
# @param data_store_mode [Symbol] The (optional) data store mode
709708
# @param data_store [LaunchDarkly::Interfaces::FeatureStore, nil] The (optional) data store
710709
# @param fdv1_fallback_synchronizer [#build(String, Config), nil]
711710
# The (optional) builder for FDv1-compatible fallback synchronizer
712711
#
713-
def initialize(initializers: nil, primary_synchronizer: nil, secondary_synchronizer: nil,
712+
def initialize(initializers: nil, synchronizers: nil,
714713
data_store_mode: LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_ONLY, data_store: nil, fdv1_fallback_synchronizer: nil)
715714
@initializers = initializers
716-
@primary_synchronizer = primary_synchronizer
717-
@secondary_synchronizer = secondary_synchronizer
715+
@synchronizers = synchronizers
718716
@data_store_mode = data_store_mode
719717
@data_store = data_store
720718
@fdv1_fallback_synchronizer = fdv1_fallback_synchronizer
721719
end
722720

723-
# The initializers for the data system. Each builder responds to build(sdk_key, config) and returns an Initializer.
721+
# The initializer builders for the data system. Each builder responds to build(sdk_key, config) and returns an Initializer.
724722
# @return [Array<#build(String, Config)>, nil]
725723
attr_reader :initializers
726724

727-
# The primary synchronizer builder. Responds to build(sdk_key, config) and returns a Synchronizer.
728-
# @return [#build(String, Config), nil]
729-
attr_reader :primary_synchronizer
730-
731-
# The secondary synchronizer builder. Responds to build(sdk_key, config) and returns a Synchronizer.
732-
# @return [#build(String, Config), nil]
733-
attr_reader :secondary_synchronizer
725+
# The synchronizer builders for the data system. Each builder responds to build(sdk_key, config) and returns a Synchronizer.
726+
# @return [Array<#build(String, Config)>, nil]
727+
attr_reader :synchronizers
734728

735729
# The data store mode.
736730
# @return [Symbol]

lib/ldclient-rb/data_system.rb

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ module DataSystem
1818
class ConfigBuilder
1919
def initialize
2020
@initializers = nil
21-
@primary_synchronizer = nil
22-
@secondary_synchronizer = nil
21+
@synchronizers = nil
2322
@fdv1_fallback_synchronizer = nil
2423
@data_store_mode = LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_ONLY
2524
@data_store = nil
@@ -40,13 +39,12 @@ def initializers(initializers)
4039
#
4140
# Sets the synchronizers for the data system.
4241
#
43-
# @param primary [#build(String, Config)] Builder that responds to build(sdk_key, config) and returns the primary Synchronizer
44-
# @param secondary [#build(String, Config), nil] Builder that responds to build(sdk_key, config) and returns the secondary Synchronizer
42+
# @param synchronizers [Array<#build(String, Config)>]
43+
# Array of builders that respond to build(sdk_key, config) and return a Synchronizer
4544
# @return [ConfigBuilder] self for chaining
4645
#
47-
def synchronizers(primary, secondary = nil)
48-
@primary_synchronizer = primary
49-
@secondary_synchronizer = secondary
46+
def synchronizers(synchronizers)
47+
@synchronizers = synchronizers
5048
self
5149
end
5250

@@ -79,17 +77,11 @@ def data_store(data_store, store_mode)
7977
# Builds the data system configuration.
8078
#
8179
# @return [DataSystemConfig]
82-
# @raise [ArgumentError] if configuration is invalid
8380
#
8481
def build
85-
if @secondary_synchronizer && @primary_synchronizer.nil?
86-
raise ArgumentError, "Primary synchronizer must be set if secondary is set"
87-
end
88-
8982
DataSystemConfig.new(
9083
initializers: @initializers,
91-
primary_synchronizer: @primary_synchronizer,
92-
secondary_synchronizer: @secondary_synchronizer,
84+
synchronizers: @synchronizers,
9385
data_store_mode: @data_store_mode,
9486
data_store: @data_store,
9587
fdv1_fallback_synchronizer: @fdv1_fallback_synchronizer
@@ -151,7 +143,7 @@ def self.default
151143

152144
builder = ConfigBuilder.new
153145
builder.initializers([polling_builder])
154-
builder.synchronizers(streaming_builder, polling_builder)
146+
builder.synchronizers([streaming_builder, polling_builder])
155147
builder.fdv1_compatible_synchronizer(fallback)
156148

157149
builder
@@ -169,7 +161,7 @@ def self.streaming
169161
fallback = fdv1_fallback_ds_builder
170162

171163
builder = ConfigBuilder.new
172-
builder.synchronizers(streaming_builder)
164+
builder.synchronizers([streaming_builder])
173165
builder.fdv1_compatible_synchronizer(fallback)
174166

175167
builder
@@ -187,7 +179,7 @@ def self.polling
187179
fallback = fdv1_fallback_ds_builder
188180

189181
builder = ConfigBuilder.new
190-
builder.synchronizers(polling_builder)
182+
builder.synchronizers([polling_builder])
191183
builder.fdv1_compatible_synchronizer(fallback)
192184

193185
builder

lib/ldclient-rb/impl/data_source/status_provider.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def update_status(new_state, new_error)
5454
new_state = LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING
5555
end
5656

57+
# Special handling: You can't go back to INITIALIZING after being anything else
58+
if new_state == LaunchDarkly::Interfaces::DataSource::Status::INITIALIZING && !old_status.state.nil?
59+
new_state = old_status.state
60+
end
61+
5762
# No change if state is the same and no error
5863
return if new_state == old_status.state && new_error.nil?
5964

lib/ldclient-rb/impl/data_store/status_provider.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ module DataStore
1010
#
1111
# StatusProviderV2 is the FDv2-specific implementation of {LaunchDarkly::Interfaces::DataStore::StatusProvider}.
1212
#
13-
# This type is not stable, and not subject to any backwards
14-
# compatibility guarantees or semantic versioning. It is not suitable for production usage.
15-
#
16-
# Do not use it.
17-
# You have been warned.
18-
#
1913
class StatusProviderV2
2014
include LaunchDarkly::Interfaces::DataStore::StatusProvider
2115

0 commit comments

Comments
 (0)