Class: SplitIoClient::SplitConfig
- Inherits:
-
Object
- Object
- SplitIoClient::SplitConfig
- 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
-
#base_uri ⇒ String
readonly
The base URL for split API end points.
-
#block_until_ready ⇒ Integer
readonly
The number of seconds to wait for SDK readiness or false to disable waiting.
-
#cache_adapter ⇒ Object
readonly
The cache adapter to store splits/segments in.
-
#connection_timeout ⇒ Int
readonly
The connection timeout for network connections in seconds.
-
#debug_enabled ⇒ Boolean
readonly
The boolean that represents the state of the debug log level.
-
#disable_impressions ⇒ Object
readonly
Returns the value of attribute disable_impressions.
-
#events_adapter ⇒ Object
readonly
The cache adapter to store events in.
-
#events_push_rate ⇒ Integer
readonly
The schedule time for events flush after the first one.
-
#events_queue_size ⇒ Integer
readonly
The max size of the events queue.
-
#events_uri ⇒ String
readonly
The base URL for split events API end points.
-
#features_refresh_rate ⇒ Object
readonly
Returns the value of attribute features_refresh_rate.
-
#impression_listener ⇒ Object
readonly
Returns the value of attribute impression_listener.
-
#impression_listener_refresh_rate ⇒ Object
readonly
Returns the value of attribute impression_listener_refresh_rate.
-
#impressions_adapter ⇒ Object
readonly
The cache adapter to store impressions in.
-
#impressions_bulk_size ⇒ Object
readonly
Returns the value of attribute impressions_bulk_size.
-
#impressions_queue_size ⇒ Integer
readonly
How big the impressions queue is before dropping impressions.
-
#impressions_refresh_rate ⇒ Object
readonly
Returns the value of attribute impressions_refresh_rate.
-
#labels_enabled ⇒ Boolean
readonly
Enable logging labels and sending potentially sensitive information.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#logger ⇒ Logger
readonly
The configured logger.
-
#machine_ip ⇒ Object
readonly
Returns the value of attribute machine_ip.
-
#machine_name ⇒ Object
readonly
Returns the value of attribute machine_name.
-
#metrics_adapter ⇒ Symbol
readonly
The cache adapter to store metrics in.
-
#metrics_refresh_rate ⇒ Object
readonly
Returns the value of attribute metrics_refresh_rate.
-
#mode ⇒ Symbol
readonly
The mode SDK will run.
-
#read_timeout ⇒ Int
readonly
The read timeout for network connections in seconds.
-
#redis_namespace ⇒ Object
readonly
Returns the value of attribute redis_namespace.
-
#redis_url ⇒ Object
readonly
Returns the value of attribute redis_url.
-
#segments_refresh_rate ⇒ Object
readonly
Returns the value of attribute segments_refresh_rate.
-
#threads ⇒ Object
Returns the value of attribute threads.
-
#transport_debug_enabled ⇒ Boolean
readonly
Enable to log the content retrieved from endpoints.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.default ⇒ Config
The default split client configuration.
-
.default_base_uri ⇒ string
The default base uri for api calls.
-
.default_cache_adapter ⇒ LocalStore
Configuration value for local cache store.
-
.default_connection_timeout ⇒ int
The default connection timeout value.
-
.default_debug ⇒ boolean
The default debug value.
- .default_events_push_rate ⇒ Object
- .default_events_queue_size ⇒ Object
- .default_events_uri ⇒ Object
- .default_features_refresh_rate ⇒ Object
- .default_impression_listener_refresh_rate ⇒ Object
- .default_impressions_queue_size ⇒ Object
- .default_impressions_refresh_rate ⇒ Object
-
.default_labels_logging ⇒ boolean
The default labels logging value.
-
.default_logger ⇒ object
The default logger object.
- .default_metrics_adapter ⇒ Object
- .default_metrics_refresh_rate ⇒ Object
- .default_mode ⇒ Object
-
.default_read_timeout ⇒ int
The default read timeout value.
- .default_redis_namespace ⇒ Object
- .default_redis_url ⇒ Object
- .default_segments_refresh_rate ⇒ Object
- .init_cache_adapter(adapter, data_structure, redis_url = nil, queue_size = nil) ⇒ Object
-
.machine_hostname ⇒ string
gets the hostname where the sdk gem is running.
-
.machine_ip ⇒ string
gets the ip where the sdk gem is running.
- .map_memory_adapter(name, queue_size) ⇒ Object
-
.transport_debug ⇒ boolean
The default transport_debug_enabled value.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ type
constructor
Constructor for creating custom split client config.
-
#log_found_exception(caller, error) ⇒ void
custom logger of exceptions.
-
#startup_log ⇒ void
log which cache class was loaded and SDK mode.
Constructor Details
#initialize(opts = {}) ⇒ type
Constructor for creating custom split client config
28 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 |
# File 'lib/splitclient-rb/split_config.rb', line 28 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]}.#{SplitConfig.default_redis_namespace}" : SplitConfig.default_redis_namespace @cache_adapter = SplitConfig.init_cache_adapter( opts[:cache_adapter] || SplitConfig.default_cache_adapter, :map_adapter, @redis_url, false ) @connection_timeout = opts[:connection_timeout] || SplitConfig.default_connection_timeout @read_timeout = opts[:read_timeout] || SplitConfig.default_read_timeout @features_refresh_rate = opts[:features_refresh_rate] || SplitConfig.default_features_refresh_rate @segments_refresh_rate = opts[:segments_refresh_rate] || SplitConfig.default_segments_refresh_rate @metrics_refresh_rate = opts[:metrics_refresh_rate] || SplitConfig.default_metrics_refresh_rate @impressions_refresh_rate = 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, @redis_url, @impressions_queue_size ) #Safeguard for users of older SDK versions. @disable_impressions = @impressions_queue_size == -1 #Safeguard for users of older SDK versions. @impressions_bulk_size = opts[:impressions_bulk_size] || @impressions_queue_size > 0 ? @impressions_queue_size : 0 @metrics_adapter = SplitConfig.init_cache_adapter( opts[:cache_adapter] || SplitConfig.default_cache_adapter, :map_adapter, @redis_url, false ) @logger = opts[:logger] || SplitConfig.default_logger @debug_enabled = opts[:debug_enabled] || SplitConfig.default_debug @transport_debug_enabled = opts[:transport_debug_enabled] || SplitConfig.default_debug @block_until_ready = opts[:ready] || opts[:block_until_ready] || 0 @machine_name = opts[:machine_name] || SplitConfig.machine_hostname @machine_ip = opts[:machine_ip] || SplitConfig.machine_ip @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 @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, @redis_url, @events_queue_size ) startup_log end |
Instance Attribute Details
#base_uri ⇒ String (readonly)
The base URL for split API end points
87 88 89 |
# File 'lib/splitclient-rb/split_config.rb', line 87 def base_uri @base_uri end |
#block_until_ready ⇒ Integer (readonly)
The number of seconds to wait for SDK readiness or false to disable waiting
165 166 167 |
# File 'lib/splitclient-rb/split_config.rb', line 165 def block_until_ready @block_until_ready end |
#cache_adapter ⇒ Object (readonly)
The cache adapter to store splits/segments in
110 111 112 |
# File 'lib/splitclient-rb/split_config.rb', line 110 def cache_adapter @cache_adapter end |
#connection_timeout ⇒ Int (readonly)
The connection timeout for network connections in seconds.
134 135 136 |
# File 'lib/splitclient-rb/split_config.rb', line 134 def connection_timeout @connection_timeout end |
#debug_enabled ⇒ Boolean (readonly)
The boolean that represents the state of the debug log level
147 148 149 |
# File 'lib/splitclient-rb/split_config.rb', line 147 def debug_enabled @debug_enabled end |
#disable_impressions ⇒ Object (readonly)
Returns the value of attribute disable_impressions.
187 188 189 |
# File 'lib/splitclient-rb/split_config.rb', line 187 def disable_impressions @disable_impressions end |
#events_adapter ⇒ Object (readonly)
The cache adapter to store events in
128 129 130 |
# File 'lib/splitclient-rb/split_config.rb', line 128 def events_adapter @events_adapter end |
#events_push_rate ⇒ Integer (readonly)
The schedule time for events flush after the first one
198 199 200 |
# File 'lib/splitclient-rb/split_config.rb', line 198 def events_push_rate @events_push_rate end |
#events_queue_size ⇒ Integer (readonly)
The max size of the events queue
204 205 206 |
# File 'lib/splitclient-rb/split_config.rb', line 204 def events_queue_size @events_queue_size end |
#events_uri ⇒ String (readonly)
The base URL for split events API end points
93 94 95 |
# File 'lib/splitclient-rb/split_config.rb', line 93 def events_uri @events_uri end |
#features_refresh_rate ⇒ Object (readonly)
Returns the value of attribute features_refresh_rate.
173 174 175 |
# File 'lib/splitclient-rb/split_config.rb', line 173 def features_refresh_rate @features_refresh_rate end |
#impression_listener ⇒ Object (readonly)
Returns the value of attribute impression_listener.
178 179 180 |
# File 'lib/splitclient-rb/split_config.rb', line 178 def impression_listener @impression_listener end |
#impression_listener_refresh_rate ⇒ Object (readonly)
Returns the value of attribute impression_listener_refresh_rate.
179 180 181 |
# File 'lib/splitclient-rb/split_config.rb', line 179 def impression_listener_refresh_rate @impression_listener_refresh_rate end |
#impressions_adapter ⇒ Object (readonly)
The cache adapter to store impressions in
116 117 118 |
# File 'lib/splitclient-rb/split_config.rb', line 116 def impressions_adapter @impressions_adapter end |
#impressions_bulk_size ⇒ Object (readonly)
Returns the value of attribute impressions_bulk_size.
186 187 188 |
# File 'lib/splitclient-rb/split_config.rb', line 186 def impressions_bulk_size @impressions_bulk_size end |
#impressions_queue_size ⇒ Integer (readonly)
How big the impressions queue is before dropping impressions. -1 to disable it.
185 186 187 |
# File 'lib/splitclient-rb/split_config.rb', line 185 def impressions_queue_size @impressions_queue_size end |
#impressions_refresh_rate ⇒ Object (readonly)
Returns the value of attribute impressions_refresh_rate.
176 177 178 |
# File 'lib/splitclient-rb/split_config.rb', line 176 def impressions_refresh_rate @impressions_refresh_rate end |
#labels_enabled ⇒ Boolean (readonly)
Enable logging labels and sending potentially sensitive information
159 160 161 |
# File 'lib/splitclient-rb/split_config.rb', line 159 def labels_enabled @labels_enabled end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
170 171 172 |
# File 'lib/splitclient-rb/split_config.rb', line 170 def language @language end |
#logger ⇒ Logger (readonly)
The configured logger. The client library uses the log to print warning and error messages.
141 142 143 |
# File 'lib/splitclient-rb/split_config.rb', line 141 def logger @logger end |
#machine_ip ⇒ Object (readonly)
Returns the value of attribute machine_ip.
167 168 169 |
# File 'lib/splitclient-rb/split_config.rb', line 167 def machine_ip @machine_ip end |
#machine_name ⇒ Object (readonly)
Returns the value of attribute machine_name.
168 169 170 |
# File 'lib/splitclient-rb/split_config.rb', line 168 def machine_name @machine_name end |
#metrics_adapter ⇒ Symbol (readonly)
The cache adapter to store metrics in
122 123 124 |
# File 'lib/splitclient-rb/split_config.rb', line 122 def metrics_adapter @metrics_adapter end |
#metrics_refresh_rate ⇒ Object (readonly)
Returns the value of attribute metrics_refresh_rate.
175 176 177 |
# File 'lib/splitclient-rb/split_config.rb', line 175 def metrics_refresh_rate @metrics_refresh_rate end |
#mode ⇒ Symbol (readonly)
The mode SDK will run
99 100 101 |
# File 'lib/splitclient-rb/split_config.rb', line 99 def mode @mode end |
#read_timeout ⇒ Int (readonly)
The read timeout for network connections in seconds.
104 105 106 |
# File 'lib/splitclient-rb/split_config.rb', line 104 def read_timeout @read_timeout end |
#redis_namespace ⇒ Object (readonly)
Returns the value of attribute redis_namespace.
190 191 192 |
# File 'lib/splitclient-rb/split_config.rb', line 190 def redis_namespace @redis_namespace end |
#redis_url ⇒ Object (readonly)
Returns the value of attribute redis_url.
189 190 191 |
# File 'lib/splitclient-rb/split_config.rb', line 189 def redis_url @redis_url end |
#segments_refresh_rate ⇒ Object (readonly)
Returns the value of attribute segments_refresh_rate.
174 175 176 |
# File 'lib/splitclient-rb/split_config.rb', line 174 def segments_refresh_rate @segments_refresh_rate end |
#threads ⇒ Object
Returns the value of attribute threads.
192 193 194 |
# File 'lib/splitclient-rb/split_config.rb', line 192 def threads @threads end |
#transport_debug_enabled ⇒ Boolean (readonly)
Enable to log the content retrieved from endpoints
153 154 155 |
# File 'lib/splitclient-rb/split_config.rb', line 153 def transport_debug_enabled @transport_debug_enabled end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
171 172 173 |
# File 'lib/splitclient-rb/split_config.rb', line 171 def version @version end |
Class Method Details
.default ⇒ Config
The default split client configuration
210 211 212 |
# File 'lib/splitclient-rb/split_config.rb', line 210 def self.default SplitConfig.new end |
.default_base_uri ⇒ string
The default base uri for api calls
218 219 220 |
# File 'lib/splitclient-rb/split_config.rb', line 218 def self.default_base_uri 'https://sdk.split.io/api/' end |
.default_cache_adapter ⇒ LocalStore
Returns configuration value for local cache store.
255 256 257 |
# File 'lib/splitclient-rb/split_config.rb', line 255 def self.default_cache_adapter :memory end |
.default_connection_timeout ⇒ int
The default connection timeout value
275 276 277 |
# File 'lib/splitclient-rb/split_config.rb', line 275 def self.default_connection_timeout 5 end |
.default_debug ⇒ boolean
The default debug value
323 324 325 |
# File 'lib/splitclient-rb/split_config.rb', line 323 def self.default_debug false end |
.default_events_push_rate ⇒ Object
303 304 305 |
# File 'lib/splitclient-rb/split_config.rb', line 303 def self.default_events_push_rate 60 end |
.default_events_queue_size ⇒ Object
307 308 309 |
# File 'lib/splitclient-rb/split_config.rb', line 307 def self.default_events_queue_size 500 end |
.default_events_uri ⇒ Object
222 223 224 |
# File 'lib/splitclient-rb/split_config.rb', line 222 def self.default_events_uri 'https://events.split.io/api/' end |
.default_features_refresh_rate ⇒ Object
279 280 281 |
# File 'lib/splitclient-rb/split_config.rb', line 279 def self.default_features_refresh_rate 30 end |
.default_impression_listener_refresh_rate ⇒ Object
295 296 297 |
# File 'lib/splitclient-rb/split_config.rb', line 295 def self.default_impression_listener_refresh_rate 0 end |
.default_impressions_queue_size ⇒ Object
299 300 301 |
# File 'lib/splitclient-rb/split_config.rb', line 299 def self.default_impressions_queue_size 5000 end |
.default_impressions_refresh_rate ⇒ Object
291 292 293 |
# File 'lib/splitclient-rb/split_config.rb', line 291 def self.default_impressions_refresh_rate 60 end |
.default_labels_logging ⇒ boolean
The default labels logging value
331 332 333 |
# File 'lib/splitclient-rb/split_config.rb', line 331 def self.default_labels_logging true end |
.default_logger ⇒ object
The default logger object
315 316 317 |
# File 'lib/splitclient-rb/split_config.rb', line 315 def self.default_logger (defined?(Rails) && Rails.logger) ? Rails.logger : Logger.new($stdout) end |
.default_metrics_adapter ⇒ Object
259 260 261 |
# File 'lib/splitclient-rb/split_config.rb', line 259 def self.default_metrics_adapter :memory end |
.default_metrics_refresh_rate ⇒ Object
287 288 289 |
# File 'lib/splitclient-rb/split_config.rb', line 287 def self.default_metrics_refresh_rate 60 end |
.default_mode ⇒ Object
250 251 252 |
# File 'lib/splitclient-rb/split_config.rb', line 250 def self.default_mode :standalone end |
.default_read_timeout ⇒ int
The default read timeout value
267 268 269 |
# File 'lib/splitclient-rb/split_config.rb', line 267 def self.default_read_timeout 5 end |
.default_redis_namespace ⇒ Object
339 340 341 |
# File 'lib/splitclient-rb/split_config.rb', line 339 def self.default_redis_namespace 'SPLITIO' end |
.default_redis_url ⇒ Object
335 336 337 |
# File 'lib/splitclient-rb/split_config.rb', line 335 def self.default_redis_url 'redis://127.0.0.1:6379/0' end |
.default_segments_refresh_rate ⇒ Object
283 284 285 |
# File 'lib/splitclient-rb/split_config.rb', line 283 def self.default_segments_refresh_rate 60 end |
.init_cache_adapter(adapter, data_structure, redis_url = nil, queue_size = nil) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/splitclient-rb/split_config.rb', line 226 def self.init_cache_adapter(adapter, data_structure, redis_url = nil, queue_size = 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 |
.machine_hostname ⇒ string
gets the hostname where the sdk gem is running
379 380 381 382 383 |
# File 'lib/splitclient-rb/split_config.rb', line 379 def self.machine_hostname Socket.gethostname rescue 'localhost'.freeze end |
.machine_ip ⇒ string
gets the ip where the sdk gem is running
389 390 391 392 393 394 395 396 |
# File 'lib/splitclient-rb/split_config.rb', line 389 def self.machine_ip 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 addr_info.ip_address end |
.map_memory_adapter(name, queue_size) ⇒ Object
241 242 243 244 245 246 247 248 |
# File 'lib/splitclient-rb/split_config.rb', line 241 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 |
.transport_debug ⇒ boolean
The default transport_debug_enabled value
347 348 349 |
# File 'lib/splitclient-rb/split_config.rb', line 347 def self.transport_debug false end |
Instance Method Details
#log_found_exception(caller, error) ⇒ void
This method returns an undefined value.
custom logger of exceptions
355 356 357 358 359 360 361 362 |
# File 'lib/splitclient-rb/split_config.rb', line 355 def log_found_exception(caller, error) = '' << "[splitclient-rb] Unexpected exception in #{caller}: #{error.inspect} #{error}" << "\n\t#{error.backtrace.join("\n\t")}" if @debug_enabled @logger.warn() end |
#startup_log ⇒ void
This method returns an undefined value.
log which cache class was loaded and SDK mode
368 369 370 371 372 373 |
# File 'lib/splitclient-rb/split_config.rb', line 368 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 |