Class: LaunchDarkly::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/config.rb

Overview

This class exposes advanced configuration options for the LaunchDarkly client library. Most users will not need to use a custom configuration– the default configuration sets sane defaults for most use cases.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ type

Constructor for creating custom LaunchDarkly configurations.

rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity

Parameters:

  • opts (Hash) (defaults to: {})

    the configuration options

Options Hash (opts):

  • :logger (Logger)

    A logger to use for messages from the LaunchDarkly client. Defaults to the Rails logger in a Rails environment, or stdout otherwise.

  • :base_uri (String) — default: "https://app.launchdarkly.com"

    The base URL for the LaunchDarkly server. Most users should use the default value.

  • :stream_uri (String) — default: "https://stream.launchdarkly.com"

    The URL for the LaunchDarkly streaming events server. Most users should use the default value.

  • :events_uri (String) — default: "https://events.launchdarkly.com"

    The URL for the LaunchDarkly events server. Most users should use the default value.

  • :capacity (Integer) — default: 10000

    The capacity of the events buffer. The client buffers up to this many events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events will be discarded.

  • :flush_interval (Float) — default: 30

    The number of seconds between flushes of the event buffer.

  • :read_timeout (Float) — default: 10

    The read timeout for network connections in seconds.

  • :connect_timeout (Float) — default: 2

    The connect timeout for network connections in seconds.

  • :cache_store (Object)

    A cache store for the Faraday HTTP caching library. Defaults to the Rails cache in a Rails environment, or a thread-safe in-memory store otherwise.

  • :feature_store (Object)

    A store for feature flags and related data. Defaults to an in-memory cache, or you can use RedisFeatureStore.

  • :use_ldd (Boolean) — default: false

    Whether you are using the LaunchDarkly relay proxy in daemon mode. In this configuration, the client will not use a streaming connection to listen for updates, but instead will get feature state from a Redis instance. The stream and poll_interval options will be ignored if this option is set to true.

  • :offline (Boolean) — default: false

    Whether the client should be initialized in offline mode. In offline mode, default values are returned for all flags and no remote network requests are made.

  • :poll_interval (Float) — default: 30

    The number of seconds between polls for flag updates if streaming is off.

  • :stream (Boolean) — default: true

    Whether or not the streaming API should be used to receive flag updates. Streaming should only be disabled on the advice of LaunchDarkly support.

  • all_attributes_private (Boolean) — default: false

    If true, all user attributes (other than the key) will be private, not just the attributes specified in private_attribute_names.

  • :private_attribute_names (Array)

    Marks a set of attribute names private. Any users sent to LaunchDarkly with this configuration active will have attributes with these names removed.

  • :send_events (Boolean) — default: true

    Whether or not to send events back to LaunchDarkly. This differs from offline in that it affects only the sending of client-side events, not streaming or polling for events from the server.

  • :user_keys_capacity (Integer) — default: 1000

    The number of user keys that the event processor can remember at any one time, so that duplicate user details will not be sent in analytics events.

  • :user_keys_flush_interval (Float) — default: 300

    The interval in seconds at which the event processor will reset its set of known user keys.

  • :inline_users_in_events (Boolean) — default: false

    Whether to include full user details in every analytics event. By default, events will only include the user key, except for one “index” event that provides the full details for the user.

  • :update_processor (Object)

    An object that will receive feature flag data from LaunchDarkly. Defaults to either the streaming or the polling processor, can be customized for tests.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ldclient-rb/config.rb', line 68

def initialize(opts = {})
  @base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
  @stream_uri = (opts[:stream_uri] || Config.default_stream_uri).chomp("/")
  @events_uri = (opts[:events_uri] || Config.default_events_uri).chomp("/")
  @capacity = opts[:capacity] || Config.default_capacity
  @logger = opts[:logger] || Config.default_logger
  @cache_store = opts[:cache_store] || Config.default_cache_store
  @flush_interval = opts[:flush_interval] || Config.default_flush_interval
  @connect_timeout = opts[:connect_timeout] || Config.default_connect_timeout
  @read_timeout = opts[:read_timeout] || Config.default_read_timeout
  @feature_store = opts[:feature_store] || Config.default_feature_store
  @stream = opts.has_key?(:stream) ? opts[:stream] : Config.default_stream
  @use_ldd = opts.has_key?(:use_ldd) ? opts[:use_ldd] : Config.default_use_ldd
  @offline = opts.has_key?(:offline) ? opts[:offline] : Config.default_offline
  @poll_interval = opts.has_key?(:poll_interval) && opts[:poll_interval] > Config.default_poll_interval ? opts[:poll_interval] : Config.default_poll_interval
  @proxy = opts[:proxy] || Config.default_proxy
  @all_attributes_private = opts[:all_attributes_private] || false
  @private_attribute_names = opts[:private_attribute_names] || []
  @send_events = opts.has_key?(:send_events) ? opts[:send_events] : Config.default_send_events
  @user_keys_capacity = opts[:user_keys_capacity] || Config.default_user_keys_capacity
  @user_keys_flush_interval = opts[:user_keys_flush_interval] || Config.default_user_keys_flush_interval
  @inline_users_in_events = opts[:inline_users_in_events] || false
  @update_processor = opts[:update_processor]
