Skip to content

Commit 9bd41e2

Browse files
authored
Merge pull request #466 from splitio/flagsets-test-integration
Fixed all tests
2 parents b0e92bf + 52f4530 commit 9bd41e2

34 files changed

+464
-175
lines changed

splitio/client/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,10 @@ def _get_feature_flag_names_by_flag_sets(self, flag_sets, method_name):
431431
sanitized_flag_sets = input_validator.validate_flag_sets(flag_sets, method_name)
432432
feature_flags_by_set = self._split_storage.get_feature_flags_by_sets(sanitized_flag_sets)
433433
if feature_flags_by_set is None:
434-
_LOGGER.warning("%s: Fetching feature flags for flag set %s encountered an error, skipping this flag set." % (method_name, flag_sets))
434+
_LOGGER.warning("Fetching feature flags for flag set %s encountered an error, skipping this flag set." % (flag_sets))
435435
return []
436436
return feature_flags_by_set
437437

438-
439438
def _build_impression( # pylint: disable=too-many-arguments
440439
self,
441440
matching_key,

splitio/client/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,6 @@ def sanitize(sdk_key, config):
143143
_LOGGER.warning('metricRefreshRate parameter minimum value is 60 seconds, defaulting to 3600 seconds.')
144144
processed['metricsRefreshRate'] = 3600
145145

146-
processed['flagSetsFilter'] = validate_flag_sets(processed['flagSetsFilter'], 'SDK Config') if processed['flagSetsFilter'] is not None else None
146+
processed['flagSetsFilter'] = sorted(validate_flag_sets(processed['flagSetsFilter'], 'SDK Config')) if processed['flagSetsFilter'] is not None else None
147147

148148
return processed

splitio/client/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def _build_localhost_factory(cfg):
600600
telemetry_evaluation_producer = telemetry_producer.get_telemetry_evaluation_producer()
601601

602602
storages = {
603-
'splits': InMemorySplitStorage(),
603+
'splits': InMemorySplitStorage(cfg['flagSetsFilter'] if cfg['flagSetsFilter'] is not None else []),
604604
'segments': InMemorySegmentStorage(), # not used, just to avoid possible future errors.
605605
'impressions': LocalhostImpressionsStorage(),
606606
'events': LocalhostEventsStorage(),

splitio/client/input_validator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def _check_string_not_empty(value, name, operation):
8080
return True
8181

8282

83+
8384
def _check_string_matches(value, operation, pattern, name, length):
8485
"""
8586
Check if value is adhere to a regular expression passed.

splitio/engine/telemetry.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,27 @@ def pop_formatted_stats(self):
222222
exceptions = self.pop_exceptions()['methodExceptions']
223223
latencies = self.pop_latencies()['methodLatencies']
224224
return {
225-
'mE': {'t': exceptions['treatment'],
226-
'ts': exceptions['treatments'],
227-
'tc': exceptions['treatment_with_config'],
228-
'tcs': exceptions['treatments_with_config'],
229-
'tr': exceptions['track']
225+
'mE': {
226+
't': exceptions['treatment'],
227+
'ts': exceptions['treatments'],
228+
'tc': exceptions['treatment_with_config'],
229+
'tcs': exceptions['treatments_with_config'],
230+
'tf': exceptions['treatments_by_flag_set'],
231+
'tfs': exceptions['treatments_by_flag_sets'],
232+
'tcf': exceptions['treatments_with_config_by_flag_set'],
233+
'tcfs': exceptions['treatments_with_config_by_flag_sets'],
234+
'tr': exceptions['track']
230235
},
231-
'mL': {'t': latencies['treatment'],
232-
'ts': latencies['treatments'],
233-
'tc': latencies['treatment_with_config'],
234-
'tcs': latencies['treatments_with_config'],
235-
'tr': latencies['track']
236+
'mL': {
237+
't': latencies['treatment'],
238+
'ts': latencies['treatments'],
239+
'tc': latencies['treatment_with_config'],
240+
'tcs': latencies['treatments_with_config'],
241+
'tf': latencies['treatments_by_flag_set'],
242+
'tfs': latencies['treatments_by_flag_sets'],
243+
'tcf': latencies['treatments_with_config_by_flag_set'],
244+
'tcfs': latencies['treatments_with_config_by_flag_sets'],
245+
'tr': latencies['track']
236246
},
237247
}
238248

splitio/models/splits.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def to_json(self):
183183
'algo': self.algo.value,
184184
'conditions': [c.to_json() for c in self.conditions],
185185
'configurations': self._configurations,
186-
'sets': self._sets
186+
'sets': list(self._sets)
187187
}
188188

189189
def to_split_view(self):
@@ -200,7 +200,7 @@ def to_split_view(self):
200200
list(set(part.treatment for cond in self.conditions for part in cond.partitions)),
201201
self.change_number,
202202
self._configurations if self._configurations is not None else {},
203-
self._sets if self._sets is not None else []
203+
list(self._sets) if self._sets is not None else []
204204
)
205205

206206
def local_kill(self, default_treatment, change_number):
@@ -250,5 +250,5 @@ def from_raw(raw_split):
250250
traffic_allocation=raw_split.get('trafficAllocation'),
251251
traffic_allocation_seed=raw_split.get('trafficAllocationSeed'),
252252
configurations=raw_split.get('configurations'),
253-
sets=raw_split.get('sets')
253+
sets=set(raw_split.get('sets')) if raw_split.get('sets') is not None else []
254254
)

splitio/models/telemetry.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class _ConfigParams(Enum):
4141
EVENTS_QUEUE_SIZE = 'eventsQueueSize'
4242
IMPRESSIONS_MODE = 'impressionsMode'
4343
IMPRESSIONS_LISTENER = 'impressionListener'
44-
FLAG_SETS = 'flagSetsFilter'
4544

4645
class _ExtraConfig(Enum):
4746
"""Extra config constants"""
@@ -829,7 +828,6 @@ def record_config(self, config, extra_config):
829828
self._impressions_mode = self._get_impressions_mode(config[_ConfigParams.IMPRESSIONS_MODE.value])
830829
self._impression_listener = True if config[_ConfigParams.IMPRESSIONS_LISTENER.value] is not None else False
831830
self._http_proxy = self._check_if_proxy_detected()
832-
self._flag_sets = len(config[_ConfigParams.FLAG_SETS.value]) if config[_ConfigParams.FLAG_SETS.value] is not None else 0
833831

834832
def record_active_and_redundant_factories(self, active_factory_count, redundant_factory_count):
835833
with self._lock:

splitio/push/manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def _trigger_connection_flow(self):
143143
self._feedback_loop.put(Status.PUSH_RETRYABLE_ERROR)
144144
return
145145

146-
if not token.push_enabled:
146+
147+
if token is None or not token.push_enabled:
147148
self._feedback_loop.put(Status.PUSH_NONRETRYABLE_ERROR)
148149
return
149150
self._telemetry_runtime_producer.record_token_refreshes()

splitio/storage/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Base storage interfaces."""
22
import abc
3+
import threading
34

45

56
class SplitStorage(object, metaclass=abc.ABCMeta):
@@ -315,3 +316,42 @@ def record_bur_time_out(self):
315316
316317
"""
317318
pass
319+
320+
class FlagSetsFilter(object):
321+
"""Config Flagsets Filter storage."""
322+
323+
def __init__(self, flag_sets=[]):
324+
"""Constructor."""
325+
self.flag_sets = set(flag_sets)
326+
self.should_filter = any(flag_sets)
327+
328+
def set_exist(self, flag_set):
329+
"""
330+
Check if a flagset exist in flagset filter
331+
332+
:param flag_set: set name
333+
:type flag_set: str
334+
335+
:rtype: bool
336+
"""
337+
if not self.should_filter:
338+
return True
339+
if not isinstance(flag_set, str) or flag_set == '':
340+
return False
341+
342+
return any(self.flag_sets.intersection(set([flag_set])))
343+
344+
def intersect(self, flag_sets):
345+
"""
346+
Check if a set exist in config flagset filter
347+
348+
:param flag_set: set of flagsets
349+
:type flag_set: set
350+
351+
:rtype: bool
352+
"""
353+
if not self.should_filter:
354+
return True
355+
if not isinstance(flag_sets, set) or len(flag_sets) == 0:
356+
return False
357+
return any(self.flag_sets.intersection(flag_sets))

splitio/storage/inmemmory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from splitio.models.segments import Segment
88
from splitio.models.telemetry import HTTPErrors, HTTPLatencies, MethodExceptions, MethodLatencies, LastSynchronization, StreamingEvents, TelemetryConfig, TelemetryCounters, CounterConstants
9-
from splitio.models.flag_sets import FlagSets, FlagSetsFilter
9+
from splitio.storage import FlagSetsFilter
1010
from splitio.storage import SplitStorage, SegmentStorage, ImpressionStorage, EventStorage, TelemetryStorage
1111

1212
MAX_SIZE_BYTES = 5 * 1024 * 1024

0 commit comments

Comments
 (0)