splitclient-rb 6.4.1.pre.rc3-java → 7.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.txt +15 -1
  3. data/Detailed-README.md +9 -21
  4. data/NEWS +3 -0
  5. data/lib/splitclient-rb.rb +2 -1
  6. data/lib/splitclient-rb/cache/adapters/cache_adapter.rb +3 -3
  7. data/lib/splitclient-rb/cache/repositories/events/memory_repository.rb +5 -4
  8. data/lib/splitclient-rb/cache/repositories/events/redis_repository.rb +4 -3
  9. data/lib/splitclient-rb/cache/repositories/events_repository.rb +10 -9
  10. data/lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb +7 -6
  11. data/lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb +5 -4
  12. data/lib/splitclient-rb/cache/repositories/impressions_repository.rb +9 -8
  13. data/lib/splitclient-rb/cache/repositories/metrics/memory_repository.rb +3 -2
  14. data/lib/splitclient-rb/cache/repositories/metrics/redis_repository.rb +5 -4
  15. data/lib/splitclient-rb/cache/repositories/metrics_repository.rb +6 -4
  16. data/lib/splitclient-rb/cache/repositories/repository.rb +7 -2
  17. data/lib/splitclient-rb/cache/repositories/segments_repository.rb +6 -5
  18. data/lib/splitclient-rb/cache/repositories/splits_repository.rb +56 -14
  19. data/lib/splitclient-rb/cache/routers/impression_router.rb +5 -4
  20. data/lib/splitclient-rb/cache/senders/events_sender.rb +7 -6
  21. data/lib/splitclient-rb/cache/senders/impressions_sender.rb +10 -9
  22. data/lib/splitclient-rb/cache/senders/metrics_sender.rb +9 -8
  23. data/lib/splitclient-rb/cache/stores/sdk_blocker.rb +19 -10
  24. data/lib/splitclient-rb/cache/stores/segment_store.rb +15 -28
  25. data/lib/splitclient-rb/cache/stores/split_store.rb +13 -15
  26. data/lib/splitclient-rb/clients/localhost_split_client.rb +8 -7
  27. data/lib/splitclient-rb/clients/split_client.rb +65 -35
  28. data/lib/splitclient-rb/engine/api/client.rb +17 -13
  29. data/lib/splitclient-rb/engine/api/events.rb +7 -6
  30. data/lib/splitclient-rb/engine/api/impressions.rb +6 -5
  31. data/lib/splitclient-rb/engine/api/metrics.rb +8 -7
  32. data/lib/splitclient-rb/engine/api/segments.rb +11 -10
  33. data/lib/splitclient-rb/engine/api/splits.rb +6 -5
  34. data/lib/splitclient-rb/engine/matchers/all_keys_matcher.rb +1 -1
  35. data/lib/splitclient-rb/engine/matchers/between_matcher.rb +7 -5
  36. data/lib/splitclient-rb/engine/matchers/combining_matcher.rb +5 -4
  37. data/lib/splitclient-rb/engine/matchers/contains_all_matcher.rb +4 -4
  38. data/lib/splitclient-rb/engine/matchers/contains_any_matcher.rb +3 -3
  39. data/lib/splitclient-rb/engine/matchers/contains_matcher.rb +7 -5
  40. data/lib/splitclient-rb/engine/matchers/dependency_matcher.rb +3 -2
  41. data/lib/splitclient-rb/engine/matchers/ends_with_matcher.rb +5 -4
  42. data/lib/splitclient-rb/engine/matchers/equal_to_boolean_matcher.rb +3 -2
  43. data/lib/splitclient-rb/engine/matchers/equal_to_matcher.rb +6 -4
  44. data/lib/splitclient-rb/engine/matchers/equal_to_set_matcher.rb +3 -3
  45. data/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_matcher.rb +6 -4
  46. data/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb +6 -4
  47. data/lib/splitclient-rb/engine/matchers/matcher.rb +4 -0
  48. data/lib/splitclient-rb/engine/matchers/matches_string_matcher.rb +3 -2
  49. data/lib/splitclient-rb/engine/matchers/negation_matcher.rb +3 -2
  50. data/lib/splitclient-rb/engine/matchers/part_of_set_matcher.rb +4 -4
  51. data/lib/splitclient-rb/engine/matchers/set_matcher.rb +2 -1
  52. data/lib/splitclient-rb/engine/matchers/starts_with_matcher.rb +4 -3
  53. data/lib/splitclient-rb/engine/matchers/user_defined_segment_matcher.rb +3 -2
  54. data/lib/splitclient-rb/engine/matchers/whitelist_matcher.rb +7 -5
  55. data/lib/splitclient-rb/engine/models/label.rb +2 -0
  56. data/lib/splitclient-rb/engine/parser/condition.rb +31 -20
  57. data/lib/splitclient-rb/engine/parser/evaluator.rb +3 -2
  58. data/lib/splitclient-rb/engine/parser/split_adapter.rb +9 -7
  59. data/lib/splitclient-rb/localhost_split_factory.rb +3 -2
  60. data/lib/splitclient-rb/managers/split_manager.rb +39 -5
  61. data/lib/splitclient-rb/redis_metrics_fixer.rb +5 -4
  62. data/lib/splitclient-rb/split_config.rb +35 -14
  63. data/lib/splitclient-rb/split_factory.rb +44 -32
  64. data/lib/splitclient-rb/split_factory_builder.rb +4 -5
  65. data/lib/splitclient-rb/split_factory_registry.rb +51 -0
  66. data/lib/splitclient-rb/split_logger.rb +5 -14
  67. data/lib/splitclient-rb/validators.rb +19 -16
  68. data/lib/splitclient-rb/version.rb +1 -1
  69. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e671cc2e51a3805008b98809bccb0bf01f9a6d0
