splitio-client 10.1.0rc3__tar.gz → 10.3.0__tar.gz
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.
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/PKG-INFO +2 -2
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/setup.cfg +1 -1
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/setup.py +3 -2
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/api/client.py +34 -7
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/api/commons.py +18 -2
- splitio_client-10.3.0/splitio/api/splits.py +202 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/client.py +29 -26
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/factory.py +35 -22
- splitio_client-10.3.0/splitio/engine/evaluator.py +249 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/impressions/__init__.py +20 -20
- splitio_client-10.3.0/splitio/engine/impressions/impressions.py +55 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/condition.py +6 -4
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/__init__.py +4 -1
- splitio_client-10.3.0/splitio/models/grammar/matchers/prerequisites.py +38 -0
- splitio_client-10.3.0/splitio/models/grammar/matchers/rule_based_segment.py +72 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/impressions.py +13 -0
- splitio_client-10.3.0/splitio/models/rule_based_segments.py +195 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/splits.py +57 -5
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/telemetry.py +1 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/push/parser.py +57 -3
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/push/processor.py +6 -4
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/push/workers.py +104 -30
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/recorder/recorder.py +8 -8
- splitio_client-10.3.0/splitio/spec.py +1 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/storage/__init__.py +72 -1
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/storage/inmemmory.py +274 -1
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/storage/pluggable.py +283 -3
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/storage/redis.py +291 -3
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/segment.py +11 -4
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/split.py +245 -97
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/util.py +4 -0
- splitio_client-10.3.0/splitio/util/storage_helper.py +200 -0
- splitio_client-10.3.0/splitio/version.py +1 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio_client.egg-info/PKG-INFO +2 -2
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio_client.egg-info/SOURCES.txt +3 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio_client.egg-info/requires.txt +2 -1
- splitio_client-10.1.0rc3/splitio/api/splits.py +0 -121
- splitio_client-10.1.0rc3/splitio/engine/evaluator.py +0 -185
- splitio_client-10.1.0rc3/splitio/engine/impressions/impressions.py +0 -41
- splitio_client-10.1.0rc3/splitio/spec.py +0 -1
- splitio_client-10.1.0rc3/splitio/util/storage_helper.py +0 -99
- splitio_client-10.1.0rc3/splitio/version.py +0 -1
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/README.md +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/api/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/api/auth.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/api/events.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/api/impressions.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/api/segments.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/api/telemetry.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/config.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/input_validator.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/key.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/listener.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/localhost.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/manager.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/client/util.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/cache/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/cache/lru.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/filters.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/hashfns/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/hashfns/legacy.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/hashfns/murmur3py.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/impressions/adapters.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/impressions/manager.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/impressions/strategies.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/impressions/unique_keys_tracker.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/splitters.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/engine/telemetry.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/exceptions.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/factories.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/impressions.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/key.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/datatypes.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/events.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/base.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/keys.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/misc.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/numeric.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/semver.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/sets.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/string.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/utils/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/matchers/utils/utils.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/grammar/partitions.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/notification.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/segments.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/models/token.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/optional/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/optional/loaders.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/push/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/push/manager.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/push/splitsse.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/push/sse.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/push/status_tracker.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/recorder/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/storage/adapters/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/storage/adapters/cache_trait.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/storage/adapters/redis.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/storage/adapters/util.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/event.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/impression.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/manager.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/synchronizer.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/telemetry.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/sync/unique_keys.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/events_sync.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/impressions_sync.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/segment_sync.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/split_sync.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/telemetry_sync.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/unique_keys_sync.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/util/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/util/asynctask.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/tasks/util/workerpool.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/util/__init__.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/util/backoff.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/util/decorators.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/util/threadutil.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio/util/time.py +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio_client.egg-info/dependency_links.txt +0 -0
- {splitio_client-10.1.0rc3 → splitio_client-10.3.0}/splitio_client.egg-info/top_level.txt +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: splitio_client
|
|
3
|
-
Version: 10.
|
|
3
|
+
Version: 10.3.0
|
|
4
4
|
Summary: Split.io Python Client
|
|
5
5
|
Home-page: https://github.com/splitio/python-client
|
|
6
6
|
Author: Patricio Echague, Sebastian Arrubia
|
|
7
7
|
Author-email: pato@split.io, sebastian@split.io
|
|
8
8
|
License: Apache License 2.0
|
|
9
|
-
Download-URL: https://github.com/splitio/python-client/tarball/10.
|
|
9
|
+
Download-URL: https://github.com/splitio/python-client/tarball/10.3.0
|
|
10
10
|
Description: # Split Python SDK
|
|
11
11
|

