Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare 6.5.0 release #100

Merged
merged 6 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions NOTICE.txt

This file was deleted.

10 changes: 7 additions & 3 deletions ldclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ def all_flags_state(self, user, **kwargs):
:param kwargs: optional parameters affecting how the state is computed: set
`client_side_only=True` to limit it to only flags that are marked for use with the
client-side SDK (by default, all flags are included); set `with_reasons=True` to
include evaluation reasons in the state (see `variation_detail`)
include evaluation reasons in the state (see `variation_detail`); set
`details_only_for_tracked_flags=True` to omit any metadata that is normally only
used for event generation, such as flag versions and evaluation reasons, unless
the flag has event tracking or debugging turned on
:return: a FeatureFlagsState object (will never be None; its 'valid' property will be False
if the client is offline, has not been initialized, or the user is None or has no key)
:rtype: FeatureFlagsState
Expand All @@ -319,6 +322,7 @@ def all_flags_state(self, user, **kwargs):
state = FeatureFlagsState(True)
client_only = kwargs.get('client_side_only', False)
with_reasons = kwargs.get('with_reasons', False)
details_only_if_tracked = kwargs.get('details_only_for_tracked_flags', False)
try:
flags_map = self._store.all(FEATURES, lambda x: x)
if flags_map is None:
Expand All @@ -333,12 +337,12 @@ def all_flags_state(self, user, **kwargs):
try:
detail = evaluate(flag, user, self._store, False).detail
state.add_flag(flag, detail.value, detail.variation_index,
detail.reason if with_reasons else None)
detail.reason if with_reasons else None, details_only_if_tracked)
except Exception as e:
log.error("Error evaluating flag \"%s\" in all_flags_state: %s" % (key, e))
log.debug(traceback.format_exc())
reason = {'kind': 'ERROR', 'errorKind': 'EXCEPTION'}
state.add_flag(flag, None, None, reason if with_reasons else None)
state.add_flag(flag, None, None, reason if with_reasons else None, details_only_if_tracked)

return state

Expand Down
155 changes: 0 additions & 155 deletions ldclient/expiringdict.py

This file was deleted.

18 changes: 14 additions & 4 deletions ldclient/flags_state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import time

