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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ type

Constructor for creating custom LaunchDarkly configurations.

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.

  • :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.

  • :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.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ldclient-rb/config.rb', line 24

def initialize(opts = {})
  @base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
  @stream_uri = (opts[:stream_uri] || Config.default_stream_uri).chomp("/")
  @capacity = opts[:capacity] || Config.default_capacity
  @logger = opts[:logger] || Config.default_logger
  @store = opts[:store] || Config.default_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
  @log_timings = opts[:log_timings] || Config.default_log_timings
  @stream = opts[:stream] || Config.default_stream
  @feature_store = opts[:feature_store] || Config.default_feature_store
  @debug_stream = opts[:debug_stream] || Config.default_debug_stream
end

Class Method Details

.defaultConfig

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

Returns:

  • (Config)

    The default LaunchDarkly configuration.



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

def self.default
  Config.new()
end

.default_base_uriObject



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

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

.default_capacityObject



148
149
150
# File 'lib/ldclient-rb/config.rb', line 148

def self.default_capacity
  10000
end

.default_connect_timeoutObject



172
173
174
# File 'lib/ldclient-rb/config.rb', line 172

def self.default_connect_timeout
  2
end

.default_debug_streamObject



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

def self.default_debug_stream
  false
end

.default_feature_storeObject



188
189
190
# File 'lib/ldclient-rb/config.rb', line 188

def self.default_feature_store
  nil
end

.default_flush_intervalObject



164
165
166
# File 'lib/ldclient-rb/config.rb', line 164

def self.default_flush_interval
  10
end

.default_log_timingsObject



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

def self.default_log_timings
  false
end

.default_loggerObject



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

def self.default_logger
  defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new($stdout)
end

.default_read_timeoutObject



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

def self.default_read_timeout
  10
end

.default_storeObject



160
161
162
# File 'lib/ldclient-rb/config.rb', line 160

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

.default_streamObject



184
185
186
# File 'lib/ldclient-rb/config.rb', line 184

def self.default_stream
  true
end

.default_stream_uriObject



156
157
158
# File 'lib/ldclient-rb/config.rb', line 156

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

Instance Method Details

#base_uriString

The base URL for the LaunchDarkly server.

Returns:

  • (String)

    The configured base URL for the LaunchDarkly server.



43
44
45
# File 'lib/ldclient-rb/config.rb', line 43

def base_uri
  @base_uri
end

#capacityInteger

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



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

def capacity
  @capacity
end

#connect_timeoutFloat

The connect timeout for network connections in seconds.

Returns:

  • (Float)

    The connect timeout in seconds.



120
121
122
# File 'lib/ldclient-rb/config.rb', line 120

def connect_timeout
  @connect_timeout
end

#debug_stream?Boolean

Whether we should debug streaming mode. If set, the client will fetch features via polling and compare the retrieved feature with the value in the feature store

Returns:

  • (Boolean)

    True if we should debug streaming mode



69
70
71
# File 'lib/ldclient-rb/config.rb', line 69

def debug_stream?
  @debug_stream
end

#feature_storeObject

TODO docs



136
137
138
# File 'lib/ldclient-rb/config.rb', line 136

def feature_store
  @feature_store
end

#flush_intervalFloat

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.



78
79
80
# File 'lib/ldclient-rb/config.rb', line 78

def flush_interval
  @flush_interval
end

#log_timings?Boolean

Whether timing information should be logged. If it is logged, it will be logged to the DEBUG level on the configured logger. This can be very verbose.

Returns:

  • (Boolean)

    True if timing information should be logged.



129
130
131
# File 'lib/ldclient-rb/config.rb', line 129

def log_timings?
  @log_timings
end

#loggerLogger

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

Returns:

  • (Logger)

    The configured logger



87
88
89
# File 'lib/ldclient-rb/config.rb', line 87

def logger
  @logger
end

#read_timeoutFloat

The read timeout for network connections in seconds.

Returns:

  • (Float)

    The read timeout in seconds.



112
113
114
# File 'lib/ldclient-rb/config.rb', line 112

def read_timeout
  @read_timeout
end

#storeObject

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.



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

def store
  @store
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



60
61
62
# File 'lib/ldclient-rb/config.rb', line 60

def stream?
  @stream
end

#stream_uriString

The base URL for the LaunchDarkly streaming server.

Returns:

  • (String)

    The configured base URL for the LaunchDarkly streaming server.



51
52
53
# File 'lib/ldclient-rb/config.rb', line 51

def stream_uri
  @stream_uri
end