Skip to content

Commit 2bd9704

Browse files
authored
Merge pull request #549 from splitio/impression-toggle-engine
updated impressions and evaluator classes
2 parents ec814eb + 2a0297e commit 2bd9704

File tree

4 files changed

+148
-54
lines changed

4 files changed

+148
-54
lines changed

splitio/engine/evaluator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def eval_with_context(self, key, bucketing, feature_name, attrs, ctx):
6767
'impression': {
6868
'label': label,
6969
'change_number': _change_number
70-
}
70+
},
71+
'track': feature.trackImpressions
7172
}
7273

7374
def _treatment_for_flag(self, flag, key, bucketing, attributes, ctx):

splitio/engine/impressions/impressions.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ImpressionsMode(Enum):
1111
class Manager(object): # pylint:disable=too-few-public-methods
1212
"""Impression manager."""
1313

14-
def __init__(self, strategy, telemetry_runtime_producer):
14+
def __init__(self, strategy, none_strategy, telemetry_runtime_producer):
1515
"""
1616
Construct a manger to track and forward impressions to the queue.
1717
@@ -23,19 +23,33 @@ def __init__(self, strategy, telemetry_runtime_producer):
2323
"""
2424

2525
self._strategy = strategy
26+
self._none_strategy = none_strategy
2627
self._telemetry_runtime_producer = telemetry_runtime_producer
2728

28-
def process_impressions(self, impressions):
29+
def process_impressions(self, impressions_decorated):
2930
"""
3031
Process impressions.
3132
3233
Impressions are analyzed to see if they've been seen before and counted.
3334
34-
:param impressions: List of impression objects with attributes
35-
:type impressions: list[tuple[splitio.models.impression.Impression, dict]]
35+
:param impressions_decorated: List of impression objects with attributes
36+
:type impressions_decorated: list[tuple[splitio.models.impression.ImpressionDecorated, dict]]
3637
3738
:return: processed and deduped impressions.
3839
:rtype: tuple(list[tuple[splitio.models.impression.Impression, dict]], list(int))
3940
"""
40-
for_log, for_listener, for_counter, for_unique_keys_tracker = self._strategy.process_impressions(impressions)
41-
return for_log, len(impressions) - len(for_log), for_listener, for_counter, for_unique_keys_tracker
41+
for_listener_all = []
42+
for_log_all = []
43+
for_counter_all = []
44+
for_unique_keys_tracker_all = []
45+
for impression_decorated, att in impressions_decorated:
46+
if not impression_decorated.track:
47+
for_log, for_listener, for_counter, for_unique_keys_tracker = self._none_strategy.process_impressions([(impression_decorated.Impression, att)])
48+
else:
49+
for_log, for_listener, for_counter, for_unique_keys_tracker = self._strategy.process_impressions([(impression_decorated.Impression, att)])
50+
for_listener_all.extend(for_listener)
51+
for_log_all.extend(for_log)
52+
for_counter_all.extend(for_counter)
53+
for_unique_keys_tracker_all.extend(for_unique_keys_tracker)
54+
55+
return for_log_all, len(impressions_decorated) - len(for_log_all), for_listener_all, for_counter_all, for_unique_keys_tracker_all

tests/engine/test_evaluator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def test_evaluate_treatment_ok(self, mocker):
5252
assert result['impression']['change_number'] == 123
5353
assert result['impression']['label'] == 'some_label'
5454
assert mocked_split.get_configurations_for.mock_calls == [mocker.call('on')]
55+
assert result['track'] == mocked_split.trackImpressions
5556

5657

5758
def test_evaluate_treatment_ok_no_config(self, mocker):

0 commit comments

Comments
 (0)