end

Instance Attribute Details

#all_attributes_privateObject (readonly)

Returns the value of attribute all_attributes_private.



192
193
194
# File 'lib/ldclient-rb/config.rb', line 192

def all_attributes_private
  @all_attributes_private
end

#base_uriString (readonly)

The base URL for the LaunchDarkly server.

Returns:

  • (String)

    The configured base URL for the LaunchDarkly server.



97
98
99
# File 'lib/ldclient-rb/config.rb', line 97

def base_uri
  @base_uri
end

#cache_storeObject (readonly)

The store for the Faraday HTTP caching library. Stores should respond to ‘read’ and ‘write’ requests.

Returns:

  • (Object)

    The configured store for the Faraday HTTP caching library.



169
170
171
# File 'lib/ldclient-rb/config.rb', line 169

def cache_store
  @cache_store
end

#capacityInteger (readonly)

The capacity of the events buffer. The client buffers up to this many events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events will be discarded. Increasing the capacity means that events are less likely to be discarded, at the cost of consuming more memory.

Returns:

  • (Integer)

    The configured capacity of the event buffer



162
163
164
# File 'lib/ldclient-rb/config.rb', line 162

def capacity
  @capacity
end

#connect_timeoutFloat (readonly)

The connect timeout for network connections in seconds.

Returns:

  • (Float)

    The connect timeout in seconds.



181
182
183
# File 'lib/ldclient-rb/config.rb', line 181

def connect_timeout
  @connect_timeout
end

#events_uriString (readonly)

The base URL for the LaunchDarkly events server.

Returns:

  • (String)

    The configured base URL for the LaunchDarkly events server.



109
110
111
# File 'lib/ldclient-rb/config.rb', line 109

def events_uri
  @events_uri
end

#feature_storeObject (readonly)

A store for feature flag configuration rules.



186
187
188
# File 'lib/ldclient-rb/config.rb', line 186

def feature_store
  @feature_store
end

#flush_intervalFloat (readonly)

The number of seconds between flushes of the event buffer. Decreasing the flush interval means that the event buffer is less likely to reach capacity.

Returns:

  • (Float)

    The configured number of seconds between flushes of the event buffer.



140
141
142
# File 'lib/ldclient-rb/config.rb', line 140

def flush_interval
  @flush_interval
end

#inline_users_in_eventsObject (readonly)

Whether to include full user details in every analytics event. By default, events will only include the user key, except for one “index” event that provides the full details for the user.



217
218
219
# File 'lib/ldclient-rb/config.rb', line 217

def inline_users_in_events
  @inline_users_in_events
end

#loggerLogger (readonly)

The configured logger for the LaunchDarkly client. The client library uses the log to print warning and error messages.

Returns:

  • (Logger)

    The configured logger



152
153
154
# File 'lib/ldclient-rb/config.rb', line 152

def logger
  @logger
end

#poll_intervalObject (readonly)

The number of seconds to wait before polling for feature flag updates. This option has no effect unless streaming is disabled



145
146
147
# File 'lib/ldclient-rb/config.rb', line 145

def poll_interval
  @poll_interval
end

#private_attribute_namesObject (readonly)

Returns the value of attribute private_attribute_names.



194
195
196
# File 'lib/ldclient-rb/config.rb', line 194

def private_attribute_names
  @private_attribute_names
end

#proxyObject (readonly)

The proxy configuration string



190
191
192
# File 'lib/ldclient-rb/config.rb', line 190

def proxy
  @proxy
end

#read_timeoutFloat (readonly)

The read timeout for network connections in seconds.

Returns:

  • (Float)

    The read timeout in seconds.



175
176
177
# File 'lib/ldclient-rb/config.rb', line 175

def read_timeout
  @read_timeout
end

#send_eventsObject (readonly)

Whether to send events back to LaunchDarkly.



199
200
201
# File 'lib/ldclient-rb/config.rb', line 199

def send_events
  @send_events
end

#stream_uriString (readonly)

The base URL for the LaunchDarkly streaming server.

Returns:

  • (String)

    The configured base URL for the LaunchDarkly streaming server.



103
104
105
# File 'lib/ldclient-rb/config.rb', line 103

def stream_uri
  @stream_uri
end

#update_processorObject (readonly)

