@@ -19,7 +19,7 @@ def missing_redis_dependencies(*args, **kwargs):
1919
2020from six import iteritems
2121
22- from splitio .config import import_from_string
22+ from splitio .config import import_from_string , GLOBAL_KEY_PARAMETERS
2323from splitio .cache import SegmentCache , SplitCache , ImpressionsCache , \
2424 MetricsCache
2525from splitio .matchers import UserDefinedSegmentMatcher
@@ -29,14 +29,9 @@ def missing_redis_dependencies(*args, **kwargs):
2929from splitio .impressions import Impression
3030from splitio .utils import bytes_to_string
3131from splitio .prefix_decorator import PrefixDecorator
32- from splitio .version import __version__ as _SDK_VERSION
3332# Template for Split.io related Cache keys
3433_SPLITIO_CACHE_KEY_TEMPLATE = 'SPLITIO.{suffix}'
35- _GLOBAL_KEY_PARAMETERS = {
36- 'sdk-language-version' : 'python-{version}' .format (version = _SDK_VERSION ),
37- 'instance-id' : 'unknown' ,
38- 'ip-address' : 'unknown' ,
39- }
34+
4035IMPRESSIONS_QUEUE_KEY = 'SPLITIO.impressions'
4136IMPRESSION_KEY_DEFAULT_TTL = 3600
4237
@@ -273,9 +268,9 @@ def log_event(self, event):
273268 to_store = {
274269 'e' : dict (event ._asdict ()),
275270 'm' : {
276- 's' : _GLOBAL_KEY_PARAMETERS ['sdk-language-version' ],
277- 'n' : _GLOBAL_KEY_PARAMETERS ['instance-id' ],
278- 'i' : _GLOBAL_KEY_PARAMETERS ['ip-address' ],
271+ 's' : GLOBAL_KEY_PARAMETERS ['sdk-language-version' ],
272+ 'n' : GLOBAL_KEY_PARAMETERS ['instance-id' ],
273+ 'i' : GLOBAL_KEY_PARAMETERS ['ip-address' ],
279274 }
280275 }
281276 try :
@@ -296,7 +291,7 @@ def _get_impressions_key(cls, feature_name):
296291 '''
297292 '''
298293 return cls ._KEY_TEMPLATE .format (
299- ** dict (_GLOBAL_KEY_PARAMETERS , feature = feature_name )
294+ ** dict (GLOBAL_KEY_PARAMETERS , feature = feature_name )
300295 )
301296
302297 @classmethod
@@ -314,7 +309,7 @@ def __init__(self, redis):
314309 self ._redis = redis
315310 self ._logger = logging .getLogger (self .__class__ .__name__ )
316311
317- key_params = _GLOBAL_KEY_PARAMETERS .copy ()
312+ key_params = GLOBAL_KEY_PARAMETERS .copy ()
318313 key_params ['suffix' ] = '{feature_name}'
319314
320315 def _build_impressions_dict (self , impressions ):
@@ -397,9 +392,9 @@ def add_impressions(self, impressions):
397392 if isinstance (impression , Impression ):
398393 to_store = {
399394 'm' : { # METADATA PORTION
400- 's' : _GLOBAL_KEY_PARAMETERS ['sdk-language-version' ],
401- 'n' : _GLOBAL_KEY_PARAMETERS ['instance-id' ],
402- 'i' : _GLOBAL_KEY_PARAMETERS ['ip-address' ],
395+ 's' : GLOBAL_KEY_PARAMETERS ['sdk-language-version' ],
396+ 'n' : GLOBAL_KEY_PARAMETERS ['instance-id' ],
397+ 'i' : GLOBAL_KEY_PARAMETERS ['ip-address' ],
403398 },
404399 'i' : { # IMPRESSION PORTION
405400 'k' : impression .matching_key ,
@@ -503,7 +498,7 @@ def _get_latency_bucket_key(cls, metric_name, bucket_number):
503498 Returns the latency bucket
504499 '''
505500 return cls ._KEY_LATENCY .format (** dict (
506- _GLOBAL_KEY_PARAMETERS ,
501+ GLOBAL_KEY_PARAMETERS ,
507502 metric_name = metric_name ,
508503 bucket_number = bucket_number
509504 ))
@@ -514,7 +509,7 @@ def _get_count_key(cls, counter):
514509 Returns the count key
515510 '''
516511 return cls ._KEY_COUNT .format (** dict (
517- _GLOBAL_KEY_PARAMETERS ,
512+ GLOBAL_KEY_PARAMETERS ,
518513 counter = counter
519514 ))
520515
@@ -524,7 +519,7 @@ def _get_gauge_key(cls, gauge):
524519 Returns the gauge key
525520 '''
526521 return cls ._KEY_GAUGE .format (** dict (
527- _GLOBAL_KEY_PARAMETERS ,
522+ GLOBAL_KEY_PARAMETERS ,
528523 gauge = gauge
529524 ))
530525
@@ -534,21 +529,21 @@ def _get_latency_field_re(cls):
534529 .replace ('.' , '\.' )
535530 .replace ('{metric_name}' , '(?P<operation>.+)' )
536531 .replace ('{bucket_number}' , '(?P<bucket_index>.+)' ))
537- ).format (** _GLOBAL_KEY_PARAMETERS )
532+ ).format (** GLOBAL_KEY_PARAMETERS )
538533
539534 @classmethod
540535 def _get_count_field_re (cls ):
541536 return ("^%s$" % (cls ._KEY_COUNT
542537 .replace ('.' , '\.' )
543538 .replace ('{counter}' , '(?P<counter>.+)' ))
544- ).format (** _GLOBAL_KEY_PARAMETERS )
539+ ).format (** GLOBAL_KEY_PARAMETERS )
545540
546541 @classmethod
547542 def _get_gauge_field_re (cls ):
548543 return ("^%s$" % (cls ._KEY_GAUGE
549544 .replace ('.' , '\.' )
550545 .replace ('{gauge}' , '(?P<gauge>.+)' ))
551- ).format (** _GLOBAL_KEY_PARAMETERS )
546+ ).format (** GLOBAL_KEY_PARAMETERS )
552547
553548 def __init__ (self , redis ):
554549 '''
@@ -805,25 +800,13 @@ def contains(self, key):
805800 return self ._split .segment_cache .is_in_segment (self .name , key )
806801
807802
808- def setup_instance_id (instance_id ):
809- '''
810- Setup the correct parameters once the redis-client has been instantiated
811- with a configuration from the client
812- '''
813- if instance_id :
814- _GLOBAL_KEY_PARAMETERS ['instance-id' ] = instance_id
815- else :
816- _GLOBAL_KEY_PARAMETERS ['instance-id' ] = 'unknown'
817-
818-
819803def get_redis (config ):
820804 '''
821805 Build a redis client based on the configuration.
822806 :param config: Dictionary with the contents of the config file.
823807 :type config: dict
824808 :return: A redis client
825809 '''
826- setup_instance_id (config .get ('instance-id' ))
827810 if 'redisFactory' in config :
828811 redis_factory = import_from_string (
829812 config ['redisFactory' ], 'redisFactory'
0 commit comments