4
- data.tar.gz: b182b2ce898ff203ffd495b71646ced49446b03e
3
+ metadata.gz: f6a5b99ba163bda9744577f231e0ed127d808c34
4
+ data.tar.gz: 72bbfaef6c8afe8dd3e3193c87d2b7f7e2447a37
5
5
  SHA512:
6
- metadata.gz: 55a19aeb9a951a9ef18f11de72662879096b7b383103caa634811a5068a302a90d47b666fb32f3c735150f6aa2b01ba1811952e266ee6bc2518dbfe87b56d8f0
7
- data.tar.gz: 9ea074692f9a588406dc035fc6df200fb76dbeeb0e73b0478da9f154c2d4b95605b4fdab3c4170f06ebfa6fb46f17b58aebd209c509b903c74baa1b0b0bea315
6
+ metadata.gz: 8403fd2036600e5a22fd06202365cca5063a71fa1668622b02509a89cf6233d7dcaf8229657a4cdd61398da5ea4282200a776096cefab33ce0f157e03082e7ee
7
+ data.tar.gz: 38f478dd7467fc9396430bcd69338026ddbe185dd789b09ec44022ea850a1244163a475732619f33915d2f7ebd3087df1ebb32a16457f082a1c7706700d937f9
data/CHANGES.txt CHANGED
@@ -1,5 +1,19 @@
1
- 6.3.0 (Apr 30, 2019)
1
+ 7.0.0 (Aug 23, 2019)
2
+ - BREAKING CHANGE: block_until_ready is now a method in both split_client and split_manager that needs to be explicitly called. The block_until_ready parameter is now ignored if passed in the configuration, and defaults to 15s unless passed as a parameter of the block_until_ready method.
3
+ - Added warning to track calls when traffic type does not belong to an existing split (only issued in the online client and when SDK is ready).
4
+ - Added warning to the get_treatment's method family when split does not exist in the current environment (only issued by online client and when SDK is ready).
5
+ - Added warning to the split_manager's split method when split does not exist in the current environment (only issued by online client and when SDK is ready).
6
+ - Added ability to create multiple split_factory instances. Added factory counts and warnings.
7
+ - Added SDK not ready impressions label.
8
+ - Changed the splits method implementation in the splits_repository to make use of get_splits, which outperforms the current implementation.
9
+
10
+ 6.4.1 (Jul 26, 2019)
11
+ - Fixed an issue in the latency metrics format preventing the synchronizer from correctly picking them up (consumer mode only). Old keys will be deleted on SDK startup.
2
12
 
13
+ 6.4.0 (Jul 05, 2019)
14
+ - Added properties to track method.
15
+
16
+ 6.3.0 (Apr 30, 2019)
3
17
  - Added Dynamic Configurations support through two new methods that mimick the regular ones, changing the type of what is returned.