Returns the value of attribute update_processor.



219
220
221
# File 'lib/ldclient-rb/config.rb', line 219

def update_processor
  @update_processor
end

#user_keys_capacityObject (readonly)

The number of user keys that the event processor can remember at any one time, so that duplicate user details will not be sent in analytics events.



205
206
207
# File 'lib/ldclient-rb/config.rb', line 205

def user_keys_capacity
  @user_keys_capacity
end

#user_keys_flush_intervalObject (readonly)

The interval in seconds at which the event processor will reset its set of known user keys.



210
211
212
# File 'lib/ldclient-rb/config.rb', line 210

def user_keys_flush_interval
  @user_keys_flush_interval
end

Class Method Details

.defaultConfig

The default LaunchDarkly client configuration. This configuration sets reasonable defaults for most users.

Returns:

  • (Config)

    The default LaunchDarkly configuration.



226
227
228
# File 'lib/ldclient-rb/config.rb', line 226

def self.default
  Config.new
end

.default_base_uriObject



234
235
236
# File 'lib/ldclient-rb/config.rb', line 234

def self.default_base_uri
  "https://app.launchdarkly.com"
end

.default_cache_storeObject



246
247
248
# File 'lib/ldclient-rb/config.rb', line 246

def self.default_cache_store
  defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new
end

.default_capacityObject



230
231
232
# File 'lib/ldclient-rb/config.rb', line 230

def self.default_capacity
  10000
end

.default_connect_timeoutObject



258
259
260
# File 'lib/ldclient-rb/config.rb', line 258

def self.default_connect_timeout
  2
end

.default_events_uriObject



242
243
244
# File 'lib/ldclient-rb/config.rb', line 242

def self.default_events_uri
  "https://events.launchdarkly.com"
end

.default_feature_storeObject



284
285
286
# File 'lib/ldclient-rb/config.rb', line 284

def self.default_feature_store
  InMemoryFeatureStore.new
end

.default_flush_intervalObject



250
251
252
# File 'lib/ldclient-rb/config.rb', line 250

def self.default_flush_interval
  10
end

.default_loggerObject



266
267
268
269
270
271
272
273
274
# File 'lib/ldclient-rb/config.rb', line 266

def self.default_logger
  if defined?(Rails) && Rails.respond_to?(:logger)
    Rails.logger 
  else 
    log = ::Logger.new($stdout)
    log.level = ::Logger::WARN
    log
  end
end

.default_offlineObject



288
289
290
# File 'lib/ldclient-rb/config.rb', line 288

def self.default_offline
  false
end

.default_poll_intervalObject



292
293
294
# File 'lib/ldclient-rb/config.rb', line 292

def self.default_poll_interval
  30
end

.default_proxyObject



262
263
264
# File 'lib/ldclient-rb/config.rb', line 262

def self.default_proxy
  nil
end

.default_read_timeoutObject



254
255
256
# File 'lib/ldclient-rb/config.rb', line 254

def self.default_read_timeout
  10
end

.default_send_eventsObject



296
297
298
# File 'lib/ldclient-rb/config.rb', line 296

def self.default_send_events
  true
end

.default_streamObject



276
277
278
# File 'lib/ldclient-rb/config.rb', line 276

def self.default_stream
  true
end

.default_stream_uriObject



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

def self.default_stream_uri
  "https://stream.launchdarkly.com"
end

.default_use_lddObject



280
281
282
# File 'lib/ldclient-rb/config.rb', line 280

def self.default_use_ldd
  false
end

.default_user_keys_capacityObject



300
301
302
# File 'lib/ldclient-rb/config.rb', line 300

def self.default_user_keys_capacity
  1000
end

.default_user_keys_flush_intervalObject



304
305
306
# File 'lib/ldclient-rb/config.rb', line 304

def self.default_user_keys_flush_interval
  300
end

Instance Method Details

#offline?Boolean

TODO docs

Returns:

  • (Boolean)


131
132
133
# File 'lib/ldclient-rb/config.rb', line 131

def offline?
  @offline
end

#stream?Boolean

Whether streaming mode should be enabled. Streaming mode asynchronously updates feature flags in real-time using server-sent events.

Returns:

  • (Boolean)

    True if streaming mode should be enabled



116
117
118
# File 'lib/ldclient-rb/config.rb', line 116

def stream?
  @stream
end

#use_ldd?Boolean

Whether to use the LaunchDarkly relay proxy in daemon mode. In this mode, we do not use polling or streaming to get feature flag updates from the server, but instead read them from a Redis instance that is updated by the proxy.

Returns:

  • (Boolean)

    True if using the LaunchDarkly relay proxy in daemon mode



126
127
128
# File 'lib/ldclient-rb/config.rb', line 126

def use_ldd?
  @use_ldd
end