Skip to content

Commit 182aa1b

Browse files
authored
Merge pull request #112 from splitio/development
[SDKS-285 & 413 & 377]: Python Sdk: Move to a single impressions queue
2 parents ff29c01 + bacc7e6 commit 182aa1b

30 files changed

+1375
-532
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
7.0.0 (Feb 21, 2019)
2+
- Stored Impressions in Queue.
3+
- Fixed bug related to Machine Name and Machine IP.
4+
- Updated Input Validation.
5+
- New hash implementation supporting more platforms.
16
6.2.2 (Dec 17, 2018)
27
- Fixed issue on selecting db for Sentinel.
38
6.2.1 (Dec 6, 2018)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Split has built and maintains a SDKs for:
2828
* PHP [Github](https://github.com/splitio/php-client) [Docs](http://docs.split.io/docs/php-sdk-overview)
2929
* Python [Github](https://github.com/splitio/python-client) [Docs](http://docs.split.io/docs/python-sdk-overview)
3030
* GO [Github](https://github.com/splitio/go-client) [Docs](http://docs.split.io/docs/go-sdk-overview)
31-
* Android [Github](https://github.com/splitio/android-client) [Docs](https://docs.split.io/v1/docs/android-sdk-overview)
32-
* IOS [Github](https://github.com/splitio/ios-client) [Docs](https://docs.split.io/v1/docs/ios-sdk-overview)
31+
* Android [Github](https://github.com/splitio/android-client) [Docs](https://docs.split.io/docs/android-sdk-overview)
32+
* IOS [Github](https://github.com/splitio/ios-client) [Docs](https://docs.split.io/docs/ios-sdk-overview)
3333

3434
For a comprehensive list of opensource projects visit our [Github page](https://github.com/splitio?utf8=%E2%9C%93&query=%20only%3Apublic%20).
3535

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'test': tests_require,
3636
'redis': ['redis>=2.10.5', 'jsonpickle>=0.9.3'],
3737
'uwsgi': ['uwsgi>=2.0.0', 'jsonpickle>=0.9.3'],
38-
'cpphash': ['splitmmh3']
38+
'cpphash': ['mmh3cffi>=0.1.2']
3939
},
4040
setup_requires=['nose'],
4141
classifiers=[

splitio/api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import requests
66
import json
77

8+
from splitio.exceptions import ForbiddenException
89
from splitio.config import SDK_API_BASE_URL, EVENTS_API_BASE_URL, SDK_VERSION
910

1011
_SEGMENT_CHANGES_URL_TEMPLATE = '{base_url}/segmentChanges/{segment_name}/'
@@ -92,7 +93,10 @@ def _build_headers(self):
9293
return headers
9394

9495
def _logHttpError(self, response):
95-
if response.status_code < 200 or response.status_code >= 400:
96+
if response.status_code == requests.codes.forbidden:
97+
raise ForbiddenException()
98+
99+
if response.status_code < requests.codes.ok or response.status_code >= requests.codes.bad:
96100
respJson = response.json()
97101
if 'message' in respJson:
98102
self._logger.error(

splitio/brokers.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
AllKeysSplit, CacheBasedSplitFetcher
2727
from splitio.segments import ApiSegmentChangeFetcher, \
2828
SelfRefreshingSegmentFetcher, JSONFileSegmentFetcher
29-
from splitio.config import DEFAULT_CONFIG, MAX_INTERVAL, parse_config_file
29+
from splitio.config import DEFAULT_CONFIG, MAX_INTERVAL, parse_config_file, \
30+
set_machine_ip, set_machine_name
3031
from splitio.uwsgi import UWSGISplitCache, UWSGIImpressionsCache, \
3132
UWSGIMetricsCache, UWSGIEventsCache, get_uwsgi
3233
from splitio.tasks import EventsSyncTask
@@ -79,13 +80,13 @@ def get_change_number(self):
7980
"""
8081
return self.get_split_fetcher().change_number
8182

82-
def log_impression(self, impression):
83+
def log_impressions(self, impressions):
8384
"""
84-
Logs an impression after a get_treatment call
85+
Logs impressions after a get_treatments call
8586
:return: The treatment log implementation.
8687
:rtype: TreatmentLog
8788
"""
88-
return self.get_impression_log().log(impression)
89+
return self.get_impression_log().log_impressions(impressions)
8990

9091
def log_operation_time(self, operation, elapsed):
9192
"""Get the metrics implementation.
@@ -120,6 +121,7 @@ def get_events_log(self):
120121
def destroy(self):
121122
pass
122123

124+
123125
class JSONFileBroker(BaseBroker):
124126
def __init__(self, config, segment_changes_file_name, split_changes_file_name):
125127
"""
@@ -138,8 +140,8 @@ def __init__(self, config, segment_changes_file_name, split_changes_file_name):
138140
self._segment_changes_file_name = segment_changes_file_name
139141
self._split_changes_file_name = split_changes_file_name
140142
self._split_fetcher = self._build_split_fetcher()
141-
self._treatment_log = TreatmentLog() # Does nothing on ._log()
142-
self._metrics = Metrics() # Does nothing on .count(), .time(), .gauge()
143+
self._treatment_log = TreatmentLog() # Does nothing on ._log()
144+
self._metrics = Metrics() # Does nothing on .count(), .time(), .gauge()
143145

144146
def _build_split_fetcher(self):
145147
"""
@@ -183,6 +185,7 @@ def destroy(self):
183185
def get_events_log(self):
184186
return None
185187

188+
186189
class SelfRefreshingBroker(BaseBroker):
187190
def __init__(self, api_key, config=None, sdk_api_base_url=None,
188191
events_api_base_url=None, impression_listener=None):
@@ -488,7 +491,7 @@ def get_events_log(self):
488491
def refresh_splits(self):
489492
while not self._destroyed:
490493
time.sleep(self._split_refresh_period)
491-
if not self._destroyed: # DO NOT REMOVE
494+
if not self._destroyed: # DO NOT REMOVE
492495
# This check is used in case the client was
493496
# destroyed while the thread was sleeping
494497
# and the file was closed, in order to
@@ -590,7 +593,6 @@ def __init__(self, uwsgi, config=None):
590593
self._treatment_log = treatment_log
591594
self._metrics = metrics
592595

593-
594596
def get_split_fetcher(self):
595597
"""
596598
Get the split fetcher implementation for the broker.
@@ -640,6 +642,9 @@ def _init_config(api_key, **kwargs):
640642
file_config.update(config)
641643
config = file_config
642644

645+
set_machine_ip(config.get('splitSdkMachineIp'))
646+
set_machine_name(config.get('splitSdkMachineName'))
647+
643648
return api_key, config, sdk_api_base_url, events_api_base_url
644649

645650

splitio/cache.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ def add_impression(self, impression):
177177
"""
178178
pass # Do nothing
179179

180+
def add_impressions(self, impressions):
181+
"""
182+
Adds impression to the queue if it is enabled, otherwise the impression
183+
is dropped.
184+
:param impressions: The impression bulk
185+
:type impressions: list
186+
"""
187+
for impression in impressions:
188+
self.add_impression(impression)
189+
180190
def fetch_all(self):
181191
""" List all impressions.
182192
:return: A list of Impression tuples

0 commit comments

Comments
 (0)