Class: LaunchDarkly::Config
- Inherits:
-
Object
- Object
- LaunchDarkly::Config
- 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
-
#all_attributes_private ⇒ Boolean
readonly
True if all user attributes (other than the key) should be considered private.
-
#base_uri ⇒ String
readonly
The base URL for the LaunchDarkly server.
-
#cache_store ⇒ Object
readonly
A store for HTTP caching.
-
#capacity ⇒ Integer
readonly
The capacity of the events buffer.
-
#connect_timeout ⇒ Float
readonly
The connect timeout for network connections in seconds.
-
#data_source ⇒ LaunchDarkly::Interfaces::DataSource|lambda
readonly
An object that is responsible for receiving feature flag data from LaunchDarkly.
-
#events_uri ⇒ String
readonly
The base URL for the LaunchDarkly events server.
-
#feature_store ⇒ LaunchDarkly::Interfaces::FeatureStore
readonly
A store for feature flags and related data.
-
#flush_interval ⇒ Float
readonly
The number of seconds between flushes of the event buffer.
-
#inline_users_in_events ⇒ Boolean
readonly
Whether to include full user details in every analytics event.
-
#logger ⇒ Logger
readonly
The configured logger for the LaunchDarkly client.
-
#poll_interval ⇒ Float
readonly
The number of seconds to wait before polling for feature flag updates.
-
#private_attribute_names ⇒ Array<String>
readonly
A list of user attribute names that should always be considered private.
-
#proxy ⇒ String
readonly
The proxy configuration string.
-
#read_timeout ⇒ Float
readonly
The read timeout for network connections in seconds.
-
#send_events ⇒ Boolean
readonly
Whether to send events back to LaunchDarkly.
-
#stream_uri ⇒ String
readonly
The base URL for the LaunchDarkly streaming server.
-
#update_processor ⇒ Object
readonly
deprecated
Deprecated.
This is replaced by #data_source.
-
#update_processor_factory ⇒ Object
readonly
deprecated
Deprecated.
This is replaced by #data_source.
-
#user_keys_capacity ⇒ Integer
readonly
The number of user keys that the event processor can remember at any one time.
-
#user_keys_flush_interval ⇒ Float
readonly
The interval in seconds at which the event processor will reset its set of known user keys.
Class Method Summary collapse
-
.default ⇒ Config
The default LaunchDarkly client configuration.
-
.default_base_uri ⇒ String
The default value for #base_uri.
-
.default_cache_store ⇒ Object
The default value for #cache_store.
-
.default_capacity ⇒ Integer
The default value for #capacity.
-
.default_connect_timeout ⇒ Float
The default value for #connect_timeout.
-
.default_events_uri ⇒ String
The default value for #events_uri.
-
.default_feature_store ⇒ LaunchDarkly::Interfaces::FeatureStore
The default value for #feature_store.
-
.default_flush_interval ⇒ Float
The default value for #flush_interval.
-
.default_logger ⇒ Logger
The default value for #logger.
-
.default_offline ⇒ Boolean
The default value for #offline?.
-
.default_poll_interval ⇒ Float
The default value for #poll_interval.
-
.default_proxy ⇒ String
The default value for #proxy.
-
.default_read_timeout ⇒ Float
The default value for #read_timeout.
-
.default_send_events ⇒ Boolean
The default value for #send_events.
-
.default_stream ⇒ Boolean
The default value for #stream?.
-
.default_stream_uri ⇒ String
The default value for #stream_uri.
-
.default_use_ldd ⇒ Boolean
The default value for #use_ldd?.
-
.default_user_keys_capacity ⇒ Integer
The default value for #user_keys_capacity.
-
.default_user_keys_flush_interval ⇒ Float
The default value for #user_keys_flush_interval.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Config
constructor
Constructor for creating custom LaunchDarkly configurations.
-
#offline? ⇒ Boolean
Whether the client should be initialized in offline mode.
-
#stream? ⇒ Boolean
Whether streaming mode should be enabled.
-
#use_ldd? ⇒ Boolean
Whether to use the LaunchDarkly relay proxy in daemon mode.
Constructor Details
#initialize(opts = {}) ⇒ Config
Constructor for creating custom LaunchDarkly configurations.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ldclient-rb/config.rb', line 41 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 @data_source = opts[:data_source] || opts[:update_processor] || opts[:update_processor_factory] @update_processor = opts[:update_processor] @update_processor_factory = opts[:update_processor_factory] end |
Instance Attribute Details
#all_attributes_private ⇒ Boolean (readonly)
True if all user attributes (other than the key) should be considered private. This means that the attribute values will not be sent to LaunchDarkly in analytics events and will not appear on the LaunchDarkly dashboard.
200 201 202 |
# File 'lib/ldclient-rb/config.rb', line 200 def all_attributes_private @all_attributes_private end |
#base_uri ⇒ String (readonly)
The base URL for the LaunchDarkly server. This is configurable mainly for testing purposes; most users should use the default value.
73 74 75 |
# File 'lib/ldclient-rb/config.rb', line 73 def base_uri @base_uri end |
#cache_store ⇒ Object (readonly)
A store for HTTP caching. This must support the semantics used by the
faraday-http-cache
gem. Defaults
to the Rails cache in a Rails environment, or a thread-safe in-memory store otherwise.
161 162 163 |
# File 'lib/ldclient-rb/config.rb', line 161 def cache_store @cache_store end |
#capacity ⇒ Integer (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.
153 154 155 |
# File 'lib/ldclient-rb/config.rb', line 153 def capacity @capacity end |
#connect_timeout ⇒ Float (readonly)
The connect timeout for network connections in seconds.
174 175 176 |
# File 'lib/ldclient-rb/config.rb', line 174 def connect_timeout @connect_timeout end |
#data_source ⇒ LaunchDarkly::Interfaces::DataSource|lambda (readonly)
An object that is responsible for receiving feature flag data from LaunchDarkly. By default, the client uses its standard polling or streaming implementation; this is customizable for testing purposes.
This may be set to either an object that conforms to Interfaces::DataSource, or a lambda (or Proc) that takes two parameters-- SDK key and LaunchDarkly::Config-- and returns such an object.
258 259 260 |
# File 'lib/ldclient-rb/config.rb', line 258 def data_source @data_source end |
#events_uri ⇒ String (readonly)
The base URL for the LaunchDarkly events server. This is configurable mainly for testing purposes; most users should use the default value.
87 88 89 |
# File 'lib/ldclient-rb/config.rb', line 87 def events_uri @events_uri end |
#feature_store ⇒ LaunchDarkly::Interfaces::FeatureStore (readonly)
A store for feature flags and related data. The client uses it to store all data received from LaunchDarkly, and uses the last stored data when evaluating flags. Defaults to InMemoryFeatureStore; for other implementations, see Integrations.
For more information, see "Using a persistent feature store".
185 186 187 |
# File 'lib/ldclient-rb/config.rb', line 185 def feature_store @feature_store end |
#flush_interval ⇒ Float (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.
128 129 130 |
# File 'lib/ldclient-rb/config.rb', line 128 def flush_interval @flush_interval end |
#inline_users_in_events ⇒ Boolean (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. The only reason to change this is if you are using the Analytics Data Stream.
244 245 246 |
# File 'lib/ldclient-rb/config.rb', line 244 def inline_users_in_events @inline_users_in_events end |
#logger ⇒ Logger (readonly)
The configured logger for the LaunchDarkly client. The client library uses the log to print warning and error messages. If not specified, this defaults to the Rails logger in a Rails environment, or stdout otherwise.
143 144 145 |
# File 'lib/ldclient-rb/config.rb', line 143 def logger @logger end |
#poll_interval ⇒ Float (readonly)
The number of seconds to wait before polling for feature flag updates. This option has no effect unless streaming is disabled.
135 136 137 |
# File 'lib/ldclient-rb/config.rb', line 135 def poll_interval @poll_interval end |
#private_attribute_names ⇒ Array<String> (readonly)
A list of user attribute names that should always be considered private. This means that the attribute values will not be sent to LaunchDarkly in analytics events and will not appear on the LaunchDarkly dashboard.
You can also specify the same behavior for an individual flag evaluation by storing an array
of attribute names in the :privateAttributeNames
property (note camelcase name) of the
user object.
214 215 216 |
# File 'lib/ldclient-rb/config.rb', line 214 def private_attribute_names @private_attribute_names end |
#proxy ⇒ String (readonly)
The proxy configuration string.
191 192 193 |
# File 'lib/ldclient-rb/config.rb', line 191 def proxy @proxy end |
#read_timeout ⇒ Float (readonly)
The read timeout for network connections in seconds. This does not apply to the streaming connection, which uses a longer timeout since the server does not send data constantly.
168 169 170 |
# File 'lib/ldclient-rb/config.rb', line 168 def read_timeout @read_timeout end |
#send_events ⇒ Boolean (readonly)
Whether 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.
221 222 223 |
# File 'lib/ldclient-rb/config.rb', line 221 def send_events @send_events end |
#stream_uri ⇒ String (readonly)
The base URL for the LaunchDarkly streaming server. This is configurable mainly for testing purposes; most users should use the default value.
80 81 82 |
# File 'lib/ldclient-rb/config.rb', line 80 def stream_uri @stream_uri end |
#update_processor ⇒ Object (readonly)
This is replaced by #data_source.
261 262 263 |
# File 'lib/ldclient-rb/config.rb', line 261 def update_processor @update_processor end |
#update_processor_factory ⇒ Object (readonly)
This is replaced by #data_source.
264 265 266 |
# File 'lib/ldclient-rb/config.rb', line 264 def update_processor_factory @update_processor_factory end |
#user_keys_capacity ⇒ Integer (readonly)
The number of user keys that the event processor can remember at any one time. This reduces the amount of duplicate user details sent in analytics events.
229 230 231 |
# File 'lib/ldclient-rb/config.rb', line 229 def user_keys_capacity @user_keys_capacity end |
#user_keys_flush_interval ⇒ Float (readonly)
The interval in seconds at which the event processor will reset its set of known user keys.
236 237 238 |
# File 'lib/ldclient-rb/config.rb', line 236 def user_keys_flush_interval @user_keys_flush_interval end |
Class Method Details
.default ⇒ Config
The default LaunchDarkly client configuration. This configuration sets reasonable defaults for most users.
271 272 273 |
# File 'lib/ldclient-rb/config.rb', line 271 def self.default Config.new end |
.default_base_uri ⇒ String
The default value for #base_uri.
287 288 289 |
# File 'lib/ldclient-rb/config.rb', line 287 def self.default_base_uri "https://app.launchdarkly.com" end |
.default_cache_store ⇒ Object
The default value for #cache_store.
311 312 313 |
# File 'lib/ldclient-rb/config.rb', line 311 def self.default_cache_store defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new end |
.default_capacity ⇒ Integer
The default value for #capacity.
279 280 281 |
# File 'lib/ldclient-rb/config.rb', line 279 def self.default_capacity 10000 end |
.default_connect_timeout ⇒ Float
The default value for #connect_timeout.
335 336 337 |
# File 'lib/ldclient-rb/config.rb', line 335 def self.default_connect_timeout 2 end |
.default_events_uri ⇒ String
The default value for #events_uri.
303 304 305 |
# File 'lib/ldclient-rb/config.rb', line 303 def self.default_events_uri "https://events.launchdarkly.com" end |
.default_feature_store ⇒ LaunchDarkly::Interfaces::FeatureStore
The default value for #feature_store.
381 382 383 |
# File 'lib/ldclient-rb/config.rb', line 381 def self.default_feature_store InMemoryFeatureStore.new end |
.default_flush_interval ⇒ Float
The default value for #flush_interval.
319 320 321 |
# File 'lib/ldclient-rb/config.rb', line 319 def self.default_flush_interval 10 end |
.default_logger ⇒ Logger
The default value for #logger.
351 352 353 354 355 356 357 358 359 |
# File 'lib/ldclient-rb/config.rb', line 351 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_offline ⇒ Boolean
The default value for #offline?.
389 390 391 |
# File 'lib/ldclient-rb/config.rb', line 389 def self.default_offline false end |
.default_poll_interval ⇒ Float
The default value for #poll_interval.
397 398 399 |
# File 'lib/ldclient-rb/config.rb', line 397 def self.default_poll_interval 30 end |
.default_proxy ⇒ String
The default value for #proxy.
343 344 345 |
# File 'lib/ldclient-rb/config.rb', line 343 def self.default_proxy nil end |
.default_read_timeout ⇒ Float
The default value for #read_timeout.
327 328 329 |
# File 'lib/ldclient-rb/config.rb', line 327 def self.default_read_timeout 10 end |
.default_send_events ⇒ Boolean
The default value for #send_events.
405 406 407 |
# File 'lib/ldclient-rb/config.rb', line 405 def self.default_send_events true end |
.default_stream ⇒ Boolean
The default value for #stream?.
365 366 367 |
# File 'lib/ldclient-rb/config.rb', line 365 def self.default_stream true end |
.default_stream_uri ⇒ String
The default value for #stream_uri.
295 296 297 |
# File 'lib/ldclient-rb/config.rb', line 295 def self.default_stream_uri "https://stream.launchdarkly.com" end |
.default_use_ldd ⇒ Boolean
The default value for #use_ldd?.
373 374 375 |
# File 'lib/ldclient-rb/config.rb', line 373 def self.default_use_ldd false end |
.default_user_keys_capacity ⇒ Integer
The default value for #user_keys_capacity.
413 414 415 |
# File 'lib/ldclient-rb/config.rb', line 413 def self.default_user_keys_capacity 1000 end |
.default_user_keys_flush_interval ⇒ Float
The default value for #user_keys_flush_interval.
421 422 423 |
# File 'lib/ldclient-rb/config.rb', line 421 def self.default_user_keys_flush_interval 300 end |
Instance Method Details
#offline? ⇒ Boolean
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.
119 120 121 |
# File 'lib/ldclient-rb/config.rb', line 119 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. Streaming is enabled by default, and should only be disabled on the advice of LaunchDarkly support.
95 96 97 |
# File 'lib/ldclient-rb/config.rb', line 95 def stream? @stream end |
#use_ldd? ⇒ Boolean
Whether to use the LaunchDarkly relay proxy in daemon mode. In this mode, the client does not use polling or streaming to get feature flag updates from the server, but instead reads them from the feature store, which is assumed to be a database that is populated by a LaunchDarkly relay proxy. For more information, see "The relay proxy" and "Using a persistent feature store".
All other properties related to streaming or polling are ignored if this option is set to true.
110 111 112 |
# File 'lib/ldclient-rb/config.rb', line 110 def use_ldd? @use_ldd end |