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

Unexpected ConsistentHashPercentageBucketer behavior #52

Open
jakekaplan opened this issue Dec 19, 2022 · 0 comments
Open

Unexpected ConsistentHashPercentageBucketer behavior #52

jakekaplan opened this issue Dec 19, 2022 · 0 comments

Comments

@jakekaplan
Copy link

If ConsistentHashPercentageBucketer has a key_whitelist, calling flag.is_enabled() without providing the key as the condition will always result in a consistent score of 0.32 from hashing an empty dictionary. I would expect this to feature to always be enabled instead of it being based on the % given to the bucket.

Example:

from flipper.bucketing import ConsistentHashPercentageBucketer
from flipper import FeatureFlagClient, MemoryFeatureFlagStore
from flipper.bucketing.percentage import Percentage
features = FeatureFlagClient(MemoryFeatureFlagStore())

MY_FEATURE = 'MY_FEATURE'
features.create(MY_FEATURE)
features.enable(MY_FEATURE)

features.set_bucketer(MY_FEATURE, ConsistentHashPercentageBucketer(key_whitelist=["user_id"], percentage=Percentage(0.5)))
features.is_enabled(MY_FEATURE)
>>> True

features.set_bucketer(MY_FEATURE, ConsistentHashPercentageBucketer(key_whitelist=["user_id"], percentage=Percentage(0.31)))
features.is_enabled(MY_FEATURE)
>>> False


item = features._store.get(MY_FEATURE)
item._meta.bucketer._serialize_checks({})
>>> b'[]'
serialized = item._meta.bucketer._serialize_checks({})
hashed = hashlib.sha1(serialized)
score = item._meta.bucketer._score_hash(hashed)
score
>>> 0.32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant