Skip to content

Commit ed34c51

Browse files
author
Matias Melograno
committed
refactored code
1 parent c4a1d74 commit ed34c51

File tree

6 files changed

+10
-64
lines changed

6 files changed

+10
-64
lines changed

splitio/brokers.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ def get_change_number(self):
8080
"""
8181
return self.get_split_fetcher().change_number
8282

83-
def log_impression(self, impression):
84-
"""
85-
Logs an impression after a get_treatment call
86-
:return: The treatment log implementation.
87-
:rtype: TreatmentLog
88-
"""
89-
return self.get_impression_log().log(impression)
90-
9183
def log_impressions(self, impressions):
9284
"""
9385
Logs impressions after a get_treatments call

splitio/clients.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def get_treatment(self, key, feature, attributes=None):
130130
self._record_stats(impression, start, SDK_GET_TREATMENT)
131131

132132
self._send_impression_to_listener(impression, attributes)
133-
except Exception:
133+
except Exception: # pylint: disable=broad-except
134134
self._logger.exception(
135135
'Exception reporting impression into get_treatment exception block'
136136
)
@@ -165,7 +165,7 @@ def get_treatments(self, key, features, attributes=None):
165165
bulk_impressions = []
166166
treatments = {}
167167

168-
if (matching_key is None and bucketing_key is None):
168+
if matching_key is None and bucketing_key is None:
169169
for feature in features:
170170
impression = self._build_impression(matching_key, feature, CONTROL, Label.EXCEPTION,
171171
0, bucketing_key, start)

splitio/config.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,19 @@
6161

6262
GLOBAL_KEY_PARAMETERS = {
6363
'sdk-language-version': SDK_VERSION,
64-
'instance-id': 'unknown',
65-
'ip-address': 'unknown',
64+
'instance-id': get_hostname(),
65+
'ip-address': get_ip(),
6666
}
6767

6868

6969
def set_machine_ip(machine_ip):
7070
if machine_ip:
7171
GLOBAL_KEY_PARAMETERS['ip-address'] = machine_ip
72-
else:
73-
GLOBAL_KEY_PARAMETERS['ip-address'] = get_ip()
7472

7573

7674
def set_machine_name(machine_name):
7775
if machine_name:
7876
GLOBAL_KEY_PARAMETERS['instance-id'] = machine_name
79-
else:
80-
GLOBAL_KEY_PARAMETERS['instance-id'] = get_hostname()
8177

8278

8379
def parse_config_file(filename):

splitio/evaluator.py

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from splitio.splitters import Splitter
55
from splitio.key import Key
66
from splitio.treatments import CONTROL
7-
from . import input_validator
87

98

109
class Evaluator(object):
@@ -27,13 +26,13 @@ def evaluate_treatment(self, feature, matching_key, bucketing_key, attributes=No
2726
Evaluates the user submitted data against a feature and return the resulting treatment.
2827
2928
:param feature: The feature for which to get the treatment
30-
:type string: feature
29+
:type feature: str
3130
3231
:param matching_key: The matching_key for which to get the treatment
33-
:type string: str
32+
:type matching_key: str
3433
3534
:param bucketing_key: The bucketing_key for which to get the treatment
36-
:type string: str
35+
:type bucketing_key: str
3736
3837
:param attributes: An optional dictionary of attributes
3938
:type attributes: dict
@@ -131,44 +130,3 @@ def get_treatment_for_split(self, split, matching_key, bucketing_key, attributes
131130

132131
# No condition matches
133132
return None, None
134-
135-
def get_treatment(self, key, feature, attributes=None):
136-
"""
137-
Evaluate a feature and return the appropriate traetment.
138-
Will not generate impressions nor metrics
139-
:param key: user key
140-
:type key: mixed
141-
:param feature: feature name
142-
:type feature: str
143-
:param attributes: (Optional) attributes associated with the user key
144-
:type attributes: dict
145-
"""
146-
matching_key, bucketing_key = input_validator.validate_key(key)
147-
feature = input_validator.validate_feature_name(feature)
148-
if (matching_key is None and bucketing_key is None) or feature is None:
149-
return CONTROL
150-
try:
151-
# Fetching Split definition
152-
split = self._broker.fetch_feature(feature)
153-
if split is None:
154-
self._logger.warning(
155-
'Unknown or invalid dependent feature: %s',
156-
feature
157-
)
158-
return CONTROL
159-
if split.killed:
160-
return split.default_treatment
161-
treatment, _ = self.get_treatment_for_split(
162-
split,
163-
matching_key,
164-
bucketing_key,
165-
attributes
166-
)
167-
if treatment is None:
168-
return split.default_treatment
169-
return treatment
170-
except Exception: # pylint: disable=broad-except
171-
self._logger.exception(
172-
'Exception caught retrieving dependent feature. Returning CONTROL'
173-
)
174-
return CONTROL

splitio/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def get_ip():
1717
s.connect(('10.255.255.255', 1))
1818
IP = s.getsockname()[0]
1919
except Exception:
20-
IP = '127.0.0.1'
20+
IP = 'unknown'
2121
finally:
2222
s.close()
2323
return IP
2424

2525

2626
def get_hostname():
2727
ip = get_ip()
28-
return 'ip-' + ip.replace('.', '-')
28+
return 'unknown' if ip != '' else 'ip-' + ip.replace('.', '-')

splitio/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '6.3.0'
1+
__version__ = '6.3.0-rc1'

0 commit comments

Comments
 (0)