Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
9.0.0 (Apr 21, 2021)
- BREAKING CHANGE: Deprecated Python2.
9.0.0 (Apr 30, 2021)
- BREAKING CHANGE: Removed splitSdkMachineIp and splitSdkMachineName configs.
- BREAKING CHANGE: Deprecated uWSGI local cache.
- BREAKING CHANGE: Deprecated Python2 support.
- Removed six, future and futures libs for compatibility between Python2 and Python3.
- Updated strings encoding to utf-8 by default for Redis.

Expand Down
5 changes: 0 additions & 5 deletions splitio/client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
DEFAULT_CONFIG = {
'operationMode': 'in-memory',
'connectionTimeout': 1500,
'splitSdkMachineName': None,
'splitSdkMachineIp': None,
'streamingEnabled': True,
'featuresRefreshRate': 30,
'segmentsRefreshRate': 30,
Expand Down Expand Up @@ -74,9 +72,6 @@ def _parse_operation_mode(apikey, config):
if 'redisHost' in config or 'redisSentinels' in config:
return 'redis-consumer'

if 'uwsgiClient' in config:
return 'uwsgi-consumer'

return 'inmemory-standalone'


Expand Down
36 changes: 0 additions & 36 deletions splitio/client/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
from splitio.storage.adapters import redis
from splitio.storage.redis import RedisSplitStorage, RedisSegmentStorage, RedisImpressionsStorage, \
RedisEventsStorage, RedisTelemetryStorage
from splitio.storage.adapters.uwsgi_cache import get_uwsgi
from splitio.storage.uwsgi import UWSGIEventStorage, UWSGIImpressionStorage, UWSGISegmentStorage, \
UWSGISplitStorage, UWSGITelemetryStorage

# APIs
from splitio.api.client import HttpClient
Expand Down Expand Up @@ -420,36 +417,6 @@ def _build_redis_factory(api_key, cfg):
)


def _build_uwsgi_factory(api_key, cfg):
"""Build and return a split factory with redis-based storage."""
sdk_metadata = util.get_metadata(cfg)
uwsgi_adapter = get_uwsgi()
storages = {
'splits': UWSGISplitStorage(uwsgi_adapter),
'segments': UWSGISegmentStorage(uwsgi_adapter),
'impressions': UWSGIImpressionStorage(uwsgi_adapter),
'events': UWSGIEventStorage(uwsgi_adapter),
'telemetry': UWSGITelemetryStorage(uwsgi_adapter)
}
recorder = StandardRecorder(
ImpressionsManager(cfg['impressionsMode'], True,
_wrap_impression_listener(cfg['impressionListener'], sdk_metadata)),
storages['telemetry'],
storages['events'],
storages['impressions'],
)
_LOGGER.warning(
"Beware: uwsgi-cache based operation mode is soon to be deprecated. Please consider " +
"redis if you need a centralized point of syncrhonization, or in-memory (with preforking " +
"support enabled) if running uwsgi with a master and several http workers)")
return SplitFactory(
api_key,
storages,
cfg['labelsEnabled'],
recorder,
)


