Module: LaunchDarkly::DataSystem

Defined in:
lib/ldclient-rb/data_system.rb

Overview

Configuration for LaunchDarkly’s data acquisition strategy.

This module provides factory methods for creating data system configurations.

Defined Under Namespace

Classes: ConfigBuilder

Class Method Summary collapse

Class Method Details

.customConfigBuilder

Custom returns a builder suitable for creating a custom data acquisition strategy. You may configure how the SDK uses a Persistent Store, how the SDK obtains an initial set of data, and how the SDK keeps data up-to-date.



212
213
214
# File 'lib/ldclient-rb/data_system.rb', line 212

def self.custom
  ConfigBuilder.new
end

.daemon(store) ⇒ ConfigBuilder

Daemon configures the SDK to read from a persistent store integration that is populated by Relay Proxy or other SDKs. The SDK will not connect to LaunchDarkly. In this mode, the SDK never writes to the data store.



224
225
226
# File 'lib/ldclient-rb/data_system.rb', line 224

def self.daemon(store)
  custom.data_store(store, LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_ONLY)
end

.defaultConfigBuilder

Default is LaunchDarkly’s recommended flag data acquisition strategy.

Currently, it operates a two-phase method for obtaining data: first, it requests data from LaunchDarkly’s global CDN. Then, it initiates a streaming connection to LaunchDarkly’s Flag Delivery services to receive real-time updates.

If the streaming connection is interrupted for an extended period of time, the SDK will automatically fall back to polling the global CDN for updates.



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/ldclient-rb/data_system.rb', line 155

def self.default
  polling_builder = polling_ds_builder
  streaming_builder = streaming_ds_builder
  fallback = fdv1_fallback_ds_builder

  builder = ConfigBuilder.new
  builder.initializers([polling_builder])
  builder.synchronizers(streaming_builder, polling_builder)
  builder.fdv1_compatible_synchronizer(fallback)

  builder
end

.fdv1_fallback_ds_builderProc

Returns a builder proc for creating an FDv1 fallback polling data source. This is a building block that can be used with LaunchDarkly::DataSystem::ConfigBuilder#fdv1_compatible_synchronizer to provide FDv1 compatibility in custom data system configurations.



121
122
123
124
125
# File 'lib/ldclient-rb/data_system.rb', line 121

def self.fdv1_fallback_ds_builder
  lambda do |sdk_key, config|
    LaunchDarkly::Impl::DataSystem::FDv1PollingDataSourceBuilder.new(sdk_key, config).build
  end
end

.persistent_store(store) ⇒ ConfigBuilder

PersistentStore is similar to default, with the addition of a persistent store integration. Before data has arrived from LaunchDarkly, the SDK is able to evaluate flags using data from the persistent store. Once fresh data is available, the SDK will no longer read from the persistent store, although it will keep it up-to-date.



238
239
240
# File 'lib/ldclient-rb/data_system.rb', line 238

def self.persistent_store(store)
  default.data_store(store, LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_WRITE)
end

.pollingConfigBuilder

Polling configures the SDK to regularly poll an endpoint for flag/segment data in the background. This is less efficient than streaming, but may be necessary in some network environments.



193
194
195
196
197
198
199
200
201
202
# File 'lib/ldclient-rb/data_system.rb', line 193

def self.polling
  polling_builder = polling_ds_builder
  fallback = fdv1_fallback_ds_builder

  builder = ConfigBuilder.new
  builder.synchronizers(polling_builder)
  builder.fdv1_compatible_synchronizer(fallback)

  builder
end

.polling_ds_builderProc

Returns a builder proc for creating a polling data source. This is a building block that can be used with LaunchDarkly::DataSystem::ConfigBuilder#initializers or LaunchDarkly::DataSystem::ConfigBuilder#synchronizers to create custom data system configurations.



108
109
110
111
112
# File 'lib/ldclient-rb/data_system.rb', line 108

def self.polling_ds_builder
  lambda do |sdk_key, config|
    LaunchDarkly::Impl::DataSystem::PollingDataSourceBuilder.new(sdk_key, config).build
  end
end

.streamingConfigBuilder

Streaming configures the SDK to efficiently stream flag/segment data in the background, allowing evaluations to operate on the latest data with no additional latency.



175
176
177
178
179
180
181
182
183
184
# File 'lib/ldclient-rb/data_system.rb', line 175

def self.streaming
  streaming_builder = streaming_ds_builder
  fallback = fdv1_fallback_ds_builder

  builder = ConfigBuilder.new
  builder.synchronizers(streaming_builder)
  builder.fdv1_compatible_synchronizer(fallback)

  builder
end

.streaming_ds_builderProc

Returns a builder proc for creating a streaming data source. This is a building block that can be used with LaunchDarkly::DataSystem::ConfigBuilder#synchronizers to create custom data system configurations.



134
135
136
137
138
139
# File 'lib/ldclient-rb/data_system.rb', line 134

def self.streaming_ds_builder
  # TODO(fdv2): Implement streaming data source builder
  lambda do |_sdk_key, _config|
    raise NotImplementedError, "Streaming data source not yet implemented for FDv2"
  end
end