4
18
  - get_treatment_with_config: Same as get_treatment but returning the treatment with it's config.
5
19
  - get_treatments_with_config: Same as get_treatments, but instead of a map of string it returns a map of treatments with config.
data/Detailed-README.md CHANGED
@@ -72,15 +72,12 @@ else
72
72
  end
73
73
  ```
74
74
 
75
- **Note**: You can ensure the SDK resources are loaded before querying for treatments by using `block_until_ready`. See [Advanced Configuration](#advanced-configuration).
76
- ``` ruby
77
- options = {
78
- block_until_ready: 10
79
- }
75
+ **Note**: You can ensure the SDK resources are loaded before querying for treatments by using `block_until_ready`.
80
76
 
81
- # Then init the factory passing the options hash
82
- factory = SplitIoClient::SplitFactoryBuilder.build('YOUR_API_KEY', options)
77
+ ``` ruby
78
+ factory = SplitIoClient::SplitFactoryBuilder.build('YOUR_API_KEY')
83
79
  split_client = factory.client
80
+ split_client.block_until_ready # Wait for a specified time (default 15 seconds). SDK raises an SDKBlockerTimeoutExpiredException if not ready by then
84
81
  ```
85
82
 
86
83
  For features that use targeting rules based on user attributes, you can call the `get_treatment` method the following way:
@@ -108,8 +105,6 @@ An scenario that requires the usage of both keys is a visitor user that browses
108
105
 
109
106
  Split solves this situation by introducing the concept of a matching_key and a bucketing key. By providing the `subscriber_id` as the `matching_key` and the `visitor_id` as the `bucketing_key`, Split will give the same treatment back to the user that it used to give to the visitor.
110
107
 
