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.
- checksums.yaml +4 -4
- data/CHANGES.txt +15 -1
- data/Detailed-README.md +9 -21
- data/NEWS +3 -0
- data/lib/splitclient-rb.rb +2 -1
- data/lib/splitclient-rb/cache/adapters/cache_adapter.rb +3 -3
- data/lib/splitclient-rb/cache/repositories/events/memory_repository.rb +5 -4
- data/lib/splitclient-rb/cache/repositories/events/redis_repository.rb +4 -3
- data/lib/splitclient-rb/cache/repositories/events_repository.rb +10 -9
- data/lib/splitclient-rb/cache/repositories/impressions/memory_repository.rb +7 -6
- data/lib/splitclient-rb/cache/repositories/impressions/redis_repository.rb +5 -4
- data/lib/splitclient-rb/cache/repositories/impressions_repository.rb +9 -8
- data/lib/splitclient-rb/cache/repositories/metrics/memory_repository.rb +3 -2
- data/lib/splitclient-rb/cache/repositories/metrics/redis_repository.rb +5 -4
- data/lib/splitclient-rb/cache/repositories/metrics_repository.rb +6 -4
- data/lib/splitclient-rb/cache/repositories/repository.rb +7 -2
- data/lib/splitclient-rb/cache/repositories/segments_repository.rb +6 -5
- data/lib/splitclient-rb/cache/repositories/splits_repository.rb +56 -14
- data/lib/splitclient-rb/cache/routers/impression_router.rb +5 -4
- data/lib/splitclient-rb/cache/senders/events_sender.rb +7 -6
- data/lib/splitclient-rb/cache/senders/impressions_sender.rb +10 -9
- data/lib/splitclient-rb/cache/senders/metrics_sender.rb +9 -8
- data/lib/splitclient-rb/cache/stores/sdk_blocker.rb +19 -10
- data/lib/splitclient-rb/cache/stores/segment_store.rb +15 -28
- data/lib/splitclient-rb/cache/stores/split_store.rb +13 -15
- data/lib/splitclient-rb/clients/localhost_split_client.rb +8 -7
- data/lib/splitclient-rb/clients/split_client.rb +65 -35
- data/lib/splitclient-rb/engine/api/client.rb +17 -13
- data/lib/splitclient-rb/engine/api/events.rb +7 -6
- data/lib/splitclient-rb/engine/api/impressions.rb +6 -5
- data/lib/splitclient-rb/engine/api/metrics.rb +8 -7
- data/lib/splitclient-rb/engine/api/segments.rb +11 -10
- data/lib/splitclient-rb/engine/api/splits.rb +6 -5
- data/lib/splitclient-rb/engine/matchers/all_keys_matcher.rb +1 -1
- data/lib/splitclient-rb/engine/matchers/between_matcher.rb +7 -5
- data/lib/splitclient-rb/engine/matchers/combining_matcher.rb +5 -4
- data/lib/splitclient-rb/engine/matchers/contains_all_matcher.rb +4 -4
- data/lib/splitclient-rb/engine/matchers/contains_any_matcher.rb +3 -3
- data/lib/splitclient-rb/engine/matchers/contains_matcher.rb +7 -5
- data/lib/splitclient-rb/engine/matchers/dependency_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/ends_with_matcher.rb +5 -4
- data/lib/splitclient-rb/engine/matchers/equal_to_boolean_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/equal_to_matcher.rb +6 -4
- data/lib/splitclient-rb/engine/matchers/equal_to_set_matcher.rb +3 -3
- data/lib/splitclient-rb/engine/matchers/greater_than_or_equal_to_matcher.rb +6 -4
- data/lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb +6 -4
- data/lib/splitclient-rb/engine/matchers/matcher.rb +4 -0
- data/lib/splitclient-rb/engine/matchers/matches_string_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/negation_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/part_of_set_matcher.rb +4 -4
- data/lib/splitclient-rb/engine/matchers/set_matcher.rb +2 -1
- data/lib/splitclient-rb/engine/matchers/starts_with_matcher.rb +4 -3
- data/lib/splitclient-rb/engine/matchers/user_defined_segment_matcher.rb +3 -2
- data/lib/splitclient-rb/engine/matchers/whitelist_matcher.rb +7 -5
- data/lib/splitclient-rb/engine/models/label.rb +2 -0
- data/lib/splitclient-rb/engine/parser/condition.rb +31 -20
- data/lib/splitclient-rb/engine/parser/evaluator.rb +3 -2
- data/lib/splitclient-rb/engine/parser/split_adapter.rb +9 -7
- data/lib/splitclient-rb/localhost_split_factory.rb +3 -2
- data/lib/splitclient-rb/managers/split_manager.rb +39 -5
- data/lib/splitclient-rb/redis_metrics_fixer.rb +5 -4
- data/lib/splitclient-rb/split_config.rb +35 -14
- data/lib/splitclient-rb/split_factory.rb +44 -32
- data/lib/splitclient-rb/split_factory_builder.rb +4 -5
- data/lib/splitclient-rb/split_factory_registry.rb +51 -0
- data/lib/splitclient-rb/split_logger.rb +5 -14
- data/lib/splitclient-rb/validators.rb +19 -16
- data/lib/splitclient-rb/version.rb +1 -1
- metadata +5 -4
@@ -13,10 +13,11 @@ module SplitIoClient
|
|
13
13
|
# @param splits_file [File] file that contains some splits
|
14
14
|
#
|
15
15
|
# @return [LocalhostSplitIoClient] split.io localhost client instance
|
16
|
-
def initialize(splits_file, reload_rate = nil)
|
16
|
+
def initialize(splits_file, config, reload_rate = nil)
|
17
17
|
@localhost_mode = true
|
18
18
|
@localhost_mode_features = []
|
19
19
|
load_localhost_mode_features(splits_file, reload_rate)
|
20
|
+
@config = config
|
20
21
|
end
|
21
22
|
|
22
23
|
#
|
@@ -101,12 +102,12 @@ module SplitIoClient
|
|
101
102
|
parsed_control_treatment = parsed_treatment(control_treatment)
|
102
103
|
|
103
104
|
bucketing_key, matching_key = keys_from_key(key)
|
104
|
-
return parsed_control_treatment unless
|
105
|
+
return parsed_control_treatment unless @config.split_validator.valid_get_treatment_parameters(calling_method, key, split_name, matching_key, bucketing_key, attributes)
|
105
106
|
|
106
107
|
sanitized_split_name = split_name.to_s.strip
|
107
108
|
|
108
109
|
if split_name.to_s != sanitized_split_name
|
109
|
-
|
110
|
+
@config.logger.warn("get_treatment: split_name #{split_name} has extra whitespace, trimming")
|
110
111
|
split_name = sanitized_split_name
|
111
112
|
end
|
112
113
|
|
@@ -127,12 +128,12 @@ module SplitIoClient
|
|
127
128
|
end
|
128
129
|
|
129
130
|
def get_localhost_treatments(key, split_names, attributes = nil, calling_method = 'get_treatments')
|
130
|
-
return nil unless
|
131
|
+
return nil unless @config.split_validator.valid_get_treatments_parameters(calling_method, split_names)
|
131
132
|
|
132
133
|
sanitized_split_names = sanitize_split_names(calling_method, split_names)
|
133
134
|
|
134
135
|
if sanitized_split_names.empty?
|
135
|
-
|
136
|
+
@config.logger.error("#{calling_method}: split_names must be a non-empty Array")
|
136
137
|
return {}
|
137
138
|
end
|
138
139
|
|
@@ -146,10 +147,10 @@ module SplitIoClient
|
|
146
147
|
if (split_name.is_a?(String) || split_name.is_a?(Symbol)) && !split_name.empty?
|
147
148
|
true
|
148
149
|
elsif split_name.is_a?(String) && split_name.empty?
|
149
|
-
|
150
|
+
@config.logger.warn("#{calling_method}: you passed an empty split_name, split_name must be a non-empty String or a Symbol")
|
150
151
|
false
|
151
152
|
else
|
152
|
-
|
153
|
+
@config.logger.warn("#{calling_method}: you passed an invalid split_name, split_name must be a non-empty String or a Symbol")
|
153
154
|
false
|
154
155
|
end
|
155
156
|
end
|
@@ -9,14 +9,16 @@ module SplitIoClient
|
|
9
9
|
# @param api_key [String] the API key for your split account
|
10
10
|
#
|
11
11
|
# @return [SplitIoClient] split.io client instance
|
12
|
-
def initialize(api_key, adapter = nil, splits_repository, segments_repository, impressions_repository, metrics_repository, events_repository)
|
12
|
+
def initialize(api_key, adapter = nil, splits_repository, segments_repository, impressions_repository, metrics_repository, events_repository, sdk_blocker, config)
|
13
|
+
@api_key = api_key
|
13
14
|
@splits_repository = splits_repository
|
14
15
|
@segments_repository = segments_repository
|
15
16
|
@impressions_repository = impressions_repository
|
16
17
|
@metrics_repository = metrics_repository
|
17
18
|
@events_repository = events_repository
|
19
|
+
@sdk_blocker = sdk_blocker
|
18
20
|
@destroyed = false
|
19
|
-
|
21
|
+
@config = config
|
20
22
|
@adapter = adapter
|
21
23
|
end
|
22
24
|
|
@@ -52,27 +54,30 @@ module SplitIoClient
|
|
52
54
|
end
|
53
55
|
|
54
56
|
def destroy
|
55
|
-
|
57
|
+
@config.logger.info('Split client shutdown started...') if @config.debug_enabled
|
56
58
|
|
57
|
-
|
59
|
+
@config.threads.select { |name, thread| name.to_s.end_with? 'sender' }.values.each do |thread|
|
58
60
|
thread.raise(SplitIoClient::SDKShutdownException)
|
59
61
|
thread.join
|
60
62
|
end
|
61
63
|
|
62
|
-
|
64
|
+
@config.threads.values.each { |thread| Thread.kill(thread) }
|
63
65
|
|
64
66
|
@splits_repository.clear
|
65
67
|
@segments_repository.clear
|
66
68
|
|
67
|
-
SplitIoClient.
|
68
|
-
SplitIoClient.
|
69
|
+
SplitIoClient.load_factory_registry
|
70
|
+
SplitIoClient.split_factory_registry.remove(@api_key)
|
71
|
+
|
72
|
+
@config.logger.info('Split client shutdown complete') if @config.debug_enabled
|
73
|
+
@config.valid_mode = false
|
69
74
|
@destroyed = true
|
70
75
|
end
|
71
76
|
|
72
77
|
def store_impression(split_name, matching_key, bucketing_key, treatment, store_impressions, attributes)
|
73
78
|
time = (Time.now.to_f * 1000.0).to_i
|
74
79
|
|
75
|
-
return if
|
80
|
+
return if @config.disable_impressions || !store_impressions
|
76
81
|
|
77
82
|
@impressions_repository.add(
|
78
83
|
matching_key,
|
@@ -85,7 +90,7 @@ module SplitIoClient
|
|
85
90
|
route_impression(split_name, matching_key, bucketing_key, time, treatment, attributes)
|
86
91
|
|
87
92
|
rescue StandardError => error
|
88
|
-
|
93
|
+
@config.log_found_exception(__method__.to_s, error)
|
89
94
|
end
|
90
95
|
|
91
96
|
def route_impression(split_name, matching_key, bucketing_key, time, treatment, attributes)
|
@@ -111,11 +116,11 @@ module SplitIoClient
|
|
111
116
|
end
|
112
117
|
|
113
118
|
def impression_router
|
114
|
-
@impression_router ||= SplitIoClient::ImpressionRouter.new
|
119
|
+
@impression_router ||= SplitIoClient::ImpressionRouter.new(@config)
|
115
120
|
end
|
116
121
|
|
117
122
|
def track(key, traffic_type_name, event_type, value = nil, properties = nil)
|
118
|
-
return false unless valid_client &&
|
123
|
+
return false unless valid_client && @config.split_validator.valid_track_parameters(key, traffic_type_name, event_type, value, properties)
|
119
124
|
|
120
125
|
properties_size = EVENT_AVERAGE_SIZE
|
121
126
|
|
@@ -123,16 +128,22 @@ module SplitIoClient
|
|
123
128
|
properties, size = validate_properties(properties)
|
124
129
|
properties_size += size
|
125
130
|
if (properties_size > EVENTS_SIZE_THRESHOLD)
|
126
|
-
|
131
|
+
@config.logger.error("The maximum size allowed for the properties is #{EVENTS_SIZE_THRESHOLD}. Current is #{properties_size}. Event not queued")
|
127
132
|
return false
|
128
133
|
end
|
129
134
|
end
|
130
135
|
|
136
|
+
if ready? && !@splits_repository.traffic_type_exists(traffic_type_name)
|
137
|
+
@config.logger.warn("track: Traffic Type #{traffic_type_name} " \
|
138
|
+
"does not have any corresponding Splits in this environment, make sure you're tracking " \
|
139
|
+
'your events to a valid traffic type defined in the Split console')
|
140
|
+
end
|
141
|
+
|
131
142
|
begin
|
132
143
|
@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)
|
133
144
|
true
|
134
145
|
rescue StandardError => error
|
135
|
-
|
146
|
+
@config.log_found_exception(__method__.to_s, error)
|
136
147
|
false
|
137
148
|
end
|
138
149
|
end
|
@@ -167,15 +178,19 @@ module SplitIoClient
|
|
167
178
|
if (split_name.is_a?(String) || split_name.is_a?(Symbol)) && !split_name.empty?
|
168
179
|
true
|
169
180
|
elsif split_name.is_a?(String) && split_name.empty?
|
170
|
-
|
181
|
+
@config.logger.warn("#{calling_method}: you passed an empty split_name, split_name must be a non-empty String or a Symbol")
|
171
182
|
false
|
172
183
|
else
|
173
|
-
|
184
|
+
@config.logger.warn("#{calling_method}: you passed an invalid split_name, split_name must be a non-empty String or a Symbol")
|
174
185
|
false
|
175
186
|
end
|
176
187
|
end
|
177
188
|
end
|
178
189
|
|
190
|
+
def block_until_ready(time = nil)
|
191
|
+
@sdk_blocker.block(time) if @sdk_blocker && !@sdk_blocker.ready?
|
192
|
+
end
|
193
|
+
|
179
194
|
private
|
180
195
|
|
181
196
|
def validate_properties(properties)
|
@@ -191,32 +206,32 @@ module SplitIoClient
|
|
191
206
|
result[key] = value
|
192
207
|
size += variable_size(value)
|
193
208
|
else
|
194
|
-
|
209
|
+
@config.logger.warn("Property #{key} is of invalid type. Setting value to nil")
|
195
210
|
result[key] = nil
|
196
211
|
end
|
197
212
|
end
|
198
213
|
}
|
199
214
|
|
200
|
-
|
215
|
+
@config.logger.warn('Event has more than 300 properties. Some of them will be trimmed when processed') if properties_count > 300
|
201
216
|
|
202
217
|
return fixed_properties, size
|
203
218
|
end
|
204
219
|
|
205
220
|
def valid_client
|
206
221
|
if @destroyed
|
207
|
-
|
222
|
+
@config.logger.error('Client has already been destroyed - no calls possible')
|
208
223
|
return false
|
209
224
|
end
|
210
|
-
|
225
|
+
@config.valid_mode
|
211
226
|
end
|
212
227
|
|
213
228
|
def treatments(key, split_names, attributes = {}, calling_method = 'get_treatments')
|
214
|
-
return nil unless
|
229
|
+
return nil unless @config.split_validator.valid_get_treatments_parameters(calling_method, split_names)
|
215
230
|
|
216
231
|
sanitized_split_names = sanitize_split_names(calling_method, split_names)
|
217
232
|
|
218
233
|
if sanitized_split_names.empty?
|
219
|
-
|
234
|
+
@config.logger.error("#{calling_method}: split_names must be a non-empty Array")
|
220
235
|
return {}
|
221
236
|
end
|
222
237
|
|
@@ -224,7 +239,7 @@ module SplitIoClient
|
|
224
239
|
bucketing_key = bucketing_key ? bucketing_key.to_s : nil
|
225
240
|
matching_key = matching_key ? matching_key.to_s : nil
|
226
241
|
|
227
|
-
evaluator = Engine::Parser::Evaluator.new(@segments_repository, @splits_repository, true)
|
242
|
+
evaluator = Engine::Parser::Evaluator.new(@segments_repository, @splits_repository, @config, true)
|
228
243
|
start = Time.now
|
229
244
|
treatments_labels_change_numbers =
|
230
245
|
@splits_repository.get_splits(sanitized_split_names).each_with_object({}) do |(name, data), memo|
|
@@ -234,7 +249,7 @@ module SplitIoClient
|
|
234
249
|
# Measure
|
235
250
|
@adapter.metrics.time('sdk.' + calling_method, latency)
|
236
251
|
|
237
|
-
unless
|
252
|
+
unless @config.disable_impressions
|
238
253
|
time = (Time.now.to_f * 1000.0).to_i
|
239
254
|
@impressions_repository.add_bulk(
|
240
255
|
matching_key, bucketing_key, treatments_labels_change_numbers, time
|
@@ -269,38 +284,48 @@ module SplitIoClient
|
|
269
284
|
key, split_name, attributes = {}, split_data = nil, store_impressions = true,
|
270
285
|
multiple = false, evaluator = nil, calling_method = 'get_treatment'
|
271
286
|
)
|
272
|
-
control_treatment = {
|
273
|
-
|
287
|
+
control_treatment = { treatment: Engine::Models::Treatment::CONTROL }
|
288
|
+
|
289
|
+
parsed_control_exception = parsed_treatment(multiple,
|
290
|
+
control_treatment.merge({ label: Engine::Models::Label::EXCEPTION }))
|
274
291
|
|
275
292
|
bucketing_key, matching_key = keys_from_key(key)
|
276
293
|
|
277
|
-
return
|
294
|
+
return parsed_control_exception unless valid_client && @config.split_validator.valid_get_treatment_parameters(calling_method, key, split_name, matching_key, bucketing_key, attributes)
|
278
295
|
|
279
296
|
bucketing_key = bucketing_key ? bucketing_key.to_s : nil
|
280
297
|
matching_key = matching_key.to_s
|
281
298
|
sanitized_split_name = split_name.to_s.strip
|
282
299
|
|
283
300
|
if split_name.to_s != sanitized_split_name
|
284
|
-
|
301
|
+
@config.logger.warn("#{calling_method}: split_name #{split_name} has extra whitespace, trimming")
|
285
302
|
split_name = sanitized_split_name
|
286
303
|
end
|
287
304
|
|
288
|
-
evaluator ||= Engine::Parser::Evaluator.new(@segments_repository, @splits_repository)
|
305
|
+
evaluator ||= Engine::Parser::Evaluator.new(@segments_repository, @splits_repository, @config)
|
289
306
|
|
290
307
|
begin
|
291
308
|
start = Time.now
|
292
309
|
|
293
310
|
split = multiple ? split_data : @splits_repository.get_split(split_name)
|
294
311
|
|
295
|
-
if split.nil?
|
296
|
-
|
297
|
-
|
312
|
+
if split.nil? && ready?
|
313
|
+
@config.logger.warn("#{calling_method}: you passed #{split_name} that " \
|
314
|
+
'does not exist in this environment, please double check what Splits exist in the web console')
|
315
|
+
|
316
|
+
return parsed_treatment(multiple, control_treatment.merge({ label: Engine::Models::Label::NOT_FOUND }))
|
298
317
|
end
|
299
318
|
|
300
319
|
treatment_data =
|
320
|
+
if !split.nil? && ready?
|
301
321
|
evaluator.call(
|
302
|
-
|
303
|
-
|
322
|
+
{ bucketing_key: bucketing_key, matching_key: matching_key }, split, attributes
|
323
|
+
)
|
324
|
+
else
|
325
|
+
@config.logger.error("#{calling_method}: the SDK is not ready, the operation cannot be executed")
|
326
|
+
|
327
|
+
control_treatment.merge({ label: Engine::Models::Label::NOT_READY })
|
328
|
+
end
|
304
329
|
|
305
330
|
latency = (Time.now - start) * 1000.0
|
306
331
|
store_impression(split_name, matching_key, bucketing_key, treatment_data, store_impressions, attributes)
|
@@ -308,11 +333,11 @@ module SplitIoClient
|
|
308
333
|
# Measure
|
309
334
|
@adapter.metrics.time('sdk.' + calling_method, latency) unless multiple
|
310
335
|
rescue StandardError => error
|
311
|
-
|
336
|
+
@config.log_found_exception(__method__.to_s, error)
|
312
337
|
|
313
338
|
store_impression(split_name, matching_key, bucketing_key, control_treatment, store_impressions, attributes)
|
314
339
|
|
315
|
-
return
|
340
|
+
return parsed_control_exception
|
316
341
|
end
|
317
342
|
|
318
343
|
parsed_treatment(multiple, treatment_data)
|
@@ -321,5 +346,10 @@ module SplitIoClient
|
|
321
346
|
def variable_size(value)
|
322
347
|
value.is_a?(String) ? value.length : 0
|
323
348
|
end
|
349
|
+
|
350
|
+
def ready?
|
351
|
+
return @sdk_blocker.ready? if @sdk_blocker
|
352
|
+
true
|
353
|
+
end
|
324
354
|
end
|
325
355
|
end
|
@@ -7,17 +7,21 @@ module SplitIoClient
|
|
7
7
|
class Client
|
8
8
|
RUBY_ENCODING = '1.9'.respond_to?(:force_encoding)
|
9
9
|
|
10
|
+
def initialize(config)
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
10
14
|
def get_api(url, api_key, params = {})
|
11
15
|
api_client.get(url, params) do |req|
|
12
16
|
req.headers = common_headers(api_key).merge('Accept-Encoding' => 'gzip')
|
13
17
|
|
14
|
-
req.options[:timeout] =
|
15
|
-
req.options[:open_timeout] =
|
18
|
+
req.options[:timeout] = @config.read_timeout
|
19
|
+
req.options[:open_timeout] = @config.connection_timeout
|
16
20
|
|
17
|
-
|
21
|
+
@config.split_logger.log_if_debug("GET #{url} proxy: #{api_client.proxy}")
|
18
22
|
end
|
19
23
|
rescue StandardError => e
|
20
|
-
|
24
|
+
@config.logger.warn("#{e}\nURL:#{url}\nparams:#{params}")
|
21
25
|
raise e, 'Split SDK failed to connect to backend to retrieve information', e.backtrace
|
22
26
|
end
|
23
27
|
|
@@ -29,14 +33,14 @@ module SplitIoClient
|
|
29
33
|
|
30
34
|
req.body = data.to_json
|
31
35
|
|
32
|
-
req.options[:timeout] =
|
33
|
-
req.options[:open_timeout] =
|
36
|
+
req.options[:timeout] = @config.read_timeout
|
37
|
+
req.options[:open_timeout] = @config.connection_timeout
|
34
38
|
|
35
|
-
|
36
|
-
|
39
|
+
@config.split_logger.log_if_transport("POST #{url} #{req.body}")
|
40
|
+
@config.split_logger.log_if_debug("POST #{url}")
|
37
41
|
end
|
38
42
|
rescue StandardError => e
|
39
|
-
|
43
|
+
@config.logger.warn("#{e}\nURL:#{url}\ndata:#{data}\nparams:#{params}")
|
40
44
|
raise e, 'Split SDK failed to connect to backend to post information', e.backtrace
|
41
45
|
end
|
42
46
|
|
@@ -73,15 +77,15 @@ module SplitIoClient
|
|
73
77
|
def common_headers(api_key)
|
74
78
|
{
|
75
79
|
'Authorization' => "Bearer #{api_key}",
|
76
|
-
'SplitSDKVersion' => "#{
|
77
|
-
'SplitSDKMachineName' =>
|
78
|
-
'SplitSDKMachineIP' =>
|
80
|
+
'SplitSDKVersion' => "#{@config.language}-#{@config.version}",
|
81
|
+
'SplitSDKMachineName' => @config.machine_name,
|
82
|
+
'SplitSDKMachineIP' => @config.machine_ip,
|
79
83
|
'Referer' => referer
|
80
84
|
}
|
81
85
|
end
|
82
86
|
|
83
87
|
def referer
|
84
|
-
result = "#{
|
88
|
+
result = "#{@config.language}-#{@config.version}"
|
85
89
|
|
86
90
|
result = "#{result}::#{SplitIoClient::SplitConfig.machine_hostname}" unless SplitIoClient::SplitConfig.machine_hostname == 'localhost'
|
87
91
|
|
@@ -3,19 +3,20 @@
|
|
3
3
|
module SplitIoClient
|
4
4
|
module Api
|
5
5
|
class Events < Client
|
6
|
-
def initialize(api_key)
|
6
|
+
def initialize(api_key, config)
|
7
|
+
super(config)
|
7
8
|
@api_key = api_key
|
8
9
|
end
|
9
10
|
|
10
11
|
def post(events)
|
11
12
|
if events.empty?
|
12
|
-
|
13
|
+
@config.split_logger.log_if_debug('No events to report')
|
13
14
|
return
|
14
15
|
end
|
15
16
|
|
16
|
-
events.each_slice(
|
17
|
+
events.each_slice(@config.events_queue_size) do |events_slice|
|
17
18
|
response = post_api(
|
18
|
-
"#{
|
19
|
+
"#{@config.events_uri}/events/bulk",
|
19
20
|
@api_key,
|
20
21
|
events_slice.map { |event| formatted_event(event[:e]) },
|
21
22
|
'SplitSDKMachineIP' => events_slice[0][:m][:i],
|
@@ -24,9 +25,9 @@ module SplitIoClient
|
|
24
25
|
)
|
25
26
|
|
26
27
|
if response.success?
|
27
|
-
|
28
|
+
@config.split_logger.log_if_debug("Events reported: #{events_slice.size}")
|
28
29
|
else
|
29
|
-
|
30
|
+
@config.logger.error("Unexpected status code while posting events: #{response.status}." \
|
30
31
|
' - Check your API key and base URI')
|
31
32
|
raise 'Split SDK failed to connect to backend to post events'
|
32
33
|
end
|
@@ -3,23 +3,24 @@
|
|
3
3
|
module SplitIoClient
|
4
4
|
module Api
|
5
5
|
class Impressions < Client
|
6
|
-
def initialize(api_key)
|
6
|
+
def initialize(api_key, config)
|
7
7
|
@api_key = api_key
|
8
|
+
@config = config
|
8
9
|
end
|
9
10
|
|
10
11
|
def post(impressions)
|
11
12
|
if impressions.empty?
|
12
|
-
|
13
|
+
@config.split_logger.log_if_debug('No impressions to report')
|
13
14
|
return
|
14
15
|
end
|
15
16
|
|
16
17
|
impressions_by_ip(impressions).each do |ip, impressions_ip|
|
17
|
-
response = post_api("#{
|
18
|
+
response = post_api("#{@config.events_uri}/testImpressions/bulk", @api_key, impressions_ip, 'SplitSDKMachineIP' => ip)
|
18
19
|
|
19
20
|
if response.success?
|
20
|
-
|
21
|
+
@config.split_logger.log_if_debug("Impressions reported: #{total_impressions(impressions)}")
|
21
22
|
else
|
22
|
-
|
23
|
+
@config.logger.error("Unexpected status code while posting impressions: #{response.status}." \
|
23
24
|
' - Check your API key and base URI')
|
24
25
|
raise 'Split SDK failed to connect to backend to post impressions'
|
25
26
|
end
|