class FeatureFlagsState(object):
"""
Expand All @@ -12,15 +13,24 @@ def __init__(self, valid):
self.__flag_metadata = {}
self.__valid = valid

def add_flag(self, flag, value, variation, reason):
def add_flag(self, flag, value, variation, reason, details_only_if_tracked):
"""Used internally to build the state map."""
key = flag['key']
self.__flag_values[key] = value
meta = { 'version': flag.get('version'), 'trackEvents': flag.get('trackEvents') }
meta = {}
with_details = (not details_only_if_tracked) or flag.get('trackEvents')
if not with_details:
if flag.get('debugEventsUntilDate'):
now = int(time.time() * 1000)
with_details = (flag.get('debugEventsUntilDate') > now)
if with_details:
meta['version'] = flag.get('version')
if reason is not None:
meta['reason'] = reason
if variation is not None:
meta['variation'] = variation
if reason is not None:
meta['reason'] = reason
if flag.get('trackEvents'):
meta['trackEvents'] = True
if flag.get('debugEventsUntilDate') is not None:
meta['debugEventsUntilDate'] = flag.get('debugEventsUntilDate')
self.__flag_metadata[key] = meta
Expand Down
2 changes: 1 addition & 1 deletion ldclient/redis_feature_store.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
from pprint import pprint

from expiringdict import ExpiringDict
import redis

from ldclient import log
from ldclient.expiringdict import ExpiringDict
from ldclient.interfaces import FeatureStore
from ldclient.memoized_value import MemoizedValue
from ldclient.versioned_data_kind import FEATURES
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
backoff>=1.4.3
certifi>=2018.4.16
expiringdict>=1.1.4
future>=0.16.0
six>=1.10.0
pyRFC3339>=1.0
Expand Down
21 changes: 10 additions & 11 deletions testing/test_flags_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def test_can_get_flag_value():
state = FeatureFlagsState(True)
flag = { 'key': 'key' }
state.add_flag(flag, 'value', 1, None)
state.add_flag(flag, 'value', 1, None, False)
assert state.get_flag_value('key') == 'value'

def test_returns_none_for_unknown_flag():
Expand All @@ -17,16 +17,16 @@ def test_can_convert_to_values_map():
state = FeatureFlagsState(True)
flag1 = { 'key': 'key1' }
flag2 = { 'key': 'key2' }
state.add_flag(flag1, 'value1', 0, None)
state.add_flag(flag2, 'value2', 1, None)
state.add_flag(flag1, 'value1', 0, None, False)
state.add_flag(flag2, 'value2', 1, None, False)
assert state.to_values_map() == { 'key1': 'value1', 'key2': 'value2' }

def test_can_convert_to_json_dict():
state = FeatureFlagsState(True)
flag1 = { 'key': 'key1', 'version': 100, 'offVariation': 0, 'variations': [ 'value1' ], 'trackEvents': False }
flag2 = { 'key': 'key2', 'version': 200, 'offVariation': 1, 'variations': [ 'x', 'value2' ], 'trackEvents': True, 'debugEventsUntilDate': 1000 }
state.add_flag(flag1, 'value1', 0, None)
state.add_flag(flag2, 'value2', 1, None)
state.add_flag(flag1, 'value1', 0, None, False)
state.add_flag(flag2, 'value2', 1, None, False)

result = state.to_json_dict()
assert result == {
Expand All @@ -35,8 +35,7 @@ def test_can_convert_to_json_dict():
'$flagsState': {
'key1': {
'variation': 0,
'version': 100,
'trackEvents': False
'version': 100
},
'key2': {
'variation': 1,
Expand All @@ -52,8 +51,8 @@ def test_can_convert_to_json_string():
state = FeatureFlagsState(True)
flag1 = { 'key': 'key1', 'version': 100, 'offVariation': 0, 'variations': [ 'value1' ], 'trackEvents': False }
flag2 = { 'key': 'key2', 'version': 200, 'offVariation': 1, 'variations': [ 'x', 'value2' ], 'trackEvents': True, 'debugEventsUntilDate': 1000 }
state.add_flag(flag1, 'value1', 0, None)
state.add_flag(flag2, 'value2', 1, None)
state.add_flag(flag1, 'value1', 0, None, False)
state.add_flag(flag2, 'value2', 1, None, False)

obj = state.to_json_dict()
str = state.to_json_string()
Expand All @@ -63,8 +62,8 @@ def test_can_serialize_with_jsonpickle():
state = FeatureFlagsState(True)
flag1 = { 'key': 'key1', 'version': 100, 'offVariation': 0, 'variations': [ 'value1' ], 'trackEvents': False }
flag2 = { 'key': 'key2', 'version': 200, 'offVariation': 1, 'variations': [ 'x', 'value2' ], 'trackEvents': True, 'debugEventsUntilDate': 1000 }
state.add_flag(flag1, 'value1', 0, None)
state.add_flag(flag2, 'value2', 1, None)
state.add_flag(flag1, 'value1', 0, None, False)
state.add_flag(flag2, 'value2', 1, None, False)

obj = state.to_json_dict()
str = jsonpickle.encode(state, unpicklable=False)
Expand Down
61 changes: 58 additions & 3 deletions testing/test_ldclient_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import json
import time
from ldclient.client import LDClient, Config
from ldclient.feature_store import InMemoryFeatureStore
from ldclient.flag import EvaluationDetail
Expand Down Expand Up @@ -149,8 +150,7 @@ def test_all_flags_state_returns_state():
'$flagsState': {
'key1': {
'variation': 0,
'version': 100,
'trackEvents': False
'version': 100
},
'key2': {
'variation': 1,
Expand All @@ -176,7 +176,6 @@ def test_all_flags_state_returns_state_with_reasons():
'key1': {
'variation': 0,
'version': 100,
'trackEvents': False,
'reason': {'kind': 'OFF'}
},
'key2': {
Expand Down Expand Up @@ -229,6 +228,62 @@ def test_all_flags_state_can_be_filtered_for_client_side_flags():
values = state.to_values_map()
assert values == { 'client-side-1': 'value1', 'client-side-2': 'value2' }

def test_all_flags_state_can_omit_details_for_untracked_flags():
future_time = (time.time() * 1000) + 100000
flag1 = {
'key': 'key1',
'version': 100,
'on': False,
'offVariation': 0,
'variations': [ 'value1' ],
'trackEvents': False
}
flag2 = {
'key': 'key2',
'version': 200,
'on': False,
'offVariation': 1,
'variations': [ 'x', 'value2' ],
'trackEvents': True
}
flag3 = {
'key': 'key3',
'version': 300,
'on': False,
'offVariation': 1,
'variations': [ 'x', 'value3' ],
'debugEventsUntilDate': future_time
}
store = InMemoryFeatureStore()
store.init({ FEATURES: { 'key1': flag1, 'key2': flag2, 'key3': flag3 } })
client = make_client(store)
state = client.all_flags_state(user, with_reasons=True, details_only_for_tracked_flags=True)
assert state.valid == True
result = state.to_json_dict()
assert result == {
'key1': 'value1',
'key2': 'value2',
'key3': 'value3',
'$flagsState': {
'key1': {
'variation': 0
},
'key2': {
'variation': 1,
'version': 200,
'trackEvents': True,
'reason': {'kind': 'OFF'}
},
'key3': {
'variation': 1,
'version': 300,
'debugEventsUntilDate': future_time,
'reason': {'kind': 'OFF'}
}
},
'$valid': True
}

def test_all_flags_state_returns_empty_state_if_user_is_none():
store = InMemoryFeatureStore()
store.init({ FEATURES: { 'key1': flag1, 'key2': flag2 } })
Expand Down