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.
-
#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.
-
#impressions_adapter ⇒ Object
readonly
The cache adapter to store impressions in.
-
#impressions_queue_size ⇒ Integer
readonly
Wow big the impressions queue is before dropping impressions.
-
#impressions_refresh_rate ⇒ Object
readonly
Returns the value of attribute impressions_refresh_rate.
-
#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.
-
#transport_debug_enabled ⇒ Boolean
readonly
Enable to log the content retrieved from endpoints.
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_uri ⇒ Object
- .default_features_refresh_rate ⇒ Object
- .default_impressions_queue_size ⇒ Object
- .default_impressions_refresh_rate ⇒ Object
-
.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
-
.get_hostname ⇒ string
gets the hostname where the sdk gem is running.
-
.get_ip ⇒ string
gets the ip where the sdk gem is running.
- .init_cache_adapter(adapter, data_structure, redis_url = nil, impressions_queue_size = nil) ⇒ Object
-
.sdk_version ⇒ string
method that returns the sdk gem version.
-
.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, exn) ⇒ 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
27 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 |
# File 'lib/splitclient-rb/split_config.rb', line 27 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] || 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 ) @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[:block_until_ready] || false @machine_name = SplitConfig.get_hostname @machine_ip = SplitConfig.get_ip startup_log end |
Instance Attribute Details
#base_uri ⇒ String (readonly)
The base URL for split API end points
66 67 68 |
# File 'lib/splitclient-rb/split_config.rb', line 66 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
132 133 134 |
# File 'lib/splitclient-rb/split_config.rb', line 132 def block_until_ready @block_until_ready end |
#cache_adapter ⇒ Object (readonly)
The cache adapter to store splits/segments in
89 90 91 |
# File 'lib/splitclient-rb/split_config.rb', line 89 def cache_adapter @cache_adapter end |
#connection_timeout ⇒ Int (readonly)
The connection timeout for network connections in seconds.
107 108 109 |
# File 'lib/splitclient-rb/split_config.rb', line 107 def connection_timeout @connection_timeout end |
#debug_enabled ⇒ Boolean (readonly)
The boolean that represents the state of the debug log level
120 121 122 |
# File 'lib/splitclient-rb/split_config.rb', line 120 def debug_enabled @debug_enabled end |
#events_uri ⇒ String (readonly)
The base URL for split events API end points
72 73 74 |
# File 'lib/splitclient-rb/split_config.rb', line 72 def events_uri @events_uri end |
#features_refresh_rate ⇒ Object (readonly)
Returns the value of attribute features_refresh_rate.
137 138 139 |
# File 'lib/splitclient-rb/split_config.rb', line 137 def features_refresh_rate @features_refresh_rate end |
#impressions_adapter ⇒ Object (readonly)
The cache adapter to store impressions in
95 96 97 |
# File 'lib/splitclient-rb/split_config.rb', line 95 def impressions_adapter @impressions_adapter end |
#impressions_queue_size ⇒ Integer (readonly)
Wow big the impressions queue is before dropping impressions. -1 to disable it.
146 147 148 |
# File 'lib/splitclient-rb/split_config.rb', line 146 def impressions_queue_size @impressions_queue_size end |
#impressions_refresh_rate ⇒ Object (readonly)
Returns the value of attribute impressions_refresh_rate.
140 141 142 |
# File 'lib/splitclient-rb/split_config.rb', line 140 def impressions_refresh_rate @impressions_refresh_rate end |
#logger ⇒ Logger (readonly)
The configured logger. The client library uses the log to print warning and error messages.
114 115 116 |
# File 'lib/splitclient-rb/split_config.rb', line 114 def logger @logger end |
#machine_ip ⇒ Object (readonly)
Returns the value of attribute machine_ip.
134 135 136 |
# File 'lib/splitclient-rb/split_config.rb', line 134 def machine_ip @machine_ip end |
#machine_name ⇒ Object (readonly)
Returns the value of attribute machine_name.
135 136 137 |
# File 'lib/splitclient-rb/split_config.rb', line 135 def machine_name @machine_name end |
#metrics_adapter ⇒ Symbol (readonly)
The cache adapter to store metrics in
101 102 103 |
# File 'lib/splitclient-rb/split_config.rb', line 101 def metrics_adapter @metrics_adapter end |
#metrics_refresh_rate ⇒ Object (readonly)
Returns the value of attribute metrics_refresh_rate.
139 140 141 |
# File 'lib/splitclient-rb/split_config.rb', line 139 def metrics_refresh_rate @metrics_refresh_rate end |
#mode ⇒ Symbol (readonly)
The mode SDK will run
78 79 80 |
# File 'lib/splitclient-rb/split_config.rb', line 78 def mode @mode end |
#read_timeout ⇒ Int (readonly)
The read timeout for network connections in seconds.
83 84 85 |
# File 'lib/splitclient-rb/split_config.rb', line 83 def read_timeout @read_timeout end |
#redis_namespace ⇒ Object (readonly)
Returns the value of attribute redis_namespace.
149 150 151 |
# File 'lib/splitclient-rb/split_config.rb', line 149 def redis_namespace @redis_namespace end |
#redis_url ⇒ Object (readonly)
Returns the value of attribute redis_url.
148 149 150 |
# File 'lib/splitclient-rb/split_config.rb', line 148 def redis_url @redis_url end |
#segments_refresh_rate ⇒ Object (readonly)
Returns the value of attribute segments_refresh_rate.
138 139 140 |
# File 'lib/splitclient-rb/split_config.rb', line 138 def segments_refresh_rate @segments_refresh_rate end |
#transport_debug_enabled ⇒ Boolean (readonly)
Enable to log the content retrieved from endpoints
126 127 128 |
# File 'lib/splitclient-rb/split_config.rb', line 126 def transport_debug_enabled @transport_debug_enabled end |
Class Method Details
.default ⇒ Config
The default split client configuration
155 156 157 |
# File 'lib/splitclient-rb/split_config.rb', line 155 def self.default SplitConfig.new end |
.default_base_uri ⇒ string
The default base uri for api calls
171 172 173 |
# File 'lib/splitclient-rb/split_config.rb', line 171 def self.default_base_uri 'https://sdk.split.io/api/' end |
.default_cache_adapter ⇒ LocalStore
Returns configuration value for local cache store.
204 205 206 |
# File 'lib/splitclient-rb/split_config.rb', line 204 def self.default_cache_adapter :memory end |
.default_connection_timeout ⇒ int
The default connection timeout value
224 225 226 |
# File 'lib/splitclient-rb/split_config.rb', line 224 def self.default_connection_timeout 5 end |
.default_debug ⇒ boolean
The default debug value
260 261 262 |
# File 'lib/splitclient-rb/split_config.rb', line 260 def self.default_debug false end |
.default_events_uri ⇒ Object
175 176 177 |
# File 'lib/splitclient-rb/split_config.rb', line 175 def self.default_events_uri 'https://events.split.io/api/' end |
.default_features_refresh_rate ⇒ Object
228 229 230 |
# File 'lib/splitclient-rb/split_config.rb', line 228 def self.default_features_refresh_rate 30 end |
.default_impressions_queue_size ⇒ Object
244 245 246 |
# File 'lib/splitclient-rb/split_config.rb', line 244 def self.default_impressions_queue_size 5000 end |
.default_impressions_refresh_rate ⇒ Object
240 241 242 |
# File 'lib/splitclient-rb/split_config.rb', line 240 def self.default_impressions_refresh_rate 60 end |
.default_logger ⇒ object
The default logger object
252 253 254 |
# File 'lib/splitclient-rb/split_config.rb', line 252 def self.default_logger Logger.new($stdout) end |
.default_metrics_adapter ⇒ Object
208 209 210 |
# File 'lib/splitclient-rb/split_config.rb', line 208 def self.default_metrics_adapter :memory end |
.default_metrics_refresh_rate ⇒ Object
236 237 238 |
# File 'lib/splitclient-rb/split_config.rb', line 236 def self.default_metrics_refresh_rate 60 end |
.default_mode ⇒ Object
199 200 201 |
# File 'lib/splitclient-rb/split_config.rb', line 199 def self.default_mode :standalone end |
.default_read_timeout ⇒ int
The default read timeout value
216 217 218 |
# File 'lib/splitclient-rb/split_config.rb', line 216 def self.default_read_timeout 5 end |
.default_redis_namespace ⇒ Object
268 269 270 |
# File 'lib/splitclient-rb/split_config.rb', line 268 def self.default_redis_namespace "SPLITIO/ruby-#{VERSION}" end |
.default_redis_url ⇒ Object
264 265 266 |
# File 'lib/splitclient-rb/split_config.rb', line 264 def self.default_redis_url 'redis://127.0.0.1:6379/0' end |
.default_segments_refresh_rate ⇒ Object
232 233 234 |
# File 'lib/splitclient-rb/split_config.rb', line 232 def self.default_segments_refresh_rate 60 end |
.get_hostname ⇒ string
gets the hostname where the sdk gem is running
305 306 307 308 309 310 311 312 |
# File 'lib/splitclient-rb/split_config.rb', line 305 def self.get_hostname begin Socket.gethostname rescue #unable to get hostname 'localhost' end end |
.get_ip ⇒ string
gets the ip where the sdk gem is running
318 319 320 321 322 323 324 325 |
# File 'lib/splitclient-rb/split_config.rb', line 318 def self.get_ip begin Socket::getaddrinfo(Socket.gethostname, 'echo', Socket::AF_INET)[0][3] rescue #unable to get local ip '127.0.0.0' end end |
.init_cache_adapter(adapter, data_structure, redis_url = nil, impressions_queue_size = nil) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/splitclient-rb/split_config.rb', line 179 def self.init_cache_adapter(adapter, data_structure, redis_url = nil, impressions_queue_size = nil) case adapter when :memory # takes :memory_adapter (symbol) and returns MemoryAdapter (string) adapter = SplitIoClient::Cache::Adapters::MemoryAdapters.const_get( data_structure.to_s.split('_').collect(&:capitalize).join ).new(impressions_queue_size) SplitIoClient::Cache::Adapters::MemoryAdapter.new(adapter) 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 |
.sdk_version ⇒ string
method that returns the sdk gem version
163 164 165 |
# File 'lib/splitclient-rb/split_config.rb', line 163 def self.sdk_version 'RubyClientSDK-'+SplitIoClient::VERSION end |
.transport_debug ⇒ boolean
The default transport_debug_enabled value
276 277 278 |
# File 'lib/splitclient-rb/split_config.rb', line 276 def self.transport_debug false end |
Instance Method Details
#log_found_exception(caller, exn) ⇒ void
This method returns an undefined value.
custom logger of exceptions
284 285 286 287 288 |
# File 'lib/splitclient-rb/split_config.rb', line 284 def log_found_exception(caller, exn) error_traceback = "#{exn.inspect} #{exn}\n\t#{exn.backtrace.join("\n\t")}" error = "[splitclient-rb] Unexpected exception in #{caller}: #{error_traceback}" @logger.error(error) end |
#startup_log ⇒ void
This method returns an undefined value.
log which cache class was loaded and SDK mode
294 295 296 297 298 299 |
# File 'lib/splitclient-rb/split_config.rb', line 294 def startup_log return if ENV['SPLITCLIENT_ENV'] == 'test' @logger.info("Loaded SDK in the #{@mode} mode") @logger.info("Loaded cache class: #{@cache_adapter.class}") end |