def _build_localhost_factory(cfg):
"""Build and return a localhost factory for testing/development purposes."""
storages = {
Expand Down Expand Up @@ -521,9 +488,6 @@ def get_factory(api_key, **kwargs):
if config['operationMode'] == 'redis-consumer':
return _build_redis_factory(api_key, config)

if config['operationMode'] == 'uwsgi-consumer':
return _build_uwsgi_factory(api_key, config)

return _build_in_memory_factory(
api_key,
config,
Expand Down
1 change: 0 additions & 1 deletion splitio/client/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""General purpose SDK utilities."""

import inspect
import socket
from collections import namedtuple
from splitio.version import __version__
Expand Down
4 changes: 2 additions & 2 deletions splitio/engine/cache/lru.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
DEFAULT_MAX_SIZE = 5000


class SimpleLruCache(object): #pylint: disable=too-many-instance-attributes
class SimpleLruCache(object): # pylint: disable=too-many-instance-attributes
"""
Key/Value local memory cache. with expiration & LRU eviction.

Expand All @@ -21,7 +21,7 @@ class SimpleLruCache(object): #pylint: disable=too-many-instance-attributes
None <---next--- || node || <---next--- || node || ... <---next--- || node ||
"""

class _Node(object): #pylint: disable=too-few-public-methods
class _Node(object): # pylint: disable=too-few-public-methods
"""Links to previous an next items in the circular list."""

def __init__(self, key, value, previous_element, next_element):
Expand Down
1 change: 0 additions & 1 deletion splitio/engine/impressions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Split evaluator module."""
import logging
import threading
from collections import defaultdict, namedtuple
from enum import Enum
Expand Down
5 changes: 5 additions & 0 deletions splitio/models/datatypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Datatypes converters for matchers."""


def ts_truncate_seconds(timestamp):
"""
Set seconds to zero in a timestamp.
Expand All @@ -12,6 +13,7 @@ def ts_truncate_seconds(timestamp):
"""
return timestamp - (timestamp % 60)


def ts_truncate_time(timestamp):
"""
Set time to zero in a timestamp.
Expand All @@ -24,6 +26,7 @@ def ts_truncate_time(timestamp):
"""
return timestamp - (timestamp % 86400)


def java_ts_to_secs(java_ts):
"""
Convert java timestamp into unix timestamp.
Expand All @@ -36,6 +39,7 @@ def java_ts_to_secs(java_ts):
"""
return java_ts / 1000


def java_ts_truncate_seconds(java_ts):
"""
Set seconds to zero in a timestamp.
Expand All @@ -48,6 +52,7 @@ def java_ts_truncate_seconds(java_ts):
"""
return ts_truncate_seconds(java_ts_to_secs(java_ts))


def java_ts_truncate_time(java_ts):
"""
Set time to zero in a timestamp.
Expand Down
59 changes: 30 additions & 29 deletions splitio/models/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, channel, notification_type, control_type):
self._channel = channel
self._notification_type = Type(notification_type)
self._control_type = Control(control_type)

@property
def channel(self):
return self._channel
Expand Down Expand Up @@ -87,7 +87,7 @@ def change_number(self):
@property
def notification_type(self):
return self._notification_type

@property
def segment_name(self):
return self._segment_name
Expand All @@ -111,7 +111,7 @@ def __init__(self, channel, notification_type, change_number):
self._channel = channel
self._notification_type = Type(notification_type)
self._change_number = change_number

@property
def channel(self):
return self._channel
Expand Down Expand Up @@ -149,23 +149,23 @@ def __init__(self, channel, notification_type, change_number, default_treatment,
self._change_number = change_number
self._default_treatment = default_treatment
self._split_name = split_name

@property
def channel(self):
return self._channel

@property
def change_number(self):
return self._change_number

@property
def default_treatment(self):
return self._default_treatment

@property
def notification_type(self):
return self._notification_type

@property
def split_name(self):
return self._split_name
Expand All @@ -178,25 +178,26 @@ def split_name(self):
Type.CONTROL: lambda c, d: ControlNotification(c, Type.CONTROL, d['controlType'])
}

def wrap_notification(raw_data, channel):
"""
Parse notification from raw notification payload

:param raw_data: data
:type raw_data: str
:param channel: Channel of incoming notification
:type channel: str
"""
try:
if channel is None:
raise ValueError("channel cannot be None.")
raw_data = json.loads(raw_data)
notification_type = Type(raw_data['type'])
mapper = _NOTIFICATION_MAPPERS[notification_type]
return mapper(channel, raw_data)
except ValueError:
raise ValueError("Wrong notification type received.")
except KeyError:
raise KeyError("Could not parse notification.")
except TypeError:
raise TypeError("Wrong JSON format.")
def wrap_notification(raw_data, channel):
"""
Parse notification from raw notification payload

:param raw_data: data
:type raw_data: str
:param channel: Channel of incoming notification
:type channel: str
"""
try:
if channel is None:
raise ValueError("channel cannot be None.")
raw_data = json.loads(raw_data)
notification_type = Type(raw_data['type'])
mapper = _NOTIFICATION_MAPPERS[notification_type]
return mapper(channel, raw_data)
except ValueError:
raise ValueError("Wrong notification type received.")
except KeyError:
raise KeyError("Could not parse notification.")
except TypeError:
raise TypeError("Wrong JSON format.")
18 changes: 10 additions & 8 deletions splitio/models/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import base64
import json


class Token(object):
"""Token object class."""

Expand Down Expand Up @@ -30,27 +31,27 @@ def __init__(self, push_enabled, token, channels, exp, iat):
self._channels = channels
self._exp = exp
self._iat = iat

@property
def push_enabled(self):
"""Return push_enabled"""
return self._push_enabled

@property
def token(self):
"""Return token"""
return self._token

@property
def channels(self):
"""Return channels"""
return self._channels

@property
def exp(self):
"""Return exp"""
return self._exp

@property
def iat(self):
"""Return iat"""
Expand All @@ -66,15 +67,16 @@ def decode_token(raw_token):
push_enabled = raw_token['pushEnabled']
if not push_enabled or len(token.strip()) == 0:
return None, None, None

token_parts = token.split('.')
if len(token_parts) < 2:
return None, None, None

to_decode = token_parts[1]
decoded_payload = base64.b64decode(to_decode + '='*(-len(to_decode) % 4))
decoded_payload = base64.b64decode(to_decode + '='*(-len(to_decode) % 4))
return push_enabled, token, json.loads(decoded_payload)


def from_raw(raw_token):
"""
Parse a new token from a raw token response.
Expand Down
2 changes: 1 addition & 1 deletion splitio/push/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _event_handler(self, event):

try:
handle(parsed)
except Exception: #pylint:disable=broad-except
except Exception: # pylint:disable=broad-except
_LOGGER.error('something went wrong when processing message of type %s',
parsed.event_type)
_LOGGER.debug(str(parsed), exc_info=True)
Expand Down
8 changes: 4 additions & 4 deletions splitio/storage/adapters/cache_trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
DEFAULT_MAX_SIZE = 100


class LocalMemoryCache(object): #pylint: disable=too-many-instance-attributes
class LocalMemoryCache(object): # pylint: disable=too-many-instance-attributes
"""
Key/Value local memory cache. with expiration & LRU eviction.

Expand All @@ -25,10 +25,10 @@ class LocalMemoryCache(object): #pylint: disable=too-many-instance-attributes
None <---next--- || node || <---next--- || node || ... <---next--- || node ||
"""

class _Node(object): #pylint: disable=too-few-public-methods
class _Node(object): # pylint: disable=too-few-public-methods
"""Links to previous an next items in the circular list."""

def __init__(self, key, value, last_update, previous_element, next_element): #pylint: disable=too-many-arguments
def __init__(self, key, value, last_update, previous_element, next_element): # pylint: disable=too-many-arguments
"""Class constructor."""
self.key = key # we also keep the key for O(1) access when removing the LRU.
self.value = value
Expand Down Expand Up @@ -186,7 +186,7 @@ def _decorator(user_function):
_cache = LocalMemoryCache(key_func, user_function, max_age_seconds, max_size)
# The lambda below IS necessary, otherwise update_wrapper fails since the function
# is an instance method and has no reference to the __module__ namespace.
wrapper = lambda *args, **kwargs: _cache.get(*args, **kwargs) #pylint: disable=unnecessary-lambda
wrapper = lambda *args, **kwargs: _cache.get(*args, **kwargs) # pylint: disable=unnecessary-lambda
return update_wrapper(wrapper, user_function)

return _decorator
4 changes: 2 additions & 2 deletions splitio/storage/adapters/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Custom utilities."""


class DynamicDecorator(object): #pylint: disable=too-few-public-methods
class DynamicDecorator(object): # pylint: disable=too-few-public-methods
"""
Decorator that will inject a decorator during class construction.

Expand Down Expand Up @@ -65,7 +65,7 @@ def __call__(self, to_decorate):
positional_args_lambdas = self._positional_args_lambdas
keyword_args_lambdas = self._keyword_args_lambdas

class _decorated(to_decorate): #pylint: disable=too-few-public-methods
class _decorated(to_decorate): # pylint: disable=too-few-public-methods
"""
Decorated class wrapper.

Expand Down
Loading