splitclient-rb 6.3.0.pre.rc1-java → 6.4.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32663e4c149a158e500c4a3920d32748417513af
4
- data.tar.gz: aac00674e0ad13c7941adc89bd49a2a7411f5dba
3
+ metadata.gz: d4a6ccb94a40d5e5fcf6ba59388bbfc844d3be32
4
+ data.tar.gz: d7e33c62913cbca99a4dcc37ca5a61f3b21625e2
5
5
  SHA512:
6
- metadata.gz: a3654658a46079123705da5a31cd44caad72b56359b050ad0cfea5dcf2b547934838e9100e1ae26336851e652551a0025d301f43af25fd7fa57b5a91da0714bd
7
- data.tar.gz: cec1512dbe90831cf138e312b21a3a69699e7ca7949f36fb4c1c7ab470ccca7bc6f72fe665730c515e90200d3f69f8ab39b152bbd23e781a4dfd31582436c018
6
+ metadata.gz: 6fa3bb21bc4a04cd8d5dc2f3fe8827aaad8c3a9870d2520a4410db5f115d4cb7244f70f41fd75136a106202685eec437fd2467b306f730a0da761010592b531a
7
+ data.tar.gz: 95477f6c83503bc1a7d2b117d4717784508e6ecf27e40514b9b89748a8688a5d8fdf658da443ebdd242dd32fddc6ea54d1e1f5b6f2ce583d01f4283e8f0a2ea0
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - "2.3.6"
5
+
6
+ services:
7
+ - redis-server
8
+
9
+ before_install:
10
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
11
+ - gem install bundler -v '< 2'
data/CHANGES.txt CHANGED
@@ -1,5 +1,7 @@
1
- 6.3.0 (Apr 22, 2019)
1
+ 6.4.0 (Jul 05, 2019)
2
+ - Added properties to track method.
2
3
 
4
+ 6.3.0 (Apr 30, 2019)
3
5
  - Added Dynamic Configurations support through two new methods that mimick the regular ones, changing the type of what is returned.
4
6
  - get_treatment_with_config: Same as get_treatment but returning the treatment with it's config.
5
7
  - get_treatments_with_config: Same as get_treatments, but instead of a map of string it returns a map of treatments with config.
data/NEWS CHANGED
@@ -1,4 +1,7 @@
1
- 6.3.0 (Apr 22, 2019)
1
+ 6.4.0 (Jul 05, 2019)
2
+ - Added properties to track method.
3
+
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.
4
7
  - get_treatment_with_config: Same as get_treatment but returning the treatment with it's config.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [ ![Codeship Status for splitio/ruby-client](https://app.codeship.com/projects/306c6b60-c164-0133-e179-16471d4e6045/status?branch=master)](https://app.codeship.com/projects/137510)