111
- **Note**: read more about this topic [here](https://docs.split.io/docs/anonymous-to-logged-in).
112
-
113
108
  The `bucketing_key` may be `nil`. In that case the `matching_key` would be used instead, so calling:
114
109
  ```ruby
115
110
  split_client.get_treatment(
@@ -174,6 +169,8 @@ Which would produce an output similar to:
174
169
  ]
175
170
  ```
176
171
 
172
+ **Note**: `block_until_ready` is also available as a Split manager method
173
+
177
174
  #### Localhost Mode
178
175
 
179
176
  You can run the SDK in _localhost_ mode. In this mode, the SDK won't actually communicate with the Split API, but it'll rather return treatments based on a `.split` file on your local environment. This file must be a list of `split_name treatment_name_to_be_returned` entries. e.g.:
@@ -216,7 +213,7 @@ In order to provide consistency among the SDKs for the different programming lan
216
213
 
217
214
  - `matching_key`, `bucketing_key`: the containing `Hash` must have both keys, and the same rules above apply for each.
218
215
 
219
- - `split_name`: must be a non-empty `String` or a `Symbol`. Whitespaces will be trimmed from both ends of it. The trimmed version of the `split_name` will be used for both evaluation and to store the resulting impression.
216
+ - `split_name`: must be a non-empty `String` or a `Symbol`. Whitespaces will be trimmed from both ends of it. The trimmed version of the `split_name` will be used for both evaluation and to store the resulting impression. In addition, split must exist in the environment.
220
217
 
221
218
  - `attributes`: must be of type `Hash`.
222
219
 
@@ -238,15 +235,12 @@ In order to provide consistency among the SDKs for the different programming lan
238
235
 
239
236
  #### split (split_manager)
240
237
 
241
- - `split_name`: must be a non-empty `String` or a `Symbol`.
238
+ - `split_name`: must be a non-empty `String` or a `Symbol`. In addition, split must exist in the environment.
242
239
 
243
240
  #### Configuration Parameters
244
241
 
245
242
  - `api_key`: must be a non-empty `String` or a `Symbol` of type `sdk` (`browser` type API keys will break this rule).
246
243
 
247
- - `block_until_ready`: a warning log message will be issued if this value is not set.
248
-
249
-
250
244
  #### Client Destroyed Rules
251
245
  Calls to the SDK methods are still possible after `destroy` is called. All will log an error message stating _client has been destroyed_.
252
246
 
@@ -329,12 +323,6 @@ The following values can be customized:
329
323
 
330
324
  *default value* = (no impression listener)
331
325
 
332
- **block_until_ready** : The SDK will block your app for the provided amount of seconds until it's ready. A `SplitIoClient::SDKBlockerTimeoutExpiredException` will be thrown If the provided time expires. When `0` is provided, the SDK runs in non-blocking mode.
333
-
334
- _When using consumer mode, blocking has no effect._
335
-
336
- *default value* = `0`
337
-
338
326
  **labels_enabled** : Allows preventing labels from being sent to the Split servers, as they may contain sensitive information.
339
327
 
340
328
  *default value* = `true`
@@ -448,7 +436,7 @@ In the example above, the listener simply takes an impression and logs it to the
448
436
  The SDK is capable of running in two different modes to fit in different infrastructure configurations:
449
437
 
450
438
  - `:standalone` - (default) : The SDK will retrieve information (e.g. split definitions) periodically from the Split servers, and store it in the memory cache. It'll also store the application execution information (e.g. impressions) in the cache and send it periodically to the Split servers. As it name implies, in this mode, the SDK neither relies nor synchronizes with any other component. _This mode is only available when using the `memory` cache adapter._
451
- - `:consumer` - If using a load balancer or more than one SDK in your application, guaranteeing that all changes in split definitions are picked up by all SDK instances at the same time is highly recommended in order to ensure consistent results across your infrastructure (i.e. getting the same treatment for a specific split and user pair). To achieve this, use the [Split Synchronizer](https://docs.split.io/docs/split-synchronizer)) and setup your SDKs to work in the `consumer` mode. Setting the components this way, all communication with the Split server is orchestrated by the Synchronizer, while the SDKs pick up definitions and store the execution information from / into a shared Redis data store. _This mode is only available when using the `redis` cache adapter._
439
+ - `:consumer` - If using a load balancer or more than one SDK in your application, guaranteeing that all changes in split definitions are picked up by all SDK instances at the same time is highly recommended in order to ensure consistent results across your infrastructure (i.e. getting the same treatment for a specific split and user pair). To achieve this, use the [Split Synchronizer](https://docs.split.io/docs/split-synchronizer)) and setup your SDKs to work in the `consumer` mode. Setting the components this way, all communication with the Split server is orchestrated by the Synchronizer, while the SDKs pick up definitions and store the execution information from / into a shared Redis data store. _This mode is only available when using the `redis` cache adapter. In addition, note that `block_until_ready` has no effect in this mode_
452
440
 
453
441
  _You can choose between these 2 modes setting the `mode` option in the config. An invalid combination of `cache_adaper` and `mode` will result in an Invalid Mode exception being raised._
454
442
 
data/NEWS CHANGED
@@ -1,3 +1,6 @@
1
+ 6.4.0 (Jul 05, 2019)
2
+ - Added properties to track method.
3
+
1
4
  6.3.0 (Apr 30, 2019)
2
5
 
3
6
  - Added Dynamic Configurations support through two new methods that mimick the regular ones, changing the type of what is returned.
@@ -39,6 +39,8 @@ require 'splitclient-rb/split_factory_builder'
39
39
  require 'splitclient-rb/localhost_split_factory'
40
40
  require 'splitclient-rb/split_config'
41
41
  require 'splitclient-rb/split_logger'
42
+ require 'splitclient-rb/validators'
43
+ require 'splitclient-rb/split_factory_registry'
42
44
 
43
45
  require 'splitclient-rb/engine/api/faraday_middleware/gzip'
44
46
  require 'splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent'
@@ -82,7 +84,6 @@ require 'splitclient-rb/engine/models/split'
82
84
  require 'splitclient-rb/engine/models/label'
83
85
  require 'splitclient-rb/engine/models/treatment'
84
86
  require 'splitclient-rb/utilitites'
85
- require 'splitclient-rb/validators'
86
87
 
87
88
  # redis metrics fixer
88
89
  require 'splitclient-rb/redis_metrics_fixer'
@@ -7,9 +7,9 @@ module SplitIoClient
7
7
  extend Forwardable
8
8
  def_delegators :@adapter, :initialize_set, :set_bool, :pipelined
9
9
 
10
- def initialize(adapter)
11
- @cache = LruRedux::TTL::ThreadSafeCache.new(SplitIoClient.configuration.max_cache_size, SplitIoClient.configuration.cache_ttl)
12
- @adapter = adapter
10
+ def initialize(config)
11
+ @cache = LruRedux::TTL::ThreadSafeCache.new(config.max_cache_size, config.cache_ttl)
12
+ @adapter = config.cache_adapter
13
13
  end
14
14
 
15
15
  def delete(key)
@@ -5,8 +5,9 @@ module SplitIoClient
5
5
  class MemoryRepository < EventsRepository
6
6
  EVENTS_MAX_SIZE_BYTES = 5242880
7
7
 
8
- def initialize(adapter)
9
- @adapter = adapter
8
+ def initialize(config)
9
+ @config = config
10
+ @adapter = @config.events_adapter
10
11
  @size = 0
11
12
  end
12
13
 
@@ -14,10 +15,10 @@ module SplitIoClient
14
15
  @adapter.add_to_queue(m: metadata, e: event(key, traffic_type, event_type, time, value, properties))
15
16
  @size += event_size
16
17
 
17
- post_events if @size >= EVENTS_MAX_SIZE_BYTES || @adapter.length == SplitIoClient.configuration.events_queue_size
18
+ post_events if @size >= EVENTS_MAX_SIZE_BYTES || @adapter.length == @config.events_queue_size
18
19
 
19
20
  rescue StandardError => error
20
- SplitIoClient.configuration.log_found_exception(__method__.to_s, error)
21
+ @config.log_found_exception(__method__.to_s, error)
21
22
  end
22
23
 
23
24
  def clear
@@ -4,8 +4,9 @@ module SplitIoClient
4
4
  module Events
5
5
  class RedisRepository < EventsRepository
6
6
 
7
- def initialize(adapter)
8
- @adapter = adapter
7
+ def initialize(config)
8
+ @config = config
9
+ @adapter = @config.events_adapter
9
10
  end
10
11
 
11
12
  def add(key, traffic_type, event_type, time, value, properties, size)
@@ -20,7 +21,7 @@ module SplitIoClient
20
21
  JSON.parse(e, symbolize_names: true)
21
22
  end
22
23
  rescue StandardError => e
23
- SplitIoClient.configuration.logger.error("Exception while clearing events cache: #{e}")
24
+ @config.logger.error("Exception while clearing events cache: #{e}")
24
25
  []
25
26
  end
26
27
  end
@@ -6,12 +6,13 @@ module SplitIoClient
6
6
  extend Forwardable
7
7
  def_delegators :@repository, :add, :clear
8
8
 
9
- def initialize(adapter, api_key)
10
- @repository = case adapter.class.to_s
9
+ def initialize(config, api_key)
10
+ super(config)
11
+ @repository = case @config.events_adapter.class.to_s
11
12
  when 'SplitIoClient::Cache::Adapters::MemoryAdapter'
12
- Repositories::Events::MemoryRepository.new(adapter)
13
+ Repositories::Events::MemoryRepository.new(@config)
13
14
  when 'SplitIoClient::Cache::Adapters::RedisAdapter'
14
- Repositories::Events::RedisRepository.new(adapter)
15
+ Repositories::Events::RedisRepository.new(@config)
15
16
  end
16
17
 
17
18
  @api_key = api_key
@@ -20,16 +21,16 @@ module SplitIoClient
20
21
  def post_events
21
22
  events_api.post(self.clear)
22
23
  rescue StandardError => error
23
- SplitIoClient.configuration.log_found_exception(__method__.to_s, error)
24
+ @config.log_found_exception(__method__.to_s, error)
24
25
  end
25
26
 
26
27
  protected
27
28
 
28
29
  def metadata
29
30
  {
30
- s: "#{SplitIoClient.configuration.language}-#{SplitIoClient.configuration.version}",
31
- i: SplitIoClient.configuration.machine_ip,
32
- n: SplitIoClient.configuration.machine_name
31
+ s: "#{@config.language}-#{@config.version}",
32
+ i: @config.machine_ip,
33
+ n: @config.machine_name
33
34
  }
34
35
  end
35
36
 
@@ -47,7 +48,7 @@ module SplitIoClient
47
48
  private
48
49
 
49
50
  def events_api
50
- @events_api ||= SplitIoClient::Api::Events.new(@api_key)
51
+ @events_api ||= SplitIoClient::Api::Events.new(@api_key, @config)
51
52
  end
52
53
  end
53
54
  end
@@ -5,8 +5,9 @@ module SplitIoClient
5
5
  module Repositories
6
6
  module Impressions
7
7
  class MemoryRepository < ImpressionsRepository
8
- def initialize(adapter)
9
- @adapter = adapter
8
+ def initialize(config)
9
+ @config = config
10
+ @adapter = @config.impressions_adapter
10
11
  end
11
12
 
12
13
  # Store impression data in the selected adapter
@@ -23,8 +24,8 @@ module SplitIoClient
23
24
  )
24
25
  rescue ThreadError # queue is full
25
26
  if random_sampler.rand(1..1000) <= 2 # log only 0.2 % of the time
26
- SplitIoClient.configuration.logger.warn("Dropping impressions. Current size is \
27
- #{SplitIoClient.configuration.impressions_queue_size}. " \
27
+ @config.logger.warn("Dropping impressions. Current size is \
28
+ #{@config.impressions_queue_size}. " \
28
29
  'Consider increasing impressions_queue_size')
29
30
  end
30
31
  end
@@ -36,9 +37,9 @@ module SplitIoClient
36
37
  end
37
38
 
38
39
  def batch
39
- return [] if SplitIoClient.configuration.impressions_bulk_size.zero?
40
+ return [] if @config.impressions_bulk_size.zero?
40
41
 
41
- @adapter.get_batch(SplitIoClient.configuration.impressions_bulk_size)
42
+ @adapter.get_batch(@config.impressions_bulk_size)
42
43
  end
43
44
 
44
45
  def clear
@@ -7,8 +7,9 @@ module SplitIoClient
7
7
  class RedisRepository < ImpressionsRepository
8
8
  EXPIRE_SECONDS = 3600
9
9
 
10
- def initialize(adapter)
11
- @adapter = adapter
10
+ def initialize(config)
11
+ @config = config
12
+ @adapter = @config.impressions_adapter
12
13
  end
13
14
 
14
15
  def add(matching_key, bucketing_key, split_name, treatment, time)
@@ -42,12 +43,12 @@ module SplitIoClient
42
43
  impression
43
44
  end
44
45
  rescue StandardError => e
45
- SplitIoClient.configuration.logger.error("Exception while clearing impressions cache: #{e}")
46
+ @config.logger.error("Exception while clearing impressions cache: #{e}")
46
47
  []
47
48
  end
48
49
 
49
50
  def batch
50
- get_impressions(SplitIoClient.configuration.impressions_bulk_size)
51
+ get_impressions(@config.impressions_bulk_size)
51
52
  end
52
53
 
53
54
  def clear
@@ -8,12 +8,13 @@ module SplitIoClient
8
8
  extend Forwardable
9
9
  def_delegators :@adapter, :add, :add_bulk, :batch, :clear, :empty?
10
10
 
11
- def initialize(adapter)
12
- @adapter = case adapter.class.to_s
11
+ def initialize(config)
12
+ super(config)
13
+ @adapter = case @config.impressions_adapter.class.to_s
13
14
  when 'SplitIoClient::Cache::Adapters::MemoryAdapter'
14
- Repositories::Impressions::MemoryRepository.new(adapter)
15
+ Repositories::Impressions::MemoryRepository.new(@config)
15
16
  when 'SplitIoClient::Cache::Adapters::RedisAdapter'
16
- Repositories::Impressions::RedisRepository.new(adapter)
17
+ Repositories::Impressions::RedisRepository.new(@config)
17
18
  end
18
19
  end
19
20
 
@@ -33,14 +34,14 @@ module SplitIoClient
33
34
 
34
35
  def metadata
35
36
  {
36
- s: "#{SplitIoClient.configuration.language}-#{SplitIoClient.configuration.version}",
37
- i: SplitIoClient.configuration.machine_ip,
38
- n: SplitIoClient.configuration.machine_name
37
+ s: "#{@config.language}-#{@config.version}",
38
+ i: @config.machine_ip,
39
+ n: @config.machine_name
39
40
  }
40
41
  end
41
42
 
42
43
  def applied_rule(label)
43
- SplitIoClient.configuration.labels_enabled ? label : nil
44
+ @config.labels_enabled ? label : nil
44
45
  end
45
46
  end
46
47
  end
@@ -5,10 +5,11 @@ module SplitIoClient
5
5
  class MemoryRepository
6
6
  OPERATIONS = %w(sdk.get_treatment sdk.get_treatments sdk.get_treatment_with_config sdk.get_treatments_with_config)
7
7
 
8
- def initialize(_ = nil, adapter)
8
+ def initialize(_ = nil, config)
9
9
  @counts = []
10
10
  @latencies = []
11
11
  @gauges = []
12
+ @config = config
12
13
  end
13
14
 
14
15
  def add_count(counter, delta)
@@ -127,7 +128,7 @@ module SplitIoClient
127
128
  end
128
129
 
129
130
  private
130
-
131
+
131
132
  def increase_latency_bucket(operation, index)
132
133
  operation_latencies = find_operation_latencies(operation)
133
134
 
@@ -3,8 +3,9 @@ module SplitIoClient
3
3
  module Repositories
4
4
  module Metrics
5
5
  class RedisRepository < Repository
6
- def initialize(adapter = nil)
7
- @adapter = adapter
6
+ def initialize(config)
7
+ @config = config
8
+ @adapter = config.metrics_adapter
8
9
  end
9
10
 
10
11
  def add_count(counter, delta)
@@ -78,7 +79,7 @@ module SplitIoClient
78
79
 
79
80
  keys.concat @adapter.find_strings_by_pattern(latencies_to_be_deleted_key_pattern_prefix('*.time'))
80
81
 
81
- SplitIoClient.configuration.logger.info("Found incorrect latency keys, deleting. Keys: #{keys}") unless keys.size == 0
82
+ @config.logger.info("Found incorrect latency keys, deleting. Keys: #{keys}") unless keys.size == 0
82
83
 
83
84
  keys.each_slice(500) do |chunk|
84
85
  @adapter.pipelined do
@@ -90,7 +91,7 @@ module SplitIoClient
90
91
  end
91
92
 
92
93
  def latencies_to_be_deleted_key_pattern_prefix(key)
93
- "#{SplitIoClient.configuration.redis_namespace}/#{SplitIoClient.configuration.language}-*/latency.#{key}"
94
+ "#{@config.redis_namespace}/#{@config.language}-*/latency.#{key}"
94
95
  end
95
96
 
96
97
  def clear_gauges
@@ -7,14 +7,16 @@ module SplitIoClient
7
7
  def_delegators :@adapter, :add_count, :add_latency, :add_gauge, :counts, :latencies, :gauges,
8
8
  :clear_counts, :clear_latencies, :clear_gauges, :clear, :fix_latencies
9
9
 
10
- def initialize(adapter)
11
- @adapter = case adapter.class.to_s
10
+ def initialize(config)
11
+ super(config)
12
+ @adapter = case @config.metrics_adapter.class.to_s
12
13
  when 'SplitIoClient::Cache::Adapters::MemoryAdapter'
13
- Repositories::Metrics::MemoryRepository.new(adapter)
14
+ Repositories::Metrics::MemoryRepository.new(@config)
14
15
  when 'SplitIoClient::Cache::Adapters::RedisAdapter'
15
- Repositories::Metrics::RedisRepository.new(adapter)
16
+ Repositories::Metrics::RedisRepository.new(@config)
16
17
  end
17
18
  end
19
+
18
20
  end
19
21
  end
20
22
  end
@@ -1,6 +1,11 @@
1
1
  module SplitIoClient
2
2
  module Cache
3
3
  class Repository
4
+
5
+ def initialize(config)
6
+ @config = config
7
+ end
8
+
4
9
  def set_string(key, str)
5
10
  @adapter.set_string(namespace_key(key), str)
6
11
  end
@@ -12,11 +17,11 @@ module SplitIoClient
12
17
  protected
13
18
 
14
19
  def namespace_key(key = '')
15
- "#{SplitIoClient.configuration.redis_namespace}#{key}"
20
+ "#{@config.redis_namespace}#{key}"
16
21
  end
17
22
 
18
23
  def impressions_metrics_key(key)
19
- namespace_key("/#{SplitIoClient.configuration.language}-#{SplitIoClient.configuration.version}/#{SplitIoClient.configuration.machine_ip}/#{key}")
24
+ namespace_key("/#{@config.language}-#{@config.version}/#{@config.machine_ip}/#{key}")
20
25
  end
21
26
  end
22
27
  end