|
|
12
12
|
|
|
@@ -8,7 +8,7 @@ TESTS_REQUIRES = [
|
|
|
8
8
|
'flake8',
|
|
9
9
|
'pytest==7.0.1',
|
|
10
10
|
'pytest-mock==3.11.1',
|
|
11
|
-
'coverage',
|
|
11
|
+
'coverage==7.0.0',
|
|
12
12
|
'pytest-cov==4.1.0',
|
|
13
13
|
'importlib-metadata==6.7',
|
|
14
14
|
'tomli==1.2.3',
|
|
@@ -17,7 +17,8 @@ TESTS_REQUIRES = [
|
|
|
17
17
|
'pytest-asyncio==0.21.0',
|
|
18
18
|
'aiohttp>=3.8.4',
|
|
19
19
|
'aiofiles>=23.1.0',
|
|
20
|
-
'requests-kerberos>=0.15.0'
|
|
20
|
+
'requests-kerberos>=0.15.0',
|
|
21
|
+
'urllib3==2.0.7'
|
|
21
22
|
]
|
|
22
23
|
|
|
23
24
|
INSTALL_REQUIRES = [
|
|
@@ -92,6 +92,25 @@ class HTTPAdapterWithProxyKerberosAuth(requests.adapters.HTTPAdapter):
|
|
|
92
92
|
class HttpClientBase(object, metaclass=abc.ABCMeta):
|
|
93
93
|
"""HttpClient wrapper template."""
|
|
94
94
|
|
|
95
|
+
def __init__(self, timeout=None, sdk_url=None, events_url=None, auth_url=None, telemetry_url=None):
|
|
96
|
+
"""
|
|
97
|
+
Class constructor.
|
|
98
|
+
|
|
99
|
+
:param timeout: How many milliseconds to wait until the server responds.
|
|
100
|
+
:type timeout: int
|
|
101
|
+
:param sdk_url: Optional alternative sdk URL.
|
|
102
|
+
:type sdk_url: str
|
|
103
|
+
:param events_url: Optional alternative events URL.
|
|
104
|
+
:type events_url: str
|
|
105
|
+
:param auth_url: Optional alternative auth URL.
|
|
106
|
+
:type auth_url: str
|
|
107
|
+
:param telemetry_url: Optional alternative telemetry URL.
|
|
108
|
+
:type telemetry_url: str
|
|
109
|
+
"""
|
|
110
|
+
_LOGGER.debug("Initializing httpclient")
|
|
111
|
+
self._timeout = timeout/1000 if timeout else None # Convert ms to seconds.
|
|
112
|
+
self._urls = _construct_urls(sdk_url, events_url, auth_url, telemetry_url)
|
|
113
|
+
|
|
95
114
|
@abc.abstractmethod
|
|
96
115
|
def get(self, server, path, apikey):
|
|
97
116
|
"""http get request"""
|
|
@@ -113,6 +132,9 @@ class HttpClientBase(object, metaclass=abc.ABCMeta):
|
|
|
113
132
|
self._telemetry_runtime_producer = telemetry_runtime_producer
|
|
114
133
|
self._metric_name = metric_name
|
|
115
134
|
|
|
135
|
+
def is_sdk_endpoint_overridden(self):
|
|
136
|
+
return self._urls['sdk'] != SDK_URL
|
|
137
|
+
|
|
116
138
|
def _get_headers(self, extra_headers, sdk_key):
|
|
117
139
|
headers = _build_basic_headers(sdk_key)
|
|
118
140
|
if extra_headers is not None:
|
|
@@ -154,10 +176,8 @@ class HttpClient(HttpClientBase):
|
|
|
154
176
|
:param telemetry_url: Optional alternative telemetry URL.
|
|
155
177
|
:type telemetry_url: str
|
|
156
178
|
"""
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
self._urls = _construct_urls(sdk_url, events_url, auth_url, telemetry_url)
|
|
160
|
-
|
|
179
|
+
HttpClientBase.__init__(self, timeout, sdk_url, events_url, auth_url, telemetry_url)
|
|
180
|
+
|
|
161
181
|
def get(self, server, path, sdk_key, query=None, extra_headers=None): # pylint: disable=too-many-arguments
|
|
162
182
|
"""
|
|
163
183
|
Issue a get request.
|
|
@@ -187,7 +207,11 @@ class HttpClient(HttpClientBase):
|
|
|
187
207
|
self._record_telemetry(response.status_code, get_current_epoch_time_ms() - start)
|
|
188
208
|
return HttpResponse(response.status_code, response.text, response.headers)
|
|
189
209
|
|
|
190
|
-
except
|
|
210
|
+
except requests.exceptions.ChunkedEncodingError as exc:
|
|
211
|
+
_LOGGER.error("IncompleteRead exception detected: %s", exc)
|
|
212
|
+
return HttpResponse(400, "", {})
|
|
213
|
+
|
|
214
|
+
except Exception as exc: # pylint: disable=broad-except
|
|
191
215
|
raise HttpClientException(_EXC_MSG.format(source='request')) from exc
|
|
192
216
|
|
|
193
217
|
def post(self, server, path, sdk_key, body, query=None, extra_headers=None): # pylint: disable=too-many-arguments
|
|
@@ -241,8 +265,7 @@ class HttpClientAsync(HttpClientBase):
|
|
|
241
265
|
:param telemetry_url: Optional alternative telemetry URL.
|
|
242
266
|
:type telemetry_url: str
|
|
243
267
|
"""
|
|
244
|
-
self
|
|
245
|
-
self._urls = _construct_urls(sdk_url, events_url, auth_url, telemetry_url)
|
|
268
|
+
HttpClientBase.__init__(self, timeout, sdk_url, events_url, auth_url, telemetry_url)
|
|
246
269
|
self._session = aiohttp.ClientSession()
|
|
247
270
|
|
|
248
271
|
async def get(self, server, path, apikey, query=None, extra_headers=None): # pylint: disable=too-many-arguments
|
|
@@ -281,6 +304,10 @@ class HttpClientAsync(HttpClientBase):
|
|
|
281
304
|
await self._record_telemetry(response.status, get_current_epoch_time_ms() - start)
|
|
282
305
|
return HttpResponse(response.status, body, response.headers)
|
|
283
306
|
|
|
307
|
+
except aiohttp.ClientPayloadError as exc:
|
|
308
|
+
_LOGGER.error("ContentLengthError exception detected: %s", exc)
|
|
309
|
+
return HttpResponse(400, "", {})
|
|
310
|
+
|
|
284
311
|
except aiohttp.ClientError as exc: # pylint: disable=broad-except
|
|
285
312
|
raise HttpClientException(_EXC_MSG.format(source='aiohttp')) from exc
|
|
286
313
|
|
|
@@ -57,7 +57,7 @@ def record_telemetry(status_code, elapsed, metric_name, telemetry_runtime_produc
|
|
|
57
57
|
class FetchOptions(object):
|
|
58
58
|
"""Fetch Options object."""
|
|
59
59
|
|
|
60
|
-
def __init__(self, cache_control_headers=False, change_number=None, sets=None, spec=SPEC_VERSION):
|
|
60
|
+
def __init__(self, cache_control_headers=False, change_number=None, rbs_change_number=None, sets=None, spec=SPEC_VERSION):
|
|
61
61
|
"""
|
|
62
62
|
Class constructor.
|
|
63
63
|
|
|
@@ -72,6 +72,7 @@ class FetchOptions(object):
|
|
|
72
72
|
"""
|
|
73
73
|
self._cache_control_headers = cache_control_headers
|
|
74
74
|
self._change_number = change_number
|
|
75
|
+
self._rbs_change_number = rbs_change_number
|
|
75
76
|
self._sets = sets
|
|
76
77
|
self._spec = spec
|
|
77
78
|
|
|
@@ -85,6 +86,11 @@ class FetchOptions(object):
|
|
|
85
86
|
"""Return change number."""
|
|
86
87
|
return self._change_number
|
|
87
88
|
|
|
89
|
+
@property
|
|
90
|
+
def rbs_change_number(self):
|
|
91
|
+
"""Return change number."""
|
|
92
|
+
return self._rbs_change_number
|
|
93
|
+
|
|
88
94
|
@property
|
|
89
95
|
def sets(self):
|
|
90
96
|
"""Return sets."""
|
|
@@ -103,14 +109,19 @@ class FetchOptions(object):
|
|
|
103
109
|
if self._change_number != other._change_number:
|
|
104
110
|
return False
|
|
105
111
|
|
|
112
|
+
if self._rbs_change_number != other._rbs_change_number:
|
|
113
|
+
return False
|
|
114
|
+
|
|
106
115
|
if self._sets != other._sets:
|
|
107
116
|
return False
|
|
117
|
+
|
|
108
118
|
if self._spec != other._spec:
|
|
109
119
|
return False
|
|
120
|
+
|
|
110
121
|
return True
|
|
111
122
|
|
|
112
123
|
|
|
113
|
-
def build_fetch(change_number, fetch_options, metadata):
|
|
124
|
+
def build_fetch(change_number, fetch_options, metadata, rbs_change_number=None):
|
|
114
125
|
"""
|
|
115
126
|
Build fetch with new flags if that is the case.
|
|
116
127
|
|
|
@@ -123,11 +134,16 @@ def build_fetch(change_number, fetch_options, metadata):
|
|
|
123
134
|
:param metadata: Metadata Headers.
|
|
124
135
|
:type metadata: dict
|
|
125
136
|
|
|
137
|
+
:param rbs_change_number: Last known timestamp of a rule based segment modification.
|
|
138
|
+
:type rbs_change_number: int
|
|
139
|
+
|
|
126
140
|
:return: Objects for fetch
|
|
127
141
|
:rtype: dict, dict
|
|
128
142
|
"""
|
|
129
143
|
query = {'s': fetch_options.spec} if fetch_options.spec is not None else {}
|
|
130
144
|
query['since'] = change_number
|
|
145
|
+
if rbs_change_number is not None:
|
|
146
|
+
query['rbSince'] = rbs_change_number
|
|
131
147
|
extra_headers = metadata
|
|
132
148
|
if fetch_options is None:
|
|
133
149
|
return query, extra_headers
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""Splits API module."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
from splitio.api import APIException, headers_from_metadata
|
|
7
|
+
from splitio.api.commons import build_fetch, FetchOptions
|
|
8
|
+
from splitio.api.client import HttpClientException
|
|
9
|
+
from splitio.models.telemetry import HTTPExceptionsAndLatencies
|
|
10
|
+
from splitio.util.time import utctime_ms
|
|
11
|
+
from splitio.spec import SPEC_VERSION
|
|
12
|
+
from splitio.sync import util
|
|
13
|
+
|
|
14
|
+
_LOGGER = logging.getLogger(__name__)
|
|
15
|
+
_SPEC_1_1 = "1.1"
|
|
16
|
+
_PROXY_CHECK_INTERVAL_MILLISECONDS_SS = 24 * 60 * 60 * 1000
|
|
17
|
+
|
|
18
|
+
class SplitsAPIBase(object): # pylint: disable=too-few-public-methods
|
|
19
|
+
"""Class that uses an httpClient to communicate with the splits API."""
|
|
20
|
+
|
|
21
|
+
def __init__(self, client, sdk_key, sdk_metadata, telemetry_runtime_producer):
|
|
22
|
+
"""
|
|
23
|
+
Class constructor.
|
|
24
|
+
|
|
25
|
+
:param client: HTTP Client responsble for issuing calls to the backend.
|
|
26
|
+
:type client: HttpClient
|
|
27
|
+
:param sdk_key: User sdk_key token.
|
|
28
|
+
:type sdk_key: string
|
|
29
|
+
:param sdk_metadata: SDK version & machine name & IP.
|
|
30
|
+
:type sdk_metadata: splitio.client.util.SdkMetadata
|
|
31
|
+
"""
|
|
32
|
+
self._client = client
|
|
33
|
+
self._sdk_key = sdk_key
|
|
34
|
+
self._metadata = headers_from_metadata(sdk_metadata)
|
|
35
|
+
self._telemetry_runtime_producer = telemetry_runtime_producer
|
|
36
|
+
self._client.set_telemetry_data(HTTPExceptionsAndLatencies.SPLIT, self._telemetry_runtime_producer)
|
|
37
|
+
self._spec_version = SPEC_VERSION
|
|
38
|
+
self._last_proxy_check_timestamp = 0
|
|
39
|
+
self.clear_storage = False
|
|
40
|
+
self._old_spec_since = None
|
|
41
|
+
|
|
42
|
+
def _check_last_proxy_check_timestamp(self, since):
|
|
43
|
+
if self._spec_version == _SPEC_1_1 and ((utctime_ms() - self._last_proxy_check_timestamp) >= _PROXY_CHECK_INTERVAL_MILLISECONDS_SS):
|
|
44
|
+
_LOGGER.info("Switching to new Feature flag spec (%s) and fetching.", SPEC_VERSION);
|
|
45
|
+
self._spec_version = SPEC_VERSION
|
|
46
|
+
self._old_spec_since = since
|
|
47
|
+
|
|
48
|
+
def _check_old_spec_since(self, change_number):
|
|
49
|
+
if self._spec_version == _SPEC_1_1 and self._old_spec_since is not None:
|
|
50
|
+
since = self._old_spec_since
|
|
51
|
+
self._old_spec_since = None
|
|
52
|
+
return since
|
|
53
|
+
return change_number
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class SplitsAPI(SplitsAPIBase): # pylint: disable=too-few-public-methods
|
|
57
|
+
"""Class that uses an httpClient to communicate with the splits API."""
|
|
58
|
+
|
|
59
|
+
def __init__(self, client, sdk_key, sdk_metadata, telemetry_runtime_producer):
|
|
60
|
+
"""
|
|
61
|
+
Class constructor.
|
|
62
|
+
|
|
63
|
+
:param client: HTTP Client responsble for issuing calls to the backend.
|
|
64
|
+
:type client: HttpClient
|
|
65
|
+
:param sdk_key: User sdk_key token.
|
|
66
|
+
:type sdk_key: string
|
|
67
|
+
:param sdk_metadata: SDK version & machine name & IP.
|
|
68
|
+
:type sdk_metadata: splitio.client.util.SdkMetadata
|
|
69
|
+
"""
|
|
70
|
+
SplitsAPIBase.__init__(self, client, sdk_key, sdk_metadata, telemetry_runtime_producer)
|
|
71
|
+
|
|
72
|
+
def fetch_splits(self, change_number, rbs_change_number, fetch_options):
|
|
73
|
+
"""
|
|
74
|
+
Fetch feature flags from backend.
|
|
75
|
+
|
|
76
|
+
:param change_number: Last known timestamp of a split modification.
|
|
77
|
+
:type change_number: int
|
|
78
|
+
|
|
79
|
+
:param rbs_change_number: Last known timestamp of a rule based segment modification.
|
|
80
|
+
:type rbs_change_number: int
|
|
81
|
+
|
|
82
|
+
:param fetch_options: Fetch options for getting feature flag definitions.
|
|
83
|
+
:type fetch_options: splitio.api.commons.FetchOptions
|
|
84
|
+
|
|
85
|
+
:return: Json representation of a splitChanges response.
|
|
86
|
+
:rtype: dict
|
|
87
|
+
"""
|
|
88
|
+
try:
|
|
89
|
+
self._check_last_proxy_check_timestamp(change_number)
|
|
90
|
+
change_number = self._check_old_spec_since(change_number)
|
|
91
|
+
|
|
92
|
+
if self._spec_version == _SPEC_1_1:
|
|
93
|
+
fetch_options = FetchOptions(fetch_options.cache_control_headers, fetch_options.change_number,
|
|
94
|
+
None, fetch_options.sets, self._spec_version)
|
|
95
|
+
rbs_change_number = None
|
|
96
|
+
query, extra_headers = build_fetch(change_number, fetch_options, self._metadata, rbs_change_number)
|
|
97
|
+
response = self._client.get(
|
|
98
|
+
'sdk',
|
|
99
|
+
'splitChanges',
|
|
100
|
+
self._sdk_key,
|
|
101
|
+
extra_headers=extra_headers,
|
|
102
|
+
query=query,
|
|
103
|
+
)
|
|
104
|
+
if 200 <= response.status_code < 300:
|
|
105
|
+
if self._spec_version == _SPEC_1_1:
|
|
106
|
+
return util.convert_to_new_spec(json.loads(response.body))
|
|
107
|
+
|
|
108
|
+
self.clear_storage = self._last_proxy_check_timestamp != 0
|
|
109
|
+
self._last_proxy_check_timestamp = 0
|
|
110
|
+
return json.loads(response.body)
|
|
111
|
+
|
|
112
|
+
else:
|
|
113
|
+
if response.status_code == 414:
|
|
114
|
+
_LOGGER.error('Error fetching feature flags; the amount of flag sets provided are too big, causing uri length error.')
|
|
115
|
+
|
|
116
|
+
if self._client.is_sdk_endpoint_overridden() and response.status_code == 400 and self._spec_version == SPEC_VERSION:
|
|
117
|
+
_LOGGER.warning('Detected proxy response error, changing spec version from %s to %s and re-fetching.', self._spec_version, _SPEC_1_1)
|
|
118
|
+
self._spec_version = _SPEC_1_1
|
|
119
|
+
self._last_proxy_check_timestamp = utctime_ms()
|
|
120
|
+
return self.fetch_splits(change_number, None, FetchOptions(fetch_options.cache_control_headers, fetch_options.change_number,
|
|
121
|
+
None, fetch_options.sets, self._spec_version))
|
|
122
|
+
|
|
123
|
+
raise APIException(response.body, response.status_code)
|
|
124
|
+
|
|
125
|
+
except HttpClientException as exc:
|
|
126
|
+
_LOGGER.error('Error fetching feature flags because an exception was raised by the HTTPClient')
|
|
127
|
+
_LOGGER.debug('Error: ', exc_info=True)
|
|
128
|
+
raise APIException('Feature flags not fetched correctly.') from exc
|
|
129
|
+
|
|
130
|
+
class SplitsAPIAsync(SplitsAPIBase): # pylint: disable=too-few-public-methods
|
|
131
|
+
"""Class that uses an httpClient to communicate with the splits API."""
|
|
132
|
+
|
|
133
|
+
def __init__(self, client, sdk_key, sdk_metadata, telemetry_runtime_producer):
|
|
134
|
+
"""
|
|
135
|
+
Class constructor.
|
|
136
|
+
|
|
137
|
+
:param client: HTTP Client responsble for issuing calls to the backend.
|
|
138
|
+
:type client: HttpClient
|
|
139
|
+
:param sdk_key: User sdk_key token.
|
|
140
|
+
:type sdk_key: string
|
|
141
|
+
:param sdk_metadata: SDK version & machine name & IP.
|
|
142
|
+
:type sdk_metadata: splitio.client.util.SdkMetadata
|
|
143
|
+
"""
|
|
144
|
+
SplitsAPIBase.__init__(self, client, sdk_key, sdk_metadata, telemetry_runtime_producer)
|
|
145
|
+
|
|
146
|
+
async def fetch_splits(self, change_number, rbs_change_number, fetch_options):
|
|
147
|
+
"""
|
|
148
|
+
Fetch feature flags from backend.
|
|
149
|
+
|
|
150
|
+
:param change_number: Last known timestamp of a split modification.
|
|
151
|
+
:type change_number: int
|
|
152
|
+
|
|
153
|
+
:param rbs_change_number: Last known timestamp of a rule based segment modification.
|
|
154
|
+
:type rbs_change_number: int
|
|
155
|
+
|
|
156
|
+
:param fetch_options: Fetch options for getting feature flag definitions.
|
|
157
|
+
:type fetch_options: splitio.api.commons.FetchOptions
|
|
158
|
+
|
|
159
|
+
:return: Json representation of a splitChanges response.
|
|
160
|
+
:rtype: dict
|
|
161
|
+
"""
|
|
162
|
+
try:
|
|
163
|
+
self._check_last_proxy_check_timestamp(change_number)
|
|
164
|
+
change_number = self._check_old_spec_since(change_number)
|
|
165
|
+
if self._spec_version == _SPEC_1_1:
|
|
166
|
+
fetch_options = FetchOptions(fetch_options.cache_control_headers, fetch_options.change_number,
|
|
167
|
+
None, fetch_options.sets, self._spec_version)
|
|
168
|
+
rbs_change_number = None
|
|
169
|
+
|
|
170
|
+
query, extra_headers = build_fetch(change_number, fetch_options, self._metadata, rbs_change_number)
|
|
171
|
+
response = await self._client.get(
|
|
172
|
+
'sdk',
|
|
173
|
+
'splitChanges',
|
|
174
|
+
self._sdk_key,
|
|
175
|
+
extra_headers=extra_headers,
|
|
176
|
+
query=query,
|
|
177
|
+
)
|
|
178
|
+
if 200 <= response.status_code < 300:
|
|
179
|
+
if self._spec_version == _SPEC_1_1:
|
|
180
|
+
return util.convert_to_new_spec(json.loads(response.body))
|
|
181
|
+
|
|
182
|
+
self.clear_storage = self._last_proxy_check_timestamp != 0
|
|
183
|
+
self._last_proxy_check_timestamp = 0
|
|
184
|
+
return json.loads(response.body)
|
|
185
|
+
|
|
186
|
+
else:
|
|
187
|
+
if response.status_code == 414:
|
|
188
|
+
_LOGGER.error('Error fetching feature flags; the amount of flag sets provided are too big, causing uri length error.')
|
|
189
|
+
|
|
190
|
+
if self._client.is_sdk_endpoint_overridden() and response.status_code == 400 and self._spec_version == SPEC_VERSION:
|
|
191
|
+
_LOGGER.warning('Detected proxy response error, changing spec version from %s to %s and re-fetching.', self._spec_version, _SPEC_1_1)
|
|
192
|
+
self._spec_version = _SPEC_1_1
|
|
193
|
+
self._last_proxy_check_timestamp = utctime_ms()
|
|
194
|
+
return await self.fetch_splits(change_number, None, FetchOptions(fetch_options.cache_control_headers, fetch_options.change_number,
|
|
195
|
+
None, fetch_options.sets, self._spec_version))
|
|
196
|
+
|
|
197
|
+
raise APIException(response.body, response.status_code)
|
|
198
|
+
|
|
199
|
+
except HttpClientException as exc:
|
|
200
|
+
_LOGGER.error('Error fetching feature flags because an exception was raised by the HTTPClient')
|
|
201
|
+
_LOGGER.debug('Error: ', exc_info=True)
|
|
202
|
+
raise APIException('Feature flags not fetched correctly.') from exc
|
|
@@ -3,7 +3,7 @@ import logging
|
|
|
3
3
|
|
|
4
4
|
from splitio.engine.evaluator import Evaluator, CONTROL, EvaluationDataFactory, AsyncEvaluationDataFactory
|
|
5
5
|
from splitio.engine.splitters import Splitter
|
|
6
|
-
from splitio.models.impressions import Impression, Label
|
|
6
|
+
from splitio.models.impressions import Impression, Label, ImpressionDecorated
|
|
7
7
|
from splitio.models.events import Event, EventWrapper
|
|
8
8
|
from splitio.models.telemetry import get_latency_bucket_index, MethodExceptionsAndLatencies
|
|
9
9
|
from splitio.client import input_validator
|
|
@@ -22,7 +22,8 @@ class ClientBase(object): # pylint: disable=too-many-instance-attributes
|
|
|
22
22
|
'impression': {
|
|
23
23
|
'label': Label.EXCEPTION,
|
|
24
24
|
'change_number': None,
|
|
25
|
-
}
|
|
25
|
+
},
|
|
26
|
+
'impressions_disabled': False
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
_NON_READY_EVAL_RESULT = {
|
|
@@ -31,7 +32,8 @@ class ClientBase(object): # pylint: disable=too-many-instance-attributes
|
|
|
31
32
|
'impression': {
|
|
32
33
|
'label': Label.NOT_READY,
|
|
33
34
|
'change_number': None
|
|
34
|
-
}
|
|
35
|
+
},
|
|
36
|
+
'impressions_disabled': False
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
def __init__(self, factory, recorder, labels_enabled=True):
|
|
@@ -116,14 +118,15 @@ class ClientBase(object): # pylint: disable=too-many-instance-attributes
|
|
|
116
118
|
|
|
117
119
|
def _build_impression(self, key, bucketing, feature, result):
|
|
118
120
|
"""Build an impression based on evaluation data & it's result."""
|
|
119
|
-
return
|
|
120
|
-
matching_key=key,
|
|
121
|
+
return ImpressionDecorated(
|
|
122
|
+
Impression(matching_key=key,
|
|
121
123
|
feature_name=feature,
|
|
122
124
|
treatment=result['treatment'],
|
|
123
125
|
label=result['impression']['label'] if self._labels_enabled else None,
|
|
124
126
|
change_number=result['impression']['change_number'],
|
|
125
127
|
bucketing_key=bucketing,
|
|
126
|
-
time=utctime_ms())
|
|
128
|
+
time=utctime_ms()),
|
|
129
|
+
disabled=result['impressions_disabled'])
|
|
127
130
|
|
|
128
131
|
def _build_impressions(self, key, bucketing, results):
|
|
129
132
|
"""Build an impression based on evaluation data & it's result."""
|
|
@@ -198,7 +201,7 @@ class Client(ClientBase): # pylint: disable=too-many-instance-attributes
|
|
|
198
201
|
:rtype: Client
|
|
199
202
|
"""
|
|
200
203
|
ClientBase.__init__(self, factory, recorder, labels_enabled)
|
|
201
|
-
self._context_factory = EvaluationDataFactory(factory._get_storage('splits'), factory._get_storage('segments'))
|
|
204
|
+
self._context_factory = EvaluationDataFactory(factory._get_storage('splits'), factory._get_storage('segments'), factory._get_storage('rule_based_segments'))
|
|
202
205
|
|
|
203
206
|
def destroy(self):
|
|
204
207
|
"""
|
|
@@ -296,8 +299,8 @@ class Client(ClientBase): # pylint: disable=too-many-instance-attributes
|
|
|
296
299
|
result = self._FAILED_EVAL_RESULT
|
|
297
300
|
|
|
298
301
|
if result['impression']['label'] != Label.SPLIT_NOT_FOUND:
|
|
299
|
-
|
|
300
|
-
self._record_stats([(
|
|
302
|
+
impression_decorated = self._build_impression(key, bucketing, feature, result)
|
|
303
|
+
self._record_stats([(impression_decorated, attributes)], start, method)
|
|
301
304
|
|
|
302
305
|
return result['treatment'], result['configurations']
|
|
303
306
|
|
|
@@ -571,23 +574,23 @@ class Client(ClientBase): # pylint: disable=too-many-instance-attributes
|
|
|
571
574
|
self._telemetry_evaluation_producer.record_exception(method)
|
|
572
575
|
results = {n: self._FAILED_EVAL_RESULT for n in features}
|
|
573
576
|
|
|
574
|
-
|
|
577
|
+
imp_decorated_attrs = [
|
|
575
578
|
(i, attributes) for i in self._build_impressions(key, bucketing, results)
|
|
576
|
-
if i.label != Label.SPLIT_NOT_FOUND
|
|
579
|
+
if i.Impression.label != Label.SPLIT_NOT_FOUND
|
|
577
580
|
]
|
|
578
|
-
self._record_stats(
|
|
581
|
+
self._record_stats(imp_decorated_attrs, start, method)
|
|
579
582
|
|
|
580
583
|
return {
|
|
581
584
|
feature: (results[feature]['treatment'], results[feature]['configurations'])
|
|
582
585
|
for feature in results
|
|
583
586
|
}
|
|
584
587
|
|
|
585
|
-
def _record_stats(self,
|
|
588
|
+
def _record_stats(self, impressions_decorated, start, operation):
|
|
586
589
|
"""
|
|
587
590
|
Record impressions.
|
|
588
591
|
|
|
589
|
-
:param
|
|
590
|
-
:type
|
|
592
|
+
:param impressions_decorated: Generated impressions
|
|
593
|
+
:type impressions_decorated: list[tuple[splitio.models.impression.ImpressionDecorated, dict]]
|
|
591
594
|
|
|
592
595
|
:param start: timestamp when get_treatment or get_treatments was called
|
|
593
596
|
:type start: int
|
|
@@ -596,7 +599,7 @@ class Client(ClientBase): # pylint: disable=too-many-instance-attributes
|
|
|
596
599
|
:type operation: str
|
|
597
600
|
"""
|
|
598
601
|
end = get_current_epoch_time_ms()
|
|
599
|
-
self._recorder.record_treatment_stats(
|
|
602
|
+
self._recorder.record_treatment_stats(impressions_decorated, get_latency_bucket_index(end - start),
|
|
600
603
|
operation, 'get_' + operation.value)
|
|
601
604
|
|
|
602
605
|
def track(self, key, traffic_type, event_type, value=None, properties=None):
|
|
@@ -665,7 +668,7 @@ class ClientAsync(ClientBase): # pylint: disable=too-many-instance-attributes
|
|
|
665
668
|
:rtype: Client
|
|
666
669
|
"""
|
|
667
670
|
ClientBase.__init__(self, factory, recorder, labels_enabled)
|
|
668
|
-
self._context_factory = AsyncEvaluationDataFactory(factory._get_storage('splits'), factory._get_storage('segments'))
|
|
671
|
+
self._context_factory = AsyncEvaluationDataFactory(factory._get_storage('splits'), factory._get_storage('segments'), factory._get_storage('rule_based_segments'))
|
|
669
672
|
|
|
670
673
|
async def destroy(self):
|
|
671
674
|
"""
|
|
@@ -763,8 +766,8 @@ class ClientAsync(ClientBase): # pylint: disable=too-many-instance-attributes
|
|
|
763
766
|
result = self._FAILED_EVAL_RESULT
|
|
764
767
|
|
|
765
768
|
if result['impression']['label'] != Label.SPLIT_NOT_FOUND:
|
|
766
|
-
|
|
767
|
-
await self._record_stats([(
|
|
769
|
+
impression_decorated = self._build_impression(key, bucketing, feature, result)
|
|
770
|
+
await self._record_stats([(impression_decorated, attributes)], start, method)
|
|
768
771
|
return result['treatment'], result['configurations']
|
|
769
772
|
|
|
770
773
|
async def get_treatments(self, key, feature_flag_names, attributes=None):
|
|
@@ -960,23 +963,23 @@ class ClientAsync(ClientBase): # pylint: disable=too-many-instance-attributes
|
|
|
960
963
|
await self._telemetry_evaluation_producer.record_exception(method)
|
|
961
964
|
results = {n: self._FAILED_EVAL_RESULT for n in features}
|
|
962
965
|
|
|
963
|
-
|
|
966
|
+
imp_decorated_attrs = [
|
|
964
967
|
(i, attributes) for i in self._build_impressions(key, bucketing, results)
|
|
965
|
-
if i.label != Label.SPLIT_NOT_FOUND
|
|
968
|
+
if i.Impression.label != Label.SPLIT_NOT_FOUND
|
|
966
969
|
]
|
|
967
|
-
await self._record_stats(
|
|
970
|
+
await self._record_stats(imp_decorated_attrs, start, method)
|
|
968
971
|
|
|
969
972
|
return {
|
|
970
973
|
feature: (res['treatment'], res['configurations'])
|
|
971
974
|
for feature, res in results.items()
|
|
972
975
|
}
|
|
973
976
|
|
|
974
|
-
async def _record_stats(self,
|
|
977
|
+
async def _record_stats(self, impressions_decorated, start, operation):
|
|
975
978
|
"""
|
|
976
979
|
Record impressions for async calls
|
|
977
980
|
|
|
978
|
-
:param
|
|
979
|
-
:type
|
|
981
|
+
:param impressions_decorated: Generated impressions decorated
|
|
982
|
+
:type impressions_decorated: list[tuple[splitio.models.impression.Impression, dict]]
|
|
980
983
|
|
|
981
984
|
:param start: timestamp when get_treatment or get_treatments was called
|
|
982
985
|
:type start: int
|
|
@@ -985,7 +988,7 @@ class ClientAsync(ClientBase): # pylint: disable=too-many-instance-attributes
|
|
|
985
988
|
:type operation: str
|
|
986
989
|
"""
|
|
987
990
|
end = get_current_epoch_time_ms()
|
|
988
|
-
await self._recorder.record_treatment_stats(
|
|
991
|
+
await self._recorder.record_treatment_stats(impressions_decorated, get_latency_bucket_index(end - start),
|
|
989
992
|
operation, 'get_' + operation.value)
|
|
990
993
|
|
|
991
994
|
async def track(self, key, traffic_type, event_type, value=None, properties=None):
|