-
Notifications
You must be signed in to change notification settings - Fork 36
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
fix(logs): Fixing log messages for Targeted Rollouts #268
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
113e964
fix(logs): Fixing log messages for Targeted Rollouts
aliabbasrizvi bfc7f25
fixing unit tests
aliabbasrizvi 476afce
wip
aliabbasrizvi cd459e9
WIP
aliabbasrizvi d18ba6b
Fixing unit tests
aliabbasrizvi 9e09ff4
fixing unit tests
aliabbasrizvi 1aa9961
Moving log messages from bucketer to decision_service
aliabbasrizvi 55a7261
lint fix
aliabbasrizvi f03a8ce
Addressing Matt's feedback
aliabbasrizvi 01b552c
Adding tests for audience log testing
aliabbasrizvi d8b6e62
lint fix
aliabbasrizvi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2016-2017, 2019 Optimizely | ||
# Copyright 2016-2017, 2019-2020 Optimizely | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
@@ -38,41 +38,41 @@ def __init__(self): | |
def _generate_unsigned_hash_code_32_bit(self, bucketing_id): | ||
""" Helper method to retrieve hash code. | ||
|
||
Args: | ||
bucketing_id: ID for bucketing. | ||
Args: | ||
bucketing_id: ID for bucketing. | ||
|
||
Returns: | ||
Hash code which is a 32 bit unsigned integer. | ||
""" | ||
Returns: | ||
Hash code which is a 32 bit unsigned integer. | ||
""" | ||
|
||
# Adjusting MurmurHash code to be unsigned | ||
return mmh3.hash(bucketing_id, self.bucket_seed) & UNSIGNED_MAX_32_BIT_VALUE | ||
|
||
def _generate_bucket_value(self, bucketing_id): | ||
""" Helper function to generate bucket value in half-closed interval [0, MAX_TRAFFIC_VALUE). | ||
|
||
Args: | ||
bucketing_id: ID for bucketing. | ||
Args: | ||
bucketing_id: ID for bucketing. | ||
|
||
Returns: | ||
Bucket value corresponding to the provided bucketing ID. | ||
""" | ||
Returns: | ||
Bucket value corresponding to the provided bucketing ID. | ||
""" | ||
|
||
ratio = float(self._generate_unsigned_hash_code_32_bit(bucketing_id)) / MAX_HASH_VALUE | ||
return math.floor(ratio * MAX_TRAFFIC_VALUE) | ||
|
||
def find_bucket(self, project_config, bucketing_id, parent_id, traffic_allocations): | ||
""" Determine entity based on bucket value and traffic allocations. | ||
|
||
Args: | ||
project_config: Instance of ProjectConfig. | ||
bucketing_id: ID to be used for bucketing the user. | ||
parent_id: ID representing group or experiment. | ||
traffic_allocations: Traffic allocations representing traffic allotted to experiments or variations. | ||
Args: | ||
project_config: Instance of ProjectConfig. | ||
bucketing_id: ID to be used for bucketing the user. | ||
parent_id: ID representing group or experiment. | ||
traffic_allocations: Traffic allocations representing traffic allotted to experiments or variations. | ||
|
||
Returns: | ||
Entity ID which may represent experiment or variation. | ||
""" | ||
Returns: | ||
Entity ID which may represent experiment or variation. | ||
""" | ||
|
||
bucketing_key = BUCKETING_ID_TEMPLATE.format(bucketing_id=bucketing_id, parent_id=parent_id) | ||
bucketing_number = self._generate_bucket_value(bucketing_key) | ||
|
@@ -90,20 +90,21 @@ def find_bucket(self, project_config, bucketing_id, parent_id, traffic_allocatio | |
def bucket(self, project_config, experiment, user_id, bucketing_id): | ||
""" For a given experiment and bucketing ID determines variation to be shown to user. | ||
|
||
Args: | ||
project_config: Instance of ProjectConfig. | ||
experiment: Object representing the experiment for which user is to be bucketed. | ||
user_id: ID for user. | ||
bucketing_id: ID to be used for bucketing the user. | ||
Args: | ||
project_config: Instance of ProjectConfig. | ||
experiment: Object representing the experiment or rollout rule in which user is to be bucketed. | ||
user_id: ID for user. | ||
bucketing_id: ID to be used for bucketing the user. | ||
|
||
Returns: | ||
Variation in which user with ID user_id will be put in. None if no variation. | ||
""" | ||
Returns: | ||
Variation in which user with ID user_id will be put in. None if no variation. | ||
""" | ||
|
||
if not experiment: | ||
return None | ||
|
||
# Determine if experiment is in a mutually exclusive group | ||
# Determine if experiment is in a mutually exclusive group. | ||
# This will not affect evaluation of rollout rules. | ||
if experiment.groupPolicy in GROUP_POLICIES: | ||
group = project_config.get_group(experiment.groupId) | ||
|
||
|
@@ -131,10 +132,6 @@ def bucket(self, project_config, experiment, user_id, bucketing_id): | |
variation_id = self.find_bucket(project_config, bucketing_id, experiment.id, experiment.trafficAllocation) | ||
if variation_id: | ||
variation = project_config.get_variation_from_id(experiment.key, variation_id) | ||
project_config.logger.info( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These log messages have been moved to the call site, akin to how log messages are generated for rollouts. |
||
'User "%s" is in variation "%s" of experiment %s.' % (user_id, variation.key, experiment.key) | ||
) | ||
return variation | ||
|
||
project_config.logger.info('User "%s" is in no variation.' % user_id) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe rename
experiment
toexperiment_or_rule
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I will keep it like this for now, given it is the
Experiment
entity.