splitclient-rb 6.4.1 → 7.0.0
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 +4 -4
- data/CHANGES.txt +10 -1
- data/Detailed-README.md +9 -21
- 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
- data/lib/splitclient-rb.rb +2 -1
- metadata +3 -2
@@ -7,7 +7,8 @@ module SplitIoClient
|
|
7
7
|
class NegationMatcher < Matcher
|
8
8
|
MATCHER_TYPE = 'NEGATION_MATCHER'
|
9
9
|
|
10
|
-
def initialize(matcher = nil)
|
10
|
+
def initialize(logger, matcher = nil)
|
11
|
+
super(logger)
|
11
12
|
@matcher = matcher
|
12
13
|
end
|
13
14
|
|
@@ -19,7 +20,7 @@ module SplitIoClient
|
|
19
20
|
# @return [boolean] evaluation of the negation matcher
|
20
21
|
def match?(args)
|
21
22
|
matches = !@matcher.match?(args)
|
22
|
-
|
23
|
+
@logger.log_if_debug("[NegationMatcherMatcher] Matcher #{@matcher} Arguments #{args} -> #{matches}")
|
23
24
|
matches
|
24
25
|
end
|
25
26
|
|
@@ -6,20 +6,20 @@ module SplitIoClient
|
|
6
6
|
|
7
7
|
attr_reader :attribute
|
8
8
|
|
9
|
-
def initialize(attribute, remote_array)
|
10
|
-
super(attribute, remote_array)
|
9
|
+
def initialize(attribute, remote_array, logger)
|
10
|
+
super(attribute, remote_array, logger)
|
11
11
|
end
|
12
12
|
|
13
13
|
def match?(args)
|
14
14
|
@local_set = local_set(args[:attributes], @attribute)
|
15
15
|
|
16
16
|
if @local_set.empty?
|
17
|
-
|
17
|
+
@logger.log_if_debug('[PartOfSetMatcher] Local Set is empty.')
|
18
18
|
return false
|
19
19
|
end
|
20
20
|
|
21
21
|
matches = @local_set.subset? @remote_set
|
22
|
-
|
22
|
+
@logger.log_if_debug("[PartOfSetMatcher] Local Set #{@local_set} is a subset of #{@remote_set} -> #{matches}")
|
23
23
|
matches
|
24
24
|
end
|
25
25
|
end
|
@@ -10,9 +10,10 @@ module SplitIoClient
|
|
10
10
|
|
11
11
|
protected
|
12
12
|
|
13
|
-
def initialize(attribute, remote_array)
|
13
|
+
def initialize(attribute, remote_array, logger)
|
14
14
|
@attribute = attribute
|
15
15
|
@remote_set = remote_array.to_set
|
16
|
+
@logger = logger
|
16
17
|
end
|
17
18
|
|
18
19
|
def local_set(data, attribute)
|
@@ -6,21 +6,22 @@ module SplitIoClient
|
|
6
6
|
|
7
7
|
attr_reader :attribute
|
8
8
|
|
9
|
-
def initialize(attribute, prefix_list)
|
9
|
+
def initialize(attribute, prefix_list, logger)
|
10
10
|
@attribute = attribute
|
11
11
|
@prefix_list = prefix_list
|
12
|
+
@logger = logger
|
12
13
|
end
|
13
14
|
|
14
15
|
def match?(args)
|
15
16
|
if @prefix_list.empty?
|
16
|
-
|
17
|
+
@logger.log_if_debug('[StartsWithMatcher] Prefix List is empty.')
|
17
18
|
return false
|
18
19
|
end
|
19
20
|
|
20
21
|
value = get_value(args)
|
21
22
|
|
22
23
|
matches = @prefix_list.any? { |prefix| value.to_s.start_with? prefix }
|
23
|
-
|
24
|
+
@logger.log_if_debug("[StartsWithMatcher] #{value} matches any of #{@prefix_list} -> #{matches}")
|
24
25
|
matches
|
25
26
|
end
|
26
27
|
|
@@ -7,7 +7,8 @@ module SplitIoClient
|
|
7
7
|
class UserDefinedSegmentMatcher < Matcher
|
8
8
|
MATCHER_TYPE = 'IN_SEGMENT'
|
9
9
|
|
10
|
-
def initialize(segments_repository, segment_name)
|
10
|
+
def initialize(segments_repository, segment_name, logger)
|
11
|
+
super(logger)
|
11
12
|
@segments_repository = segments_repository
|
12
13
|
@segment_name = segment_name
|
13
14
|
end
|
@@ -20,7 +21,7 @@ module SplitIoClient
|
|
20
21
|
# @return [boolean] evaluation of the key against the segment
|
21
22
|
def match?(args)
|
22
23
|
matches = @segments_repository.in_segment?(@segment_name, args[:value] || args[:matching_key])
|
23
|
-
|
24
|
+
@logger.log_if_debug("[InSegmentMatcher] #{@segment_name} is in segment -> #{matches}")
|
24
25
|
matches
|
25
26
|
end
|
26
27
|
end
|
@@ -9,7 +9,9 @@ module SplitIoClient
|
|
9
9
|
|
10
10
|
attr_reader :attribute
|
11
11
|
|
12
|
-
def initialize(whitelist_data)
|
12
|
+
def initialize(whitelist_data, logger, validator)
|
13
|
+
super(logger)
|
14
|
+
@validator = validator
|
13
15
|
@whitelist = case whitelist_data
|
14
16
|
when Array
|
15
17
|
whitelist_data
|
@@ -26,9 +28,9 @@ module SplitIoClient
|
|
26
28
|
def match?(args)
|
27
29
|
return matches_user_whitelist(args) unless @matcher_type == 'ATTR_WHITELIST'
|
28
30
|
|
29
|
-
|
31
|
+
@logger.log_if_debug('[WhitelistMatcher] evaluating value and attributes.')
|
30
32
|
|
31
|
-
return false unless
|
33
|
+
return false unless @validator.valid_matcher_arguments(args)
|
32
34
|
|
33
35
|
matches_attr_whitelist(args)
|
34
36
|
end
|
@@ -49,14 +51,14 @@ module SplitIoClient
|
|
49
51
|
|
50
52
|
def matches_user_whitelist(args)
|
51
53
|
matches = @whitelist.include?(args[:value] || args[:matching_key])
|
52
|
-
|
54
|
+
@logger.log_if_debug("[WhitelistMatcher] #{@whitelist} include \
|
53
55
|
#{args[:value] || args[:matching_key]} -> #{matches}")
|
54
56
|
matches
|
55
57
|
end
|
56
58
|
|
57
59
|
def matches_attr_whitelist(args)
|
58
60
|
matches = @whitelist.include?(args[:value] || args[:attributes][@attribute.to_sym])
|
59
|
-
|
61
|
+
@logger.log_if_debug("[WhitelistMatcher] #{@whitelist} include \
|
60
62
|
#{args[:value] || args[:attributes][@attribute.to_sym]} -> #{matches}")
|
61
63
|
matches
|
62
64
|
end
|
@@ -11,13 +11,14 @@ module SplitIoClient
|
|
11
11
|
# @returns [object] condition values
|
12
12
|
attr_accessor :data
|
13
13
|
|
14
|
-
def initialize(condition)
|
14
|
+
def initialize(condition, config)
|
15
15
|
@data = condition
|
16
16
|
@partitions = set_partitions
|
17
|
+
@config = config
|
17
18
|
end
|
18
19
|
|
19
20
|
def create_condition_matcher(matchers)
|
20
|
-
CombiningMatcher.new(combiner, matchers) if combiner
|
21
|
+
CombiningMatcher.new(@config.split_logger, combiner, matchers) if combiner
|
21
22
|
end
|
22
23
|
|
23
24
|
#
|
@@ -45,11 +46,11 @@ module SplitIoClient
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def negation_matcher(matcher)
|
48
|
-
NegationMatcher.new(matcher)
|
49
|
+
NegationMatcher.new(@config.split_logger, matcher)
|
49
50
|
end
|
50
51
|
|
51
52
|
def matcher_all_keys(_params)
|
52
|
-
@matcher_all_keys ||= AllKeysMatcher.new
|
53
|
+
@matcher_all_keys ||= AllKeysMatcher.new(@config.split_logger)
|
53
54
|
end
|
54
55
|
|
55
56
|
# returns UserDefinedSegmentMatcher[object]
|
@@ -57,7 +58,7 @@ module SplitIoClient
|
|
57
58
|
matcher = params[:matcher]
|
58
59
|
segment_name = matcher[:userDefinedSegmentMatcherData] && matcher[:userDefinedSegmentMatcherData][:segmentName]
|
59
60
|
|
60
|
-
UserDefinedSegmentMatcher.new(params[:segments_repository], segment_name)
|
61
|
+
UserDefinedSegmentMatcher.new(params[:segments_repository], segment_name, @config.split_logger)
|
61
62
|
end
|
62
63
|
|
63
64
|
# returns WhitelistMatcher[object] the whitelist for this condition in case it has a whitelist matcher
|
@@ -72,7 +73,7 @@ module SplitIoClient
|
|
72
73
|
white_list = (matcher[:whitelistMatcherData])[:whitelist]
|
73
74
|
result = { attribute: attribute, value: white_list }
|
74
75
|
end
|
75
|
-
WhitelistMatcher.new(result)
|
76
|
+
WhitelistMatcher.new(result, @config.split_logger, @config.split_validator)
|
76
77
|
end
|
77
78
|
|
78
79
|
def matcher_equal_to(params)
|
@@ -80,7 +81,7 @@ module SplitIoClient
|
|
80
81
|
attribute = (matcher[:keySelector])[:attribute]
|
81
82
|
value = (matcher[:unaryNumericMatcherData])[:value]
|
82
83
|
data_type = (matcher[:unaryNumericMatcherData])[:dataType]
|
83
|
-
EqualToMatcher.new(attribute: attribute, value: value, data_type: data_type)
|
84
|
+
EqualToMatcher.new({attribute: attribute, value: value, data_type: data_type}, @config.split_logger, @config.split_validator)
|
84
85
|
end
|
85
86
|
|
86
87
|
def matcher_greater_than_or_equal_to(params)
|
@@ -88,7 +89,7 @@ module SplitIoClient
|
|
88
89
|
attribute = (matcher[:keySelector])[:attribute]
|
89
90
|
value = (matcher[:unaryNumericMatcherData])[:value]
|
90
91
|
data_type = (matcher[:unaryNumericMatcherData])[:dataType]
|
91
|
-
GreaterThanOrEqualToMatcher.new(attribute: attribute, value: value, data_type: data_type)
|
92
|
+
GreaterThanOrEqualToMatcher.new({attribute: attribute, value: value, data_type: data_type}, @config.split_logger, @config.split_validator)
|
92
93
|
end
|
93
94
|
|
94
95
|
def matcher_less_than_or_equal_to(params)
|
@@ -96,7 +97,7 @@ module SplitIoClient
|
|
96
97
|
attribute = (matcher[:keySelector])[:attribute]
|
97
98
|
value = (matcher[:unaryNumericMatcherData])[:value]
|
98
99
|
data_type = (matcher[:unaryNumericMatcherData])[:dataType]
|
99
|
-
LessThanOrEqualToMatcher.new(attribute: attribute, value: value, data_type: data_type)
|
100
|
+
LessThanOrEqualToMatcher.new({attribute: attribute, value: value, data_type: data_type}, @config.split_logger, @config.split_validator)
|
100
101
|
end
|
101
102
|
|
102
103
|
def matcher_between(params)
|
@@ -105,76 +106,86 @@ module SplitIoClient
|
|
105
106
|
start_value = (matcher[:betweenMatcherData])[:start]
|
106
107
|
end_value = (matcher[:betweenMatcherData])[:end]
|
107
108
|
data_type = (matcher[:betweenMatcherData])[:dataType]
|
108
|
-
BetweenMatcher.new(attribute: attribute, start_value: start_value, end_value: end_value, data_type: data_type)
|
109
|
+
BetweenMatcher.new({attribute: attribute, start_value: start_value, end_value: end_value, data_type: data_type}, @config.split_logger, @config.split_validator)
|
109
110
|
end
|
110
111
|
|
111
112
|
def matcher_equal_to_set(params)
|
112
113
|
EqualToSetMatcher.new(
|
113
114
|
params[:matcher][:keySelector][:attribute],
|
114
|
-
params[:matcher][:whitelistMatcherData][:whitelist]
|
115
|
+
params[:matcher][:whitelistMatcherData][:whitelist],
|
116
|
+
@config.split_logger
|
115
117
|
)
|
116
118
|
end
|
117
119
|
|
118
120
|
def matcher_contains_any_of_set(params)
|
119
121
|
ContainsAnyMatcher.new(
|
120
122
|
params[:matcher][:keySelector][:attribute],
|
121
|
-
params[:matcher][:whitelistMatcherData][:whitelist]
|
123
|
+
params[:matcher][:whitelistMatcherData][:whitelist],
|
124
|
+
@config.split_logger
|
122
125
|
)
|
123
126
|
end
|
124
127
|
|
125
128
|
def matcher_contains_all_of_set(params)
|
126
129
|
ContainsAllMatcher.new(
|
127
130
|
params[:matcher][:keySelector][:attribute],
|
128
|
-
params[:matcher][:whitelistMatcherData][:whitelist]
|
131
|
+
params[:matcher][:whitelistMatcherData][:whitelist],
|
132
|
+
@config.split_logger
|
129
133
|
)
|
130
134
|
end
|
131
135
|
|
132
136
|
def matcher_part_of_set(params)
|
133
137
|
PartOfSetMatcher.new(
|
134
138
|
params[:matcher][:keySelector][:attribute],
|
135
|
-
params[:matcher][:whitelistMatcherData][:whitelist]
|
139
|
+
params[:matcher][:whitelistMatcherData][:whitelist],
|
140
|
+
@config.split_logger
|
136
141
|
)
|
137
142
|
end
|
138
143
|
|
139
144
|
def matcher_starts_with(params)
|
140
145
|
StartsWithMatcher.new(
|
141
146
|
params[:matcher][:keySelector][:attribute],
|
142
|
-
params[:matcher][:whitelistMatcherData][:whitelist]
|
147
|
+
params[:matcher][:whitelistMatcherData][:whitelist],
|
148
|
+
@config.split_logger
|
143
149
|
)
|
144
150
|
end
|
145
151
|
|
146
152
|
def matcher_ends_with(params)
|
147
153
|
EndsWithMatcher.new(
|
148
154
|
params[:matcher][:keySelector][:attribute],
|
149
|
-
params[:matcher][:whitelistMatcherData][:whitelist]
|
155
|
+
params[:matcher][:whitelistMatcherData][:whitelist],
|
156
|
+
@config.split_logger
|
150
157
|
)
|
151
158
|
end
|
152
159
|
|
153
160
|
def matcher_contains_string(params)
|
154
161
|
ContainsMatcher.new(
|
155
162
|
params[:matcher][:keySelector][:attribute],
|
156
|
-
params[:matcher][:whitelistMatcherData][:whitelist]
|
163
|
+
params[:matcher][:whitelistMatcherData][:whitelist],
|
164
|
+
@config.split_logger, @config.split_validator
|
157
165
|
)
|
158
166
|
end
|
159
167
|
|
160
168
|
def matcher_in_split_treatment(params)
|
161
169
|
DependencyMatcher.new(
|
162
170
|
params[:matcher][:dependencyMatcherData][:split],
|
163
|
-
params[:matcher][:dependencyMatcherData][:treatments]
|
171
|
+
params[:matcher][:dependencyMatcherData][:treatments],
|
172
|
+
@config.split_logger
|
164
173
|
)
|
165
174
|
end
|
166
175
|
|
167
176
|
def matcher_equal_to_boolean(params)
|
168
177
|
EqualToBooleanMatcher.new(
|
169
178
|
params[:matcher][:keySelector][:attribute],
|
170
|
-
params[:matcher][:booleanMatcherData]
|
179
|
+
params[:matcher][:booleanMatcherData],
|
180
|
+
@config.split_logger
|
171
181
|
)
|
172
182
|
end
|
173
183
|
|
174
184
|
def matcher_matches_string(params)
|
175
185
|
MatchesStringMatcher.new(
|
176
186
|
params[:matcher][:keySelector][:attribute],
|
177
|
-
params[:matcher][:stringMatcherData]
|
187
|
+
params[:matcher][:stringMatcherData],
|
188
|
+
@config.split_logger
|
178
189
|
)
|
179
190
|
end
|
180
191
|
|
@@ -2,10 +2,11 @@ module SplitIoClient
|
|
2
2
|
module Engine
|
3
3
|
module Parser
|
4
4
|
class Evaluator
|
5
|
-
def initialize(segments_repository, splits_repository, multiple = false)
|
5
|
+
def initialize(segments_repository, splits_repository, config, multiple = false)
|
6
6
|
@splits_repository = splits_repository
|
7
7
|
@segments_repository = segments_repository
|
8
8
|
@multiple = multiple
|
9
|
+
@config = config
|
9
10
|
@cache = {}
|
10
11
|
end
|
11
12
|
|
@@ -48,7 +49,7 @@ module SplitIoClient
|
|
48
49
|
splitter = Splitter.new
|
49
50
|
|
50
51
|
split[:conditions].each do |c|
|
51
|
-
condition = SplitIoClient::Condition.new(c)
|
52
|
+
condition = SplitIoClient::Condition.new(c, @config)
|
52
53
|
|
53
54
|
next if condition.empty?
|
54
55
|
|
@@ -31,7 +31,8 @@ module SplitIoClient
|
|
31
31
|
impressions_repository,
|
32
32
|
metrics_repository,
|
33
33
|
events_repository,
|
34
|
-
sdk_blocker
|
34
|
+
sdk_blocker,
|
35
|
+
config
|
35
36
|
)
|
36
37
|
@api_key = api_key
|
37
38
|
@splits_repository = splits_repository
|
@@ -41,8 +42,9 @@ module SplitIoClient
|
|
41
42
|
@events_repository = events_repository
|
42
43
|
@metrics = Metrics.new(100, @metrics_repository)
|
43
44
|
@sdk_blocker = sdk_blocker
|
45
|
+
@config = config
|
44
46
|
|
45
|
-
start_standalone_components if
|
47
|
+
start_standalone_components if @config.standalone?
|
46
48
|
end
|
47
49
|
|
48
50
|
def start_standalone_components
|
@@ -55,27 +57,27 @@ module SplitIoClient
|
|
55
57
|
|
56
58
|
# Starts thread which loops constantly and stores splits in the splits_repository of choice
|
57
59
|
def split_store
|
58
|
-
SplitStore.new(@splits_repository, @api_key, @metrics, @sdk_blocker).call
|
60
|
+
SplitStore.new(@splits_repository, @api_key, @metrics, @config, @sdk_blocker).call
|
59
61
|
end
|
60
62
|
|
61
63
|
# Starts thread which loops constantly and stores segments in the segments_repository of choice
|
62
64
|
def segment_store
|
63
|
-
SegmentStore.new(@segments_repository, @api_key, @metrics, @sdk_blocker).call
|
65
|
+
SegmentStore.new(@segments_repository, @api_key, @metrics, @config, @sdk_blocker).call
|
64
66
|
end
|
65
67
|
|
66
68
|
# Starts thread which loops constantly and sends impressions to the Split API
|
67
69
|
def impressions_sender
|
68
|
-
ImpressionsSender.new(@impressions_repository, @api_key).call
|
70
|
+
ImpressionsSender.new(@impressions_repository, @api_key, @config).call
|
69
71
|
end
|
70
72
|
|
71
73
|
# Starts thread which loops constantly and sends metrics to the Split API
|
72
74
|
def metrics_sender
|
73
|
-
MetricsSender.new(@metrics_repository, @api_key).call
|
75
|
+
MetricsSender.new(@metrics_repository, @api_key, @config).call
|
74
76
|
end
|
75
77
|
|
76
78
|
# Starts thread which loops constantly and sends events to the Split API
|
77
79
|
def events_sender
|
78
|
-
EventsSender.new(@events_repository).call
|
80
|
+
EventsSender.new(@events_repository, @config).call
|
79
81
|
end
|
80
82
|
end
|
81
83
|
end
|
@@ -2,11 +2,12 @@ module SplitIoClient
|
|
2
2
|
class LocalhostSplitFactory
|
3
3
|
attr_reader :client, :manager
|
4
4
|
|
5
|
-
def initialize(splits_file, reload_rate = nil, logger = nil)
|
5
|
+
def initialize(splits_file, config, reload_rate = nil, logger = nil)
|
6
6
|
@splits_file = splits_file
|
7
7
|
@reload_rate = reload_rate
|
8
|
+
@config = config
|
8
9
|
|
9
|
-
@client = LocalhostSplitClient.new(@splits_file, @reload_rate)
|
10
|
+
@client = LocalhostSplitClient.new(@splits_file, @config, @reload_rate)
|
10
11
|
@manager = LocalhostSplitManager.new(@splits_file, @reload_rate)
|
11
12
|
end
|
12
13
|
end
|
@@ -6,10 +6,12 @@ module SplitIoClient
|
|
6
6
|
# @param api_key [String] the API key for your split account
|
7
7
|
#
|
8
8
|
# @return [SplitIoManager] split.io client instance
|
9
|
-
def initialize(api_key, adapter = nil, splits_repository = nil)
|
9
|
+
def initialize(api_key, adapter = nil, splits_repository = nil, sdk_blocker, config)
|
10
10
|
@localhost_mode_features = []
|
11
11
|
@splits_repository = splits_repository
|
12
12
|
@adapter = adapter
|
13
|
+
@sdk_blocker = sdk_blocker
|
14
|
+
@config = config
|
13
15
|
end
|
14
16
|
|
15
17
|
#
|
@@ -17,7 +19,12 @@ module SplitIoClient
|
|
17
19
|
#
|
18
20
|
# @returns [object] array of splits
|
19
21
|
def splits
|
20
|
-
return [] if
|
22
|
+
return [] if !@config.valid_mode || @splits_repository.nil?
|
23
|
+
|
24
|
+
if !ready?
|
25
|
+
@config.logger.error("splits: the SDK is not ready, the operation cannot be executed")
|
26
|
+
return []
|
27
|
+
end
|
21
28
|
|
22
29
|
@splits_repository.splits.each_with_object([]) do |(name, split), memo|
|
23
30
|
split_view = build_split_view(name, split)
|
@@ -33,7 +40,12 @@ module SplitIoClient
|
|
33
40
|
#
|
34
41
|
# @returns [object] array of split names (String)
|
35
42
|
def split_names
|
36
|
-
return [] if
|
43
|
+
return [] if !@config.valid_mode || @splits_repository.nil?
|
44
|
+
|
45
|
+
if !ready?
|
46
|
+
@config.logger.error("split_names: the SDK is not ready, the operation cannot be executed")
|
47
|
+
return []
|
48
|
+
end
|
37
49
|
|
38
50
|
@splits_repository.split_names
|
39
51
|
end
|
@@ -43,22 +55,38 @@ module SplitIoClient
|
|
43
55
|
#
|
44
56
|
# @returns a split view
|
45
57
|
def split(split_name)
|
46
|
-
return unless
|
58
|
+
return unless @config.valid_mode && @splits_repository && @config.split_validator.valid_split_parameters(split_name)
|
59
|
+
|
60
|
+
if !ready?
|
61
|
+
@config.logger.error("split: the SDK is not ready, the operation cannot be executed")
|
62
|
+
return
|
63
|
+
end
|
47
64
|
|
48
65
|
sanitized_split_name= split_name.to_s.strip
|
49
66
|
|
50
67
|
if split_name.to_s != sanitized_split_name
|
51
|
-
|
68
|
+
@config.logger.warn("split: split_name #{split_name} has extra whitespace, trimming")
|
52
69
|
split_name = sanitized_split_name
|
53
70
|
end
|
54
71
|
|
55
72
|
split = @splits_repository.get_split(split_name)
|
56
73
|
|
74
|
+
if ready? && split.nil?
|
75
|
+
@config.logger.warn("split: you passed #{split_name} " \
|
76
|
+
'that does not exist in this environment, please double check what Splits exist in the web console')
|
77
|
+
end
|
78
|
+
|
57
79
|
return if split.nil? || Engine::Models::Split.archived?(split)
|
58
80
|
|
59
81
|
build_split_view(split_name, split)
|
60
82
|
end
|
61
83
|
|
84
|
+
def block_until_ready(time = nil)
|
85
|
+
@sdk_blocker.block(time) if @sdk_blocker && !@sdk_blocker.ready?
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
62
90
|
def build_split_view(name, split)
|
63
91
|
return {} unless split
|
64
92
|
|
@@ -79,5 +107,11 @@ module SplitIoClient
|
|
79
107
|
configs: split[:configurations] || {}
|
80
108
|
}
|
81
109
|
end
|
110
|
+
|
111
|
+
# move to blocker, alongside block until ready to avoid duplication
|
112
|
+
def ready?
|
113
|
+
return @sdk_blocker.ready? if @sdk_blocker
|
114
|
+
true
|
115
|
+
end
|
82
116
|
end
|
83
117
|
end
|
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
module SplitIoClient
|
4
4
|
class RedisMetricsFixer
|
5
|
-
def initialize(metrics_repository)
|
5
|
+
def initialize(metrics_repository, config)
|
6
6
|
@metrics_repository = metrics_repository
|
7
|
+
@config = config
|
7
8
|
end
|
8
9
|
|
9
10
|
def call
|
10
|
-
return if ENV['SPLITCLIENT_ENV'] == 'test' ||
|
11
|
+
return if ENV['SPLITCLIENT_ENV'] == 'test' || @config.mode == :standalone
|
11
12
|
|
12
13
|
fixer_thread
|
13
14
|
|
@@ -23,11 +24,11 @@ module SplitIoClient
|
|
23
24
|
def fixer_thread
|
24
25
|
Thread.new do
|
25
26
|
begin
|
26
|
-
|
27
|
+
@config.logger.info('Starting redis metrics fixer')
|
27
28
|
|
28
29
|
@metrics_repository.fix_latencies
|
29
30
|
rescue StandardError => error
|
30
|
-
|
31
|
+
@config.log_found_exception(__method__.to_s, error)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -2,15 +2,6 @@ require 'logger'
|
|
2
2
|
require 'socket'
|
3
3
|
|
4
4
|
module SplitIoClient
|
5
|
-
|
6
|
-
class << self
|
7
|
-
attr_accessor :configuration
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.configure(opts={})
|
11
|
-
self.configuration ||= SplitConfig.new(opts)
|
12
|
-
end
|
13
|
-
|
14
5
|
#
|
15
6
|
# This class manages configuration options for the split client library.
|
16
7
|
# If not custom configuration is required the default configuration values will be used
|
@@ -68,9 +59,7 @@ module SplitIoClient
|
|
68
59
|
@logger = opts[:logger] || SplitConfig.default_logger
|
69
60
|
@debug_enabled = opts[:debug_enabled] || SplitConfig.default_debug
|
70
61
|
@transport_debug_enabled = opts[:transport_debug_enabled] || SplitConfig.default_debug
|
71
|
-
@block_until_ready =
|
72
|
-
|
73
|
-
@logger.warn 'no ready parameter has been set - incorrect control treatments could be logged' if block_until_ready == 0 && !mode.equal?(:consumer)
|
62
|
+
@block_until_ready = SplitConfig.default_block_until_ready
|
74
63
|
|
75
64
|
@machine_name = opts[:machine_name] || SplitConfig.machine_hostname
|
76
65
|
@machine_ip = opts[:machine_ip] || SplitConfig.machine_ip
|
@@ -96,7 +85,8 @@ module SplitIoClient
|
|
96
85
|
opts[:cache_adapter] || SplitConfig.default_cache_adapter, :queue_adapter, @events_queue_size, @redis_url
|
97
86
|
)
|
98
87
|
@valid_mode = true
|
99
|
-
|
88
|
+
@split_logger = SplitIoClient::SplitLogger.new(self)
|
89
|
+
@split_validator = SplitIoClient::Validators.new(self)
|
100
90
|
startup_log
|
101
91
|
end
|
102
92
|
|
@@ -160,6 +150,21 @@ module SplitIoClient
|
|
160
150
|
# @return [Logger] The configured logger
|
161
151
|
attr_accessor :logger
|
162
152
|
|
153
|
+
#
|
154
|
+
# The split logger. The client library uses the split logger
|
155
|
+
# to use common functions around the logger
|
156
|
+
#
|
157
|
+
# @return [SplitLogger] The configured logger
|
158
|
+
attr_accessor :split_logger
|
159
|
+
|
160
|
+
|
161
|
+
#
|
162
|
+
# The split validator. The client library uses the split validator
|
163
|
+
# to validate inputs accross the sdk
|
164
|
+
#
|
165
|
+
# @return [SplitValidator] The validator
|
166
|
+
attr_accessor :split_validator
|
167
|
+
|
163
168
|
#
|
164
169
|
# The boolean that represents the state of the debug log level
|
165
170
|
#
|
@@ -343,7 +348,7 @@ module SplitIoClient
|
|
343
348
|
if defined?(Rails) && Rails.logger
|
344
349
|
Rails.logger
|
345
350
|
elsif ENV['SPLITCLIENT_ENV'] == 'test'
|
346
|
-
Logger.new('/dev/null')
|
351
|
+
Logger.new('/dev/null')
|
347
352
|
else
|
348
353
|
Logger.new($stdout)
|
349
354
|
end
|
@@ -375,6 +380,14 @@ module SplitIoClient
|
|
375
380
|
'SPLITIO'
|
376
381
|
end
|
377
382
|
|
383
|
+
#
|
384
|
+
# The default block until ready value
|
385
|
+
#
|
386
|
+
# @return [int]
|
387
|
+
def self.default_block_until_ready
|
388
|
+
15
|
389
|
+
end
|
390
|
+
|
378
391
|
#
|
379
392
|
# The default transport_debug_enabled value
|
380
393
|
#
|
@@ -429,6 +442,14 @@ module SplitIoClient
|
|
429
442
|
@logger.info("Loaded cache class: #{@cache_adapter.class}")
|
430
443
|
end
|
431
444
|
|
445
|
+
def standalone?
|
446
|
+
@mode.equal?(:standalone)
|
447
|
+
end
|
448
|
+
|
449
|
+
def consumer?
|
450
|
+
@mode.equal?(:consumer)
|
451
|
+
end
|
452
|
+
|
432
453
|
#
|
433
454
|
# gets the hostname where the sdk gem is running
|
434
455
|
#
|