Class: SplitIoClient::SplitConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/split_config.rb

Overview

This class manages configuration options for the split client library. If not custom configuration is required the default configuration values will be used

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ type

Constructor for creating custom split client config

Parameters:

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

    optional hash with configuration options

Options Hash (opts):

  • :base_uri (String) — default: "https://sdk.split.io/api/"

    The base URL for split API end points

  • :events_uri (String) — default: "https://events.split.io/api/"

    The events URL for events end points

  • :read_timeout (Int) — default: 10

    The read timeout for network connections in seconds.

  • :connection_timeout (Int) — default: 2

    The connect timeout for network connections in seconds.

  • :features_refresh_rate (Int)

    The SDK polls Split servers for changes to feature roll-out plans. This parameter controls this polling period in seconds.

  • :segments_refresh_rate (Int)
  • :impressions_refresh_rate (Int)
  • :logger (Object)

    a logger to user for messages from the client. Defaults to stdout

  • :debug_enabled (Boolean) — default: false

    The value for the debug flag

  • :impressions_queue_size (Int)

    Size of the impressions queue in the memory repository. Once reached, newer impressions will be dropped

  • :impressions_bulk_size (Int)

    Max number of impressions to be sent to the backend on each post

  • :impression_listener (#log)

    this object will capture all impressions and process them through ‘#log`

  • :cache_ttl (Int)

    Time to live in seconds for the memory cache values when using Redis.

  • :max_cache_size (Int)

    Max number of items to be held in the memory cache before prunning when using Redis.



29
30
31
32
33
34
35
36
37
38
39
40
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/splitclient-rb/split_config.rb', line 29

def initialize(opts = {})
  @base_uri = (opts[:base_uri] || SplitConfig.default_base_uri).chomp('/')
  @events_uri = (opts[:events_uri] || SplitConfig.default_events_uri).chomp('/')
  @mode = opts[:mode] || SplitConfig.default_mode
  @redis_url = opts[:redis_url] || SplitConfig.default_redis_url
  @redis_namespace = opts[:redis_namespace] && opts[:redis_namespace].to_s.length > 0 ? "#{opts[:redis_namespace]}.#{SplitConfig.default_redis_namespace}" : SplitConfig.default_redis_namespace
  @cache_adapter = SplitConfig.init_cache_adapter(
    opts[:cache_adapter] || SplitConfig.default_cache_adapter, :map_adapter, nil, @redis_url
  )
  @connection_timeout = opts[:connection_timeout] || SplitConfig.default_connection_timeout
  @read_timeout = opts[:read_timeout] || SplitConfig.default_read_timeout

  @logger = opts[:logger] || SplitConfig.default_logger

  if(opts[:reload_rate])
    @features_refresh_rate = opts[:reload_rate]
    @logger.warn('Localhost mode: reload_rate will be deprecated soon in favor of ' \
      'features_refresh_rate. Take a look in our documentation.'
    )
  else
    @features_refresh_rate = opts[:features_refresh_rate] || SplitConfig.default_features_refresh_rate
  end

  @segments_refresh_rate = opts[:segments_refresh_rate] || SplitConfig.default_segments_refresh_rate

  @impressions_mode = init_impressions_mode(opts[:impressions_mode], opts[:cache_adapter])

  @impressions_refresh_rate = SplitConfig.init_impressions_refresh_rate(@impressions_mode, opts[:impressions_refresh_rate], SplitConfig.default_impressions_refresh_rate)
  @impressions_queue_size = opts[:impressions_queue_size] || SplitConfig.default_impressions_queue_size
  @impressions_adapter = SplitConfig.init_cache_adapter(
    opts[:cache_adapter] || SplitConfig.default_cache_adapter, :queue_adapter, @impressions_queue_size, @redis_url
  )
  #Safeguard for users of older SDK versions.
  @impressions_bulk_size = opts[:impressions_bulk_size] || @impressions_queue_size > 0 ? @impressions_queue_size : 0

  @debug_enabled = opts[:debug_enabled] || SplitConfig.default_debug
  @transport_debug_enabled = opts[:transport_debug_enabled] || SplitConfig.default_debug
  @block_until_ready = SplitConfig.default_block_until_ready

  @ip_addresses_enabled = opts[:ip_addresses_enabled].nil? ? SplitConfig.default_ip_addresses_enabled : opts[:ip_addresses_enabled]

  @machine_name = SplitConfig.machine_hostname(@ip_addresses_enabled, opts[:machine_name], opts[:cache_adapter] || SplitConfig.default_cache_adapter)
  @machine_ip = SplitConfig.machine_ip(@ip_addresses_enabled, opts[:machine_ip], opts[:cache_adapter] || SplitConfig.default_cache_adapter)

  @cache_ttl = opts[:cache_ttl] || SplitConfig.cache_ttl
  @max_cache_size = opts[:max_cache_size] || SplitConfig.max_cache_size

  @language = opts[:language] || 'ruby'
  @version = opts[:version] || SplitIoClient::VERSION

  @labels_enabled = opts[:labels_enabled].nil? ? SplitConfig.default_labels_logging : opts[:labels_enabled]

  @impression_listener = opts[:impression_listener]
  @impression_listener_refresh_rate = opts[:impression_listener_refresh_rate] || SplitConfig.default_impression_listener_refresh_rate

  @max_key_size = SplitConfig.max_key_size

  @threads = {}

  @events_push_rate = opts[:events_push_rate] || SplitConfig.default_events_push_rate
  @events_queue_size = opts[:events_queue_size] || SplitConfig.default_events_queue_size
  @events_adapter = SplitConfig.init_cache_adapter(
    opts[:cache_adapter] || SplitConfig.default_cache_adapter, :queue_adapter, @events_queue_size, @redis_url
  )

  @telemetry_adapter = SplitConfig.init_telemetry_adapter(
    opts[:cache_adapter] || SplitConfig.default_cache_adapter, @redis_url
  )

  @split_file = opts[:split_file] || SplitConfig.default_split_file

  @valid_mode = true
  @split_logger = SplitIoClient::SplitLogger.new(self)
  @split_validator = SplitIoClient::Validators.new(self)
  @localhost_mode = opts[:localhost_mode]

  @streaming_enabled = consumer? ? false : (opts[:streaming_enabled].nil? ? SplitConfig.default_streaming_enabled : opts[:streaming_enabled])
  @streaming_service_url = opts[:streaming_service_url] || SplitConfig.default_streaming_service_url
  @auth_service_url = opts[:auth_service_url] || SplitConfig.default_auth_service_url
  @auth_retry_back_off_base = SplitConfig.init_auth_retry_back_off(opts[:auth_retry_back_off_base] || SplitConfig.default_auth_retry_back_off_base)
  @streaming_reconnect_back_off_base = SplitConfig.init_streaming_reconnect_back_off(opts[:streaming_reconnect_back_off_base] || SplitConfig.default_streaming_reconnect_back_off_base)

  @telemetry_refresh_rate = SplitConfig.init_telemetry_refresh_rate(opts[:telemetry_refresh_rate])
  @telemetry_service_url = opts[:telemetry_service_url] || SplitConfig.default_telemetry_service_url

  @unique_keys_refresh_rate = SplitConfig.default_unique_keys_refresh_rate(@cache_adapter)
  @unique_keys_cache_max_size = SplitConfig.default_unique_keys_cache_max_size
  @unique_keys_bulk_size = SplitConfig.default_unique_keys_bulk_size(@cache_adapter)

  @counter_refresh_rate = SplitConfig.default_counter_refresh_rate(@cache_adapter)

  @sdk_start_time = Time.now

  @on_demand_fetch_retry_delay_seconds = SplitConfig.default_on_demand_fetch_retry_delay_seconds
  @on_demand_fetch_max_retries = SplitConfig.default_on_demand_fetch_max_retries

  startup_log
end

Instance Attribute Details

#auth_retry_back_off_baseObject

Returns the value of attribute auth_retry_back_off_base.



272
273
274
# File 'lib/splitclient-rb/split_config.rb', line 272

def auth_retry_back_off_base
  @auth_retry_back_off_base
end

#auth_service_urlObject

Returns the value of attribute auth_service_url.



270
271
272
# File 'lib/splitclient-rb/split_config.rb', line 270

def auth_service_url
  @auth_service_url
end

#base_uriString

The base URL for split API end points

Returns:

  • (String)

    The configured base URL for the split API end points



132
133
134
# File 'lib/splitclient-rb/split_config.rb', line 132

def base_uri
  @base_uri
end

#block_until_readyInteger

The number of seconds to wait for SDK readiness or false to disable waiting

Returns:

  • (Integer)

    /[FalseClass]



218
219
220
# File 'lib/splitclient-rb/split_config.rb', line 218

def block_until_ready
  @block_until_ready
end

#cache_adapterObject

The cache adapter to store splits/segments in

Returns:

  • (Object)

    Cache adapter instance



155
156
157
# File 'lib/splitclient-rb/split_config.rb', line 155

def cache_adapter
  @cache_adapter
end

#cache_ttlObject

Returns the value of attribute cache_ttl.



223
224
225
# File 'lib/splitclient-rb/split_config.rb', line 223

def cache_ttl
  @cache_ttl
end

#connection_timeoutInt

The connection timeout for network connections in seconds.

Returns:

  • (Int)

    The connect timeout in seconds.



173
174
175
# File 'lib/splitclient-rb/split_config.rb', line 173

def connection_timeout
  @connection_timeout
end

#counter_refresh_rateObject

Returns the value of attribute counter_refresh_rate.



297
298
299
# File 'lib/splitclient-rb/split_config.rb', line 297

def counter_refresh_rate
  @counter_refresh_rate
end

#debug_enabledBoolean

The boolean that represents the state of the debug log level

Returns:

  • (Boolean)

    The value for the debug flag



200
201
202
# File 'lib/splitclient-rb/split_config.rb', line 200

def debug_enabled
  @debug_enabled
end

#events_adapterObject

The cache adapter to store events in

Returns:

  • (Object)

    Metrics adapter



167
168
169
# File 'lib/splitclient-rb/split_config.rb', line 167

def events_adapter
  @events_adapter
end

#events_push_rateInteger

The schedule time for events flush after the first one

Returns:

  • (Integer)


256
257
258
# File 'lib/splitclient-rb/split_config.rb', line 256

def events_push_rate
  @events_push_rate
end

#events_queue_sizeInteger

The max size of the events queue

Returns:

  • (Integer)


262
263
264
# File 'lib/splitclient-rb/split_config.rb', line 262

def events_queue_size
  @events_queue_size
end

#events_uriString

The base URL for split events API end points

Returns:

  • (String)

    The configured URL for the events API end points



138
139
140
# File 'lib/splitclient-rb/split_config.rb', line 138

def events_uri
  @events_uri
end

#features_refresh_rateObject

Returns the value of attribute features_refresh_rate.



231
232
233
# File 'lib/splitclient-rb/split_config.rb', line 231

def features_refresh_rate
  @features_refresh_rate
end

#impression_listenerObject

Returns the value of attribute impression_listener.



235
236
237
# File 'lib/splitclient-rb/split_config.rb', line 235

def impression_listener
  @impression_listener
end

#impression_listener_refresh_rateObject

Returns the value of attribute impression_listener_refresh_rate.



236
237
238
# File 'lib/splitclient-rb/split_config.rb', line 236

def impression_listener_refresh_rate
  @impression_listener_refresh_rate
end

#impressions_adapterObject

The cache adapter to store impressions in

Returns:

  • (Object)

    Impressions adapter instance



161
162
163
# File 'lib/splitclient-rb/split_config.rb', line 161

def impressions_adapter
  @impressions_adapter
end

#impressions_bulk_sizeObject

Returns the value of attribute impressions_bulk_size.



243
244
245
# File 'lib/splitclient-rb/split_config.rb', line 243

def impressions_bulk_size
  @impressions_bulk_size
end

#impressions_modeObject

Returns the value of attribute impressions_mode.



280
281
282
# File 'lib/splitclient-rb/split_config.rb', line 280

def impressions_mode
  @impressions_mode
end

#impressions_queue_sizeInteger

How big the impressions queue is before dropping impressions

Returns:

  • (Integer)


242
243
244
# File 'lib/splitclient-rb/split_config.rb', line 242

def impressions_queue_size
  @impressions_queue_size
end

#impressions_refresh_rateObject

Returns the value of attribute impressions_refresh_rate.



233
234
235
# File 'lib/splitclient-rb/split_config.rb', line 233

def impressions_refresh_rate
  @impressions_refresh_rate
end

#ip_addresses_enabledObject

Returns the value of attribute ip_addresses_enabled.



268
269
270
# File 'lib/splitclient-rb/split_config.rb', line 268

def ip_addresses_enabled
  @ip_addresses_enabled
end

#labels_enabledBoolean

Enable logging labels and sending potentially sensitive information

Returns:

  • (Boolean)

    The value for the labels enabled flag



212
213
214
# File 'lib/splitclient-rb/split_config.rb', line 212

def labels_enabled
  @labels_enabled
end

#languageObject

Returns the value of attribute language.



228
229
230
# File 'lib/splitclient-rb/split_config.rb', line 228

def language
  @language
end

#localhost_modeObject

Returns the value of attribute localhost_mode.



266
267
268
# File 'lib/splitclient-rb/split_config.rb', line 266

def localhost_mode
  @localhost_mode
end

#loggerLogger

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

Returns:

  • (Logger)

    The configured logger



180
181
182
# File 'lib/splitclient-rb/split_config.rb', line 180

def logger
  @logger
end

#machine_ipObject

Returns the value of attribute machine_ip.



220
221
222
# File 'lib/splitclient-rb/split_config.rb', line 220

def machine_ip
  @machine_ip
end

#machine_nameObject

Returns the value of attribute machine_name.



221
222
223
# File 'lib/splitclient-rb/split_config.rb', line 221

def machine_name
  @machine_name
end

#max_cache_sizeObject

Returns the value of attribute max_cache_size.



224
225
226
# File 'lib/splitclient-rb/split_config.rb', line 224

def max_cache_size
  @max_cache_size
end

#max_key_sizeObject

Returns the value of attribute max_key_size.



226
227
228
# File 'lib/splitclient-rb/split_config.rb', line 226

def max_key_size
  @max_key_size
end

#modeSymbol

The mode SDK will run

Returns:

  • (Symbol)

    One of the available SDK modes: standalone, consumer



144
145
146
# File 'lib/splitclient-rb/split_config.rb', line 144

def mode
  @mode
end

#on_demand_fetch_max_retriesObject

Returns the value of attribute on_demand_fetch_max_retries.



291
292
293
# File 'lib/splitclient-rb/split_config.rb', line 291

def on_demand_fetch_max_retries
  @on_demand_fetch_max_retries
end

#on_demand_fetch_retry_delay_secondsObject

Returns the value of attribute on_demand_fetch_retry_delay_seconds.



290
291
292
# File 'lib/splitclient-rb/split_config.rb', line 290

def on_demand_fetch_retry_delay_seconds
  @on_demand_fetch_retry_delay_seconds
end

#read_timeoutInt

The read timeout for network connections in seconds.

Returns:

  • (Int)

    The timeout in seconds.



149
150
151
# File 'lib/splitclient-rb/split_config.rb', line 149

def read_timeout
  @read_timeout
end

#redis_namespaceObject

Returns the value of attribute redis_namespace.



246
247
248
# File 'lib/splitclient-rb/split_config.rb', line 246

def redis_namespace
  @redis_namespace
end

#redis_urlObject

Returns the value of attribute redis_url.



245
246
247
# File 'lib/splitclient-rb/split_config.rb', line 245

def redis_url
  @redis_url
end

#sdk_start_timeObject

Returns the value of attribute sdk_start_time.



288
289
290
# File 'lib/splitclient-rb/split_config.rb', line 288

def sdk_start_time
  @sdk_start_time
end

#segments_refresh_rateObject

Returns the value of attribute segments_refresh_rate.



232
233
234
# File 'lib/splitclient-rb/split_config.rb', line 232

def segments_refresh_rate
  @segments_refresh_rate
end

#split_fileObject

Returns the value of attribute split_file.



264
265
266
# File 'lib/splitclient-rb/split_config.rb', line 264

def split_file
  @split_file
end

#split_loggerSplitLogger

The split logger. The client library uses the split logger to use common functions around the logger

Returns:



187
188
189
# File 'lib/splitclient-rb/split_config.rb', line 187

def split_logger
  @split_logger
end

#split_validatorSplitValidator

The split validator. The client library uses the split validator to validate inputs accross the sdk

Returns:

  • (SplitValidator)

    The validator



194
195
196
# File 'lib/splitclient-rb/split_config.rb', line 194

def split_validator
  @split_validator
end

#streaming_enabledObject

Returns the value of attribute streaming_enabled.



278
279
280
# File 'lib/splitclient-rb/split_config.rb', line 278

def streaming_enabled
  @streaming_enabled
end

#streaming_reconnect_back_off_baseObject

Returns the value of attribute streaming_reconnect_back_off_base.



276
277
278
# File 'lib/splitclient-rb/split_config.rb', line 276

def streaming_reconnect_back_off_base
  @streaming_reconnect_back_off_base
end

#streaming_service_urlObject

Returns the value of attribute streaming_service_url.



274
275
276
# File 'lib/splitclient-rb/split_config.rb', line 274

def streaming_service_url
  @streaming_service_url
end

#telemetry_adapterObject

Returns the value of attribute telemetry_adapter.



282
283
284
# File 'lib/splitclient-rb/split_config.rb', line 282

def telemetry_adapter
  @telemetry_adapter
end

#telemetry_refresh_rateObject

Returns the value of attribute telemetry_refresh_rate.



284
285
286
# File 'lib/splitclient-rb/split_config.rb', line 284

def telemetry_refresh_rate
  @telemetry_refresh_rate
end

#telemetry_service_urlObject

Returns the value of attribute telemetry_service_url.



286
287
288
# File 'lib/splitclient-rb/split_config.rb', line 286

def telemetry_service_url
  @telemetry_service_url
end

#threadsObject

Returns the value of attribute threads.



248
249
250
# File 'lib/splitclient-rb/split_config.rb', line 248

def threads
  @threads
end

#transport_debug_enabledBoolean

Enable to log the content retrieved from endpoints

Returns:

  • (Boolean)

    The value for the debug flag



206
207
208
# File 'lib/splitclient-rb/split_config.rb', line 206

def transport_debug_enabled
  @transport_debug_enabled
end

#unique_keys_bulk_sizeObject

Returns the value of attribute unique_keys_bulk_size.



295
296
297
# File 'lib/splitclient-rb/split_config.rb', line 295

def unique_keys_bulk_size
  @unique_keys_bulk_size
end

#unique_keys_cache_max_sizeObject

Returns the value of attribute unique_keys_cache_max_size.



294
295
296
# File 'lib/splitclient-rb/split_config.rb', line 294

def unique_keys_cache_max_size
  @unique_keys_cache_max_size
end

#unique_keys_refresh_rateObject

Returns the value of attribute unique_keys_refresh_rate.



293
294
295
# File 'lib/splitclient-rb/split_config.rb', line 293

def unique_keys_refresh_rate
  @unique_keys_refresh_rate
end

#valid_modeObject

Returns the value of attribute valid_mode.



250
251
252
# File 'lib/splitclient-rb/split_config.rb', line 250

def valid_mode
  @valid_mode
end

#versionObject

Returns the value of attribute version.



229
230
231
# File 'lib/splitclient-rb/split_config.rb', line 229

def version
  @version
end

Class Method Details

.cache_ttlint

The default cache time to live

Returns:

  • (int)


587
588
589
# File 'lib/splitclient-rb/split_config.rb', line 587

def self.cache_ttl
  5
end

.defaultConfig

The default split client configuration

Returns:

  • (Config)

    The default split client configuration.



377
378
379
# File 'lib/splitclient-rb/split_config.rb', line 377

def self.default
  SplitConfig.new
end

.default_auth_retry_back_off_baseObject



357
358
359
# File 'lib/splitclient-rb/split_config.rb', line 357

def self.default_auth_retry_back_off_base
  1
end

.default_auth_service_urlObject



353
354
355
# File 'lib/splitclient-rb/split_config.rb', line 353

def self.default_auth_service_url
  'https://auth.split.io/api/v2/auth'
end

.default_base_uristring

The default base uri for api calls

Returns:

  • (string)

    The default base uri



385
386
387
# File 'lib/splitclient-rb/split_config.rb', line 385

def self.default_base_uri
  'https://sdk.split.io/api/'
end

.default_block_until_readyint

The default block until ready value

Returns:

  • (int)


563
564
565
# File 'lib/splitclient-rb/split_config.rb', line 563

def self.default_block_until_ready
  15
end

.default_cache_adapterLocalStore

Returns configuration value for local cache store.

Returns:

  • (LocalStore)

    configuration value for local cache store



437
438
439
# File 'lib/splitclient-rb/split_config.rb', line 437

def self.default_cache_adapter
  :memory
end

.default_connection_timeoutint

The default connection timeout value

Returns:

  • (int)


453
454
455
# File 'lib/splitclient-rb/split_config.rb', line 453

def self.default_connection_timeout
  5
end

.default_counter_refresh_rate(adapter) ⇒ Object



299
300
301
302
303
# File 'lib/splitclient-rb/split_config.rb', line 299

def self.default_counter_refresh_rate(adapter)
  return 300 if adapter == :redis # Send bulk impressions count - Refresh rate: 5 min.

  1800 # Send bulk impressions count - Refresh rate: 30 min.
end

.default_debugboolean

The default debug value

Returns:

  • (boolean)


539
540
541
# File 'lib/splitclient-rb/split_config.rb', line 539

def self.default_debug
  false
end

.default_events_push_rateObject



481
482
483
# File 'lib/splitclient-rb/split_config.rb', line 481

def self.default_events_push_rate
  60
end

.default_events_queue_sizeObject



485
486
487
# File 'lib/splitclient-rb/split_config.rb', line 485

def self.default_events_queue_size
  500
end

.default_events_uriObject



389
390
391
# File 'lib/splitclient-rb/split_config.rb', line 389

def self.default_events_uri
  'https://events.split.io/api/'
end

.default_features_refresh_rateObject



457
458
459
# File 'lib/splitclient-rb/split_config.rb', line 457

def self.default_features_refresh_rate
  5
end

.default_impression_listener_refresh_rateObject



473
474
475
# File 'lib/splitclient-rb/split_config.rb', line 473

def self.default_impression_listener_refresh_rate
  0
end

.default_impressions_modeObject



313
314
315
# File 'lib/splitclient-rb/split_config.rb', line 313

def self.default_impressions_mode
  :optimized
end

.default_impressions_queue_sizeObject



477
478
479
# File 'lib/splitclient-rb/split_config.rb', line 477

def self.default_impressions_queue_size
  5000
end

.default_impressions_refresh_rateObject



465
466
467
# File 'lib/splitclient-rb/split_config.rb', line 465

def self.default_impressions_refresh_rate
  60
end

.default_impressions_refresh_rate_optimizedObject



469
470
471
# File 'lib/splitclient-rb/split_config.rb', line 469

def self.default_impressions_refresh_rate_optimized
  300
end

.default_ip_addresses_enabledboolean

The default ip addresses enabled value

Returns:

  • (boolean)


571
572
573
# File 'lib/splitclient-rb/split_config.rb', line 571

def self.default_ip_addresses_enabled
  true
end

.default_labels_loggingboolean

The default labels logging value

Returns:

  • (boolean)


547
548
549
# File 'lib/splitclient-rb/split_config.rb', line 547

def self.default_labels_logging
  true
end

.default_loggerobject

The default logger object

Returns:

  • (object)


525
526
527
528
529
530
531
532
533
# File 'lib/splitclient-rb/split_config.rb', line 525

def self.default_logger
  if defined?(Rails) && Rails.logger
    Rails.logger
  elsif ENV['SPLITCLIENT_ENV'] == 'test'
    Logger.new('/dev/null')
  else
   Logger.new($stdout)
   end
end

.default_modeObject



432
433
434
# File 'lib/splitclient-rb/split_config.rb', line 432

def self.default_mode
  :standalone
end

.default_offline_refresh_rateObject



517
518
519
# File 'lib/splitclient-rb/split_config.rb', line 517

def self.default_offline_refresh_rate
  5
end

.default_on_demand_fetch_max_retriesObject



309
310
311
# File 'lib/splitclient-rb/split_config.rb', line 309

def self.default_on_demand_fetch_max_retries
  10
end

.default_on_demand_fetch_retry_delay_secondsObject



305
306
307
# File 'lib/splitclient-rb/split_config.rb', line 305

def self.default_on_demand_fetch_retry_delay_seconds
  0.05
end

.default_read_timeoutint

The default read timeout value

Returns:

  • (int)


445
446
447
# File 'lib/splitclient-rb/split_config.rb', line 445

def self.default_read_timeout
  5
end

.default_redis_namespaceObject



555
556
557
# File 'lib/splitclient-rb/split_config.rb', line 555

def self.default_redis_namespace
  'SPLITIO'
end

.default_redis_urlObject



551
552
553
# File 'lib/splitclient-rb/split_config.rb', line 551

def self.default_redis_url
  'redis://127.0.0.1:6379/0'
end

.default_segments_refresh_rateObject



461
462
463
# File 'lib/splitclient-rb/split_config.rb', line 461

def self.default_segments_refresh_rate
  60
end

.default_split_fileObject



513
514
515
# File 'lib/splitclient-rb/split_config.rb', line 513

def self.default_split_file
  File.join(Dir.home, '.split')
end

.default_streaming_enabledObject



345
346
347
# File 'lib/splitclient-rb/split_config.rb', line 345

def self.default_streaming_enabled
  true
end

.default_streaming_reconnect_back_off_baseObject



361
362
363
# File 'lib/splitclient-rb/split_config.rb', line 361

def self.default_streaming_reconnect_back_off_base
  1
end

.default_streaming_service_urlObject



349
350
351
# File 'lib/splitclient-rb/split_config.rb', line 349

def self.default_streaming_service_url
  'https://streaming.split.io/event-stream'
end

.default_telemetry_refresh_rateObject



489
490
491
# File 'lib/splitclient-rb/split_config.rb', line 489

def self.default_telemetry_refresh_rate
  3600      
end

.default_telemetry_service_urlObject



509
510
511
# File 'lib/splitclient-rb/split_config.rb', line 509

def self.default_telemetry_service_url
  'https://telemetry.split.io/api/v1'
end

.default_unique_keys_bulk_size(adapter) ⇒ Object



503
504
505
506
507
# File 'lib/splitclient-rb/split_config.rb', line 503

def self.default_unique_keys_bulk_size(adapter)
  return 2000 if adapter == :redis

  5000
end

.default_unique_keys_cache_max_sizeObject



499
500
501
# File 'lib/splitclient-rb/split_config.rb', line 499

def self.default_unique_keys_cache_max_size
  30000
end

.default_unique_keys_refresh_rate(adapter) ⇒ Object



493
494
495
496
497
# File 'lib/splitclient-rb/split_config.rb', line 493

def self.default_unique_keys_refresh_rate(adapter)
  return 300 if adapter == :redis

  900
end

.init_auth_retry_back_off(auth_retry_back_off) ⇒ Object



365
366
367
# File 'lib/splitclient-rb/split_config.rb', line 365

def self.init_auth_retry_back_off(auth_retry_back_off)
  auth_retry_back_off < 1 ? SplitConfig.default_auth_retry_back_off_base : auth_retry_back_off
end

.init_cache_adapter(adapter, data_structure, queue_size = nil, redis_url = nil) ⇒ Object



393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/splitclient-rb/split_config.rb', line 393

def self.init_cache_adapter(adapter, data_structure, queue_size = nil, redis_url = nil)
  case adapter
  when :memory
    SplitIoClient::Cache::Adapters::MemoryAdapter.new(map_memory_adapter(data_structure, queue_size))
  when :redis
    begin
      require 'redis'
    rescue LoadError
      fail StandardError, 'To use Redis as a cache adapter you must include it in your Gemfile'
    end

    SplitIoClient::Cache::Adapters::RedisAdapter.new(redis_url)
  end
end

.init_impressions_refresh_rate(impressions_mode, refresh_rate, default_rate) ⇒ Object



333
334
335
336
337
# File 'lib/splitclient-rb/split_config.rb', line 333

def self.init_impressions_refresh_rate(impressions_mode, refresh_rate, default_rate)      
  return (refresh_rate.nil? || refresh_rate <= 0 ? default_rate : refresh_rate) if impressions_mode == :debug
  
  return refresh_rate.nil? || refresh_rate <= 0 ? SplitConfig.default_impressions_refresh_rate_optimized : [default_rate, refresh_rate].max
end

.init_streaming_reconnect_back_off(streaming_reconnect_back_off) ⇒ Object



369
370
371
# File 'lib/splitclient-rb/split_config.rb', line 369

def self.init_streaming_reconnect_back_off(streaming_reconnect_back_off)
  streaming_reconnect_back_off < 1 ? SplitConfig.default_streaming_reconnect_back_off_base : streaming_reconnect_back_off
end

.init_telemetry_adapter(adapter, redis_url) ⇒ Object



408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/splitclient-rb/split_config.rb', line 408

def self.init_telemetry_adapter(adapter, redis_url)
  case adapter
  when :memory
    Telemetry::Storages::Memory.new
  when :redis
    begin
      require 'redis'
    rescue LoadError
      fail StandardError, 'To use Redis as a cache adapter you must include it in your Gemfile'
    end

    SplitIoClient::Cache::Adapters::RedisAdapter.new(redis_url)
  end
end

.init_telemetry_refresh_rate(refresh_rate) ⇒ Object



339
340
341
342
343
# File 'lib/splitclient-rb/split_config.rb', line 339

def self.init_telemetry_refresh_rate(refresh_rate)
  return SplitConfig.default_telemetry_refresh_rate if refresh_rate.nil? || refresh_rate < 60

  refresh_rate
end

.machine_hostname(ip_addresses_enabled, machine_name, adapter) ⇒ string

gets the hostname where the sdk gem is running

Returns:

  • (string)


641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# File 'lib/splitclient-rb/split_config.rb', line 641

def self.machine_hostname(ip_addresses_enabled, machine_name, adapter)
  if ip_addresses_enabled
    begin
      return machine_name || Socket.gethostname
    rescue
      return 'unknown'.freeze
    end
  else
    case adapter
    when :redis
      return 'NA'.freeze
    end
  end
  
  return ''.freeze
end

.machine_ip(ip_addresses_enabled, ip, adapter) ⇒ string

gets the ip where the sdk gem is running

Returns:

  • (string)


662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
# File 'lib/splitclient-rb/split_config.rb', line 662

def self.machine_ip(ip_addresses_enabled, ip, adapter)
  if ip_addresses_enabled
    begin          
      return ip unless ip.nil? || ip.to_s.empty?

      loopback_ip = Socket.ip_address_list.find { |ip| ip.ipv4_loopback? }
      private_ip = Socket.ip_address_list.find { |ip| ip.ipv4_private? }

      addr_info = private_ip || loopback_ip

      return addr_info.ip_address
    rescue
      return 'unknown'.freeze
    end
  else
    case adapter
    when :redis
      return 'NA'.freeze
    end
  end

  return ''.freeze
end

.map_memory_adapter(name, queue_size) ⇒ Object



423
424
425
426
427
428
429
430
# File 'lib/splitclient-rb/split_config.rb', line 423

def self.map_memory_adapter(name, queue_size)
  case name
  when :map_adapter
    SplitIoClient::Cache::Adapters::MemoryAdapters::MapAdapter.new
  when :queue_adapter
    SplitIoClient::Cache::Adapters::MemoryAdapters::QueueAdapter.new(queue_size)
  end
end

.max_cache_sizeint

The default max cache size

Returns:

  • (int)


594
595
596
# File 'lib/splitclient-rb/split_config.rb', line 594

def self.max_cache_size
  500
end

.max_key_sizeint

The default max key size

Returns:

  • (int)


601
602
603
# File 'lib/splitclient-rb/split_config.rb', line 601

def self.max_key_size
  250
end

.transport_debugboolean

The default transport_debug_enabled value

Returns:

  • (boolean)


579
580
581
# File 'lib/splitclient-rb/split_config.rb', line 579

def self.transport_debug
  false
end

Instance Method Details

#consumer?Boolean

Returns:

  • (Boolean)


633
634
635
# File 'lib/splitclient-rb/split_config.rb', line 633

def consumer?
  @mode.equal?(:consumer)
end

#init_impressions_mode(impressions_mode, adapter) ⇒ Object



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/splitclient-rb/split_config.rb', line 317

def init_impressions_mode(impressions_mode, adapter)
  impressions_mode ||= SplitConfig.default_impressions_mode

  return :debug if adapter == :redis

  case impressions_mode
  when :debug
    return :debug
  # when :none  // we not support :none impression mode yet. Defaulting to :optimized mode
  #  return :none
  else
    @logger.error('You passed an invalid impressions_mode, impressions_mode should be one of the following values: :debug or :optimized. Defaulting to :optimized mode') unless impressions_mode == :optimized
    return :optimized
  end
end

#log_found_exception(caller, error) ⇒ void

This method returns an undefined value.

custom logger of exceptions



609
610
611
612
613
614
615
616
# File 'lib/splitclient-rb/split_config.rb', line 609

def log_found_exception(caller, error)
  message = ''

  message << "[splitclient-rb] Unexpected exception in #{caller}: #{error.inspect} #{error}"
  message << "\n\t#{error.backtrace.join("\n\t")}" if @debug_enabled

  @logger.warn(message)
end

#standalone?Boolean

Returns:

  • (Boolean)


629
630
631
# File 'lib/splitclient-rb/split_config.rb', line 629

def standalone?
  @mode.equal?(:standalone)
end

#startup_logvoid

This method returns an undefined value.

log which cache class was loaded and SDK mode



622
623
624
625
626
627
# File 'lib/splitclient-rb/split_config.rb', line 622

def startup_log
  return if ENV['SPLITCLIENT_ENV'] == 'test'

  @logger.info("Loaded Ruby SDK v#{VERSION} in the #{@mode} mode")
  @logger.info("Loaded cache class: #{@cache_adapter.class}")
end