1212from splitio .client .client import Client
1313from splitio .client import input_validator
1414from splitio .client .manager import SplitManager
15- from splitio .client .config import DEFAULT_CONFIG
15+ from splitio .client .config import sanitize as sanitize_config
1616from splitio .client import util
1717from splitio .client .listener import ImpressionListenerWrapper
1818from splitio .engine .impressions import Manager as ImpressionsManager
3838# Tasks
3939from splitio .tasks .split_sync import SplitSynchronizationTask
4040from splitio .tasks .segment_sync import SegmentSynchronizationTask
41- from splitio .tasks .impressions_sync import ImpressionsSyncTask
41+ from splitio .tasks .impressions_sync import ImpressionsSyncTask , ImpressionsCountSyncTask
4242from splitio .tasks .events_sync import EventsSyncTask
4343from splitio .tasks .telemetry_sync import TelemetrySynchronizationTask
4444
@@ -234,13 +234,11 @@ def _wrap_impression_listener(listener, metadata):
234234 return None
235235
236236
237- def _build_in_memory_factory (api_key , config , sdk_url = None , events_url = None ): # pylint: disable=too-many-locals
237+ def _build_in_memory_factory (api_key , cfg , sdk_url = None , events_url = None ): # pylint: disable=too-many-locals
238238 """Build and return a split factory tailored to the supplied config."""
239239 if not input_validator .validate_factory_instantiation (api_key ):
240240 return None
241241
242- cfg = DEFAULT_CONFIG .copy ()
243- cfg .update (config )
244242 http_client = HttpClient (
245243 sdk_url = sdk_url ,
246244 events_url = events_url ,
@@ -272,6 +270,12 @@ def _build_in_memory_factory(api_key, config, sdk_url=None, events_url=None): #
272270 segments_ready_flag = threading .Event ()
273271 sdk_ready_flag = threading .Event ()
274272
273+ imp_manager = ImpressionsManager (
274+ storages ['impressions' ].put ,
275+ cfg ['impressionsMode' ],
276+ True ,
277+ _wrap_impression_listener (cfg ['impressionListener' ], sdk_metadata ))
278+
275279 tasks = {
276280 'splits' : SplitSynchronizationTask (
277281 apis ['splits' ],
@@ -295,6 +299,11 @@ def _build_in_memory_factory(api_key, config, sdk_url=None, events_url=None): #
295299 cfg ['impressionsBulkSize' ]
296300 ),
297301
302+ 'impressions_count' : ImpressionsCountSyncTask (
303+ apis ['impressions' ],
304+ imp_manager
305+ ),
306+
298307 'events' : EventsSyncTask (
299308 apis ['events' ],
300309 storages ['events' ],
@@ -312,6 +321,7 @@ def _build_in_memory_factory(api_key, config, sdk_url=None, events_url=None): #
312321 # Start tasks that have no dependencies
313322 tasks ['splits' ].start ()
314323 tasks ['impressions' ].start ()
324+ tasks ['impressions_count' ].start ()
315325 tasks ['events' ].start ()
316326 tasks ['telemetry' ].start ()
317327
@@ -334,22 +344,13 @@ def segment_ready_task():
334344 segment_completion_thread = threading .Thread (target = segment_ready_task )
335345 segment_completion_thread .setDaemon (True )
336346 segment_completion_thread .start ()
337- return SplitFactory (
338- api_key ,
339- storages ,
340- cfg ['labelsEnabled' ],
341- ImpressionsManager (storages ['impressions' ].put , cfg ['impressionsMode' ], True ,
342- _wrap_impression_listener (cfg ['impressionListener' ], sdk_metadata )),
343- apis ,
344- tasks ,
345- sdk_ready_flag ,
346- )
347347
348+ return SplitFactory (api_key , storages , cfg ['labelsEnabled' ],
349+ imp_manager , apis , tasks , sdk_ready_flag )
348350
349- def _build_redis_factory (api_key , config ):
351+
352+ def _build_redis_factory (api_key , cfg ):
350353 """Build and return a split factory with redis-based storage."""
351- cfg = DEFAULT_CONFIG .copy ()
352- cfg .update (config )
353354 sdk_metadata = util .get_metadata (cfg )
354355 redis_adapter = redis .build (cfg )
355356 cache_enabled = cfg .get ('redisLocalCacheEnabled' , False )
@@ -370,10 +371,8 @@ def _build_redis_factory(api_key, config):
370371 )
371372
372373
373- def _build_uwsgi_factory (api_key , config ):
374+ def _build_uwsgi_factory (api_key , cfg ):
374375 """Build and return a split factory with redis-based storage."""
375- cfg = DEFAULT_CONFIG .copy ()
376- cfg .update (config )
377376 sdk_metadata = util .get_metadata (cfg )
378377 uwsgi_adapter = get_uwsgi ()
379378 storages = {
@@ -392,10 +391,8 @@ def _build_uwsgi_factory(api_key, config):
392391 )
393392
394393
395- def _build_localhost_factory (config ):
394+ def _build_localhost_factory (cfg ):
396395 """Build and return a localhost factory for testing/development purposes."""
397- cfg = DEFAULT_CONFIG .copy ()
398- cfg .update (config )
399396 storages = {
400397 'splits' : InMemorySplitStorage (),
401398 'segments' : InMemorySegmentStorage (), # not used, just to avoid possible future errors.
@@ -413,12 +410,12 @@ def _build_localhost_factory(config):
413410 )}
414411 tasks ['splits' ].start ()
415412 return SplitFactory (
416- 'localhost' ,
417- storages ,
418- False ,
413+ 'localhost' ,
414+ storages ,
415+ False ,
419416 ImpressionsManager (storages ['impressions' ].put , cfg ['impressionsMode' ], True , None ),
420- None ,
421- tasks ,
417+ None ,
418+ tasks ,
422419 ready_event
423420 )
424421
@@ -444,15 +441,15 @@ def get_factory(api_key, **kwargs):
444441 "(Singleton pattern) and reusing it throughout your application."
445442 )
446443
447- config = kwargs .get ('config' , {})
444+ config = sanitize_config ( api_key , kwargs .get ('config' , {}) )
448445
449- if api_key == 'localhost' :
446+ if config [ 'operationMode' ] == 'localhost-standalone ' :
450447 return _build_localhost_factory (config )
451448
452- if 'redisHost' in config or 'redisSentinels' in config :
449+ if config [ 'operationMode' ] == 'redis-consumer' :
453450 return _build_redis_factory (api_key , config )
454451
455- if 'uwsgiClient' in config :
452+ if config [ 'operationMode' ] == 'uwsgi-consumer' :
456453 return _build_uwsgi_factory (api_key , config )
457454
458455 return _build_in_memory_factory (
0 commit comments