1
+ [![Build Status](https://travis-ci.com/splitio/ruby-client.svg?branch=master)](https://travis-ci.com/splitio/ruby-client)
2
2
 
3
3
  # Split Ruby SDK
4
4
 
@@ -35,7 +35,7 @@ Split has built and maintains a SDKs for:
35
35
 
36
36
  For a comprehensive list of opensource projects visit our [Github page](https://github.com/splitio?utf8=%E2%9C%93&query=%20only%3Apublic%20).
37
37
 
38
- **Learn more about Split:**
38
+ **Learn more about Split:**
39
39
 
40
40
  Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [docs.split.io](http://docs.split.io) for more detailed information.
41
41
 
@@ -39,6 +39,9 @@ module SplitIoClient
39
39
  items
40
40
  end
41
41
 
42
+ def length
43
+ @current_size.value
44
+ end
42
45
  end
43
46
  end
44
47
  end
@@ -3,27 +3,25 @@ module SplitIoClient
3
3
  module Repositories
4
4
  module Events
5
5
  class MemoryRepository < EventsRepository
6
- EVENTS_SLICE = 100
6
+ EVENTS_MAX_SIZE_BYTES = 5242880
7
7
 
8
8
  def initialize(adapter)
9
9
  @adapter = adapter
10
+ @size = 0
10
11
  end
11
12
 
12
- def add(key, traffic_type, event_type, time, value)
13
- @adapter.add_to_queue(m: metadata, e: event(key, traffic_type, event_type, time, value))
14
- rescue ThreadError # queue is full
15
- if SplitIoClient.configuration.debug_enabled
16
- SplitIoClient.configuration.logger.warn("Dropping events. Current size is #{SplitIoClient.configuration.events_queue_size}. " \
17
- "Consider increasing events_queue_size")
18
- end
19
- @adapter.clear
20
- end
13
+ def add(key, traffic_type, event_type, time, value, properties, event_size)
14
+ @adapter.add_to_queue(m: metadata, e: event(key, traffic_type, event_type, time, value, properties))
15
+ @size += event_size
16
+
17
+ post_events if @size >= EVENTS_MAX_SIZE_BYTES || @adapter.length == SplitIoClient.configuration.events_queue_size
21
18
 
22
- def batch
23
- @adapter.get_batch(EVENTS_SLICE)
19
+ rescue StandardError => error
20
+ SplitIoClient.configuration.log_found_exception(__method__.to_s, error)
24
21
  end
25
22
 
26
23
  def clear
24
+ @size = 0
27
25
  @adapter.clear
28
26
  end
29
27
  end
@@ -3,36 +3,26 @@ module SplitIoClient
3
3
  module Repositories
4
4
  module Events
5
5
  class RedisRepository < EventsRepository
6
- EVENTS_SLICE = 100
7
6
 
8
7
  def initialize(adapter)
9
8
  @adapter = adapter
10
9
  end
11
10
 
12
- def add(key, traffic_type, event_type, time, value)
11
+ def add(key, traffic_type, event_type, time, value, properties, size)
13
12
  @adapter.add_to_queue(
14
13
  namespace_key('.events'),
15
- { m: metadata, e: event(key, traffic_type, event_type, time, value) }.to_json,
14
+ { m: metadata, e: event(key, traffic_type, event_type, time, value, properties) }.to_json
16
15
  )
17
16
  end
18
17
 
19
- def get_events(number_of_events = 0)
20
- @adapter.get_from_queue(namespace_key('.events'), number_of_events).map do |e|
18
+ def clear
19
+ @adapter.get_from_queue(namespace_key('.events'), 0).map do |e|
21
20
  JSON.parse(e, symbolize_names: true)
22
21
  end
23
22
  rescue StandardError => e
24
23
  SplitIoClient.configuration.logger.error("Exception while clearing events cache: #{e}")
25
24
  []
26
25
  end
27
-
28
- def batch
29
- get_events(EVENTS_SLICE)
30
- end
31
-
32
- def clear
33
- get_events
34
- end
35
-
36
26
  end
37
27
  end
38
28
  end
@@ -4,15 +4,23 @@ module SplitIoClient
4
4
  # Repository which forwards events interface to the selected adapter
5
5
  class EventsRepository < Repository
6
6
  extend Forwardable
7
- def_delegators :@adapter, :add, :clear, :batch
7
+ def_delegators :@repository, :add, :clear
8
8
 
9
- def initialize(adapter)
10
- @adapter = case adapter.class.to_s
9
+ def initialize(adapter, api_key)
10
+ @repository = case adapter.class.to_s
11
11
  when 'SplitIoClient::Cache::Adapters::MemoryAdapter'
12
12
  Repositories::Events::MemoryRepository.new(adapter)
13
13
  when 'SplitIoClient::Cache::Adapters::RedisAdapter'
14
14
  Repositories::Events::RedisRepository.new(adapter)
15
15
  end
16
+
17
+ @api_key = api_key
18
+ end
19
+
20
+ def post_events
21
+ events_api.post(self.clear)
22
+ rescue StandardError => error
23
+ SplitIoClient.configuration.log_found_exception(__method__.to_s, error)
16
24
  end
17
25
 
18
26
  protected
@@ -25,15 +33,22 @@ module SplitIoClient
25
33
  }
26
34
  end
27
35
 
28
- def event(key, traffic_type, event_type, time, value)
36
+ def event(key, traffic_type, event_type, time, value, properties)
29
37
  {
30
38
  key: key,
31
39
  trafficTypeName: traffic_type,
32
40
  eventTypeId: event_type,
33
41
  value: value,
34
- timestamp: time
42
+ timestamp: time,
43
+ properties: properties
35
44
  }.reject { |_, v| v.nil? }
36
45
  end
46
+
47
+ private
48
+
49
+ def events_api
50
+ @events_api ||= SplitIoClient::Api::Events.new(@api_key)
51
+ end
37
52
  end
38
53
  end
39
54
  end
@@ -4,9 +4,8 @@ module SplitIoClient
4
4
  module Cache
5
5
  module Senders
6
6
  class EventsSender
7
- def initialize(events_repository, api_key)
7
+ def initialize(events_repository)
8
8
  @events_repository = events_repository
9
- @api_key = api_key
10
9
  end
11
10
 
12
11
  def call
@@ -31,7 +30,7 @@ module SplitIoClient
31
30
  SplitIoClient.configuration.logger.info('Starting events service')
32
31
 
33
32
  loop do
34
- post_events(false)
33
+ post_events
35
34
 
36
35
  sleep(SplitIoClient::Utilities.randomize_interval(SplitIoClient.configuration.events_push_rate))
37
36
  end
@@ -43,15 +42,8 @@ module SplitIoClient
43
42
  end
44
43
  end
45
44
 
46
- def post_events(fetch_all_events = true)
47
- events = fetch_all_events ? @events_repository.clear : @events_repository.batch
48
- events_api.post(events)
49
- rescue StandardError => error
50
- SplitIoClient.configuration.log_found_exception(__method__.to_s, error)
51
- end
52
-
53
- def events_api
54
- @events_api ||= SplitIoClient::Api::Events.new(@api_key)
45
+ def post_events
46
+ @events_repository.post_events
55
47
  end
56
48
  end
57
49
  end
@@ -1,4 +1,6 @@
1
1
  module SplitIoClient
2
+ EVENTS_SIZE_THRESHOLD = 32768
3
+ EVENT_AVERAGE_SIZE = 1024
2
4
 
3
5
  class SplitClient
4
6
  #
@@ -112,10 +114,22 @@ module SplitIoClient
112
114
  @impression_router ||= SplitIoClient::ImpressionRouter.new
113
115
  end
114
116
 
115
- def track(key, traffic_type_name, event_type, value = nil)
116
- return false unless valid_client && SplitIoClient::Validators.valid_track_parameters(key, traffic_type_name, event_type, value)
117
+ def track(key, traffic_type_name, event_type, value = nil, properties = nil)
118
+ return false unless valid_client && SplitIoClient::Validators.valid_track_parameters(key, traffic_type_name, event_type, value, properties)
119
+
120
+ properties_size = EVENT_AVERAGE_SIZE
121
+
122
+ if !properties.nil?
123
+ properties, size = validate_properties(properties)
124
+ properties_size += size
125
+ if (properties_size > EVENTS_SIZE_THRESHOLD)
126
+ SplitIoClient.configuration.logger.error("The maximum size allowed for the properties is #{EVENTS_SIZE_THRESHOLD}. Current is #{properties_size}. Event not queued")
127
+ return false
128
+ end
129
+ end
130
+
117
131
  begin
118
- @events_repository.add(key.to_s, traffic_type_name.downcase, event_type.to_s, (Time.now.to_f * 1000).to_i, value)
132
+ @events_repository.add(key.to_s, traffic_type_name.downcase, event_type.to_s, (Time.now.to_f * 1000).to_i, value, properties, properties_size)
119
133
  true
120
134
  rescue StandardError => error
121
135
  SplitIoClient.configuration.log_found_exception(__method__.to_s, error)
@@ -164,6 +178,30 @@ module SplitIoClient
164
178
 
165
179
  private
166
180
 
181
+ def validate_properties(properties)
182
+ properties_count = 0
183
+ size = 0
184
+
185
+ fixed_properties = properties.each_with_object({}) { |(key, value), result|
186
+
187
+ if(key.is_a?(String) || key.is_a?(Symbol))
188
+ properties_count += 1
189
+ size += variable_size(key)
190
+ if value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(Numeric) || value.is_a?(TrueClass) || value.is_a?(FalseClass) || value.nil?
191
+ result[key] = value
192
+ size += variable_size(value)
193
+ else
194
+ SplitIoClient.configuration.logger.warn("Property #{key} is of invalid type. Setting value to nil")
195
+ result[key] = nil
196
+ end
197
+ end
198
+ }
199
+
200
+ SplitIoClient.configuration.logger.warn('Event has more than 300 properties. Some of them will be trimmed when processed') if properties_count > 300
201
+
202
+ return fixed_properties, size
203
+ end
204
+
167
205
  def valid_client
168
206
  if @destroyed
169
207
  SplitIoClient.configuration.logger.error('Client has already been destroyed - no calls possible')
@@ -279,5 +317,9 @@ module SplitIoClient
279
317
 
280
318
  parsed_treatment(multiple, treatment_data)
281
319
  end
320
+
321
+ def variable_size(value)
322
+ value.is_a?(String) ? value.length : 0
323
+ end
282
324
  end
283
325
  end
@@ -75,7 +75,7 @@ module SplitIoClient
75
75
 
76
76
  # Starts thread which loops constantly and sends events to the Split API
77
77
  def events_sender
78
- EventsSender.new(@events_repository, @api_key).call
78
+ EventsSender.new(@events_repository).call
79
79
  end
80
80
  end
81
81
  end
@@ -29,7 +29,7 @@ module SplitIoClient
29
29
  @segments_repository = SegmentsRepository.new(@cache_adapter)
30
30
  @impressions_repository = ImpressionsRepository.new(SplitIoClient.configuration.impressions_adapter)
31
31
  @metrics_repository = MetricsRepository.new(SplitIoClient.configuration.metrics_adapter)
32
- @events_repository = EventsRepository.new(SplitIoClient.configuration.events_adapter)
32
+ @events_repository = EventsRepository.new(SplitIoClient.configuration.events_adapter, @api_key)
33
33
 
34
34
  if SplitIoClient.configuration.mode == :standalone && SplitIoClient.configuration.block_until_ready > 0
35
35
  @sdk_blocker = SDKBlocker.new(@splits_repository, @segments_repository)
@@ -16,11 +16,12 @@ module SplitIoClient
16
16
  valid_split_names?(method, split_names)
17
17
  end
18
18
 
19
- def valid_track_parameters(key, traffic_type_name, event_type, value)
19
+ def valid_track_parameters(key, traffic_type_name, event_type, value, properties)
20
20
  valid_track_key?(key) &&
21
21
  valid_traffic_type_name?(traffic_type_name) &&
22
22
  valid_event_type?(event_type) &&
23
- valid_value?(value)
23
+ valid_value?(value) &&
24
+ valid_properties?(properties)
24
25
  end
25
26
 
26
27
  def valid_split_parameters(split_name)
@@ -253,5 +254,14 @@ module SplitIoClient
253
254
 
254
255
  true
255
256
  end
257
+
258
+ def valid_properties?(properties)
259
+ unless properties.is_a?(Hash) || properties.nil?
260
+ SplitIoClient.configuration.logger.error('track: properties must be a Hash')
261
+ return false
262
+ end
263
+
264
+ true
265
+ end
256
266
  end
257
267
  end
@@ -1,3 +1,3 @@
1
1
  module SplitIoClient
2
- VERSION = '6.3.0.pre.rc1'
2
+ VERSION = '6.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splitclient-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.0.pre.rc1
4
+ version: 6.4.0
5
5
  platform: java
6
6
  authors:
7
7
  - Split Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-22 00:00:00.000000000 Z
11
+ date: 2019-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -286,6 +286,7 @@ files:
286
286
  - ".gitignore"
287
287
  - ".rubocop.yml"
288
288
  - ".simplecov"
289
+ - ".travis.yml"
289
290
  - Appraisals
290
291
  - CHANGES.txt
291
292
  - Detailed-README.md
@@ -398,9 +399,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
398
399
  version: '0'
399
400
  required_rubygems_version: !ruby/object:Gem::Requirement
400
401
  requirements:
401
- - - ">"
402
+ - - ">="
402
403
  - !ruby/object:Gem::Version
403
- version: 1.3.1
404
+ version: '0'
404
405
  requirements: []
405
406
  rubyforge_project:
406
407
  rubygems_version: 2.6.14