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

Refact: Refactored Forced decision #365

Merged

Conversation

msohailhussain
Copy link
Contributor

@msohailhussain msohailhussain commented Nov 29, 2021

Summary

  • Removed get_variation_from_experiment_rule and get_variation_from_delivery_rule from decision service.
  • flag_variations_map logic improved using existing loops and removed get_all_variations_for_each_rule.
  • Unit test fixed.

Test plan

All FSC and unit tests should pass

@@ -100,6 +100,7 @@ def __init__(self, datafile, logger, error_handler):
self.variation_variable_usage_map = {}
self.variation_id_map_by_experiment_id = {}
self.variation_key_map_by_experiment_id = {}
self.flag_variations_map = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

holding this PR for now...

@@ -215,6 +195,28 @@ def get_rollout_experiments(self, rollout):

return rollout_experiments

def get_rules_for_flag(self, feature_flag):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't make sense to add this method.

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change suggested

if rollout:
rollout_experiments = rollout.experiments
for exp in rollout_experiments:
rules.append(self.experiment_id_map[exp['id']])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand experiment_id_map is for ab-tests only, not including rollout rules. Did it pass our tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All unit tests and FSC is passing.

@@ -120,46 +121,25 @@ def __init__(self, datafile, logger, error_handler):
)

self.feature_key_map = self._generate_key_map(self.feature_flags, 'key', entities.FeatureFlag)

self.flag_variations_map = self.generate_feature_variation_map(self.feature_flags)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line 103

@coveralls
Copy link

coveralls commented Dec 1, 2021

Coverage Status

Coverage decreased (-0.2%) to 95.879% when pulling 39ab0b0 on uzair/project-config-refactor into ab40d9e on mpirnovar/forced_decisions.


if experiment:
# variation, variation_reasons = self.get_variation_from_experiment_rule(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove commented out code?

Copy link
Contributor

@mnoman09 mnoman09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments overall looks good.


if experiment:
# variation, variation_reasons = self.get_variation_from_experiment_rule(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this commented code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing this code with travis. Will remove it on finalization.


if rollout and rollout.experiments:
experiments.extend(rollout_experiments)
# Dict containing map of experiment ID to feature ID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Dict containing map of experiment ID to feature ID.
# Dictionary containing dictionary of experiment ID to feature ID.

# Dict containing map of experiment ID to feature ID.
# for checking that experiment is a feature experiment or not.
self.experiment_feature_map = {}
for feature in self.feature_key_map.values():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we running this loop again see line 127 can we reuse it?

@ozayr-zaviar ozayr-zaviar changed the title project config refactor Refact: Refactored Forced decision Dec 2, 2021
Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@The-inside-man The-inside-man left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All lgtm, seems a few tests are failing in CI for pypy3, even after rerunning several times. I dont see this as a concern right now and can be addressed later as this seems to be a common issue with these versions of Python.

@msohailhussain
Copy link
Contributor Author

All lgtm, seems a few tests are failing in CI for pypy3, even after rerunning several times. I dont see this as a concern right now and can be addressed later as this seems to be a common issue with these versions of Python.

true.

@msohailhussain msohailhussain merged commit dbbc051 into mpirnovar/forced_decisions Dec 2, 2021
@msohailhussain msohailhussain deleted the uzair/project-config-refactor branch December 2, 2021 19:11
Mat001 added a commit that referenced this pull request Dec 6, 2021
* add maps to project config

* initial code

* feat: add remaining implementation

* WIP: addressed implementation PR comments and fixed failing unit tests

* Fixed lint errors

* fix failing tests in py 3.5

* fixed failing logger import for Py2

* add OptimizelyDecisionContext and OptmizelyForcedDecisions

* testcases added

* Update optimizely/optimizely_user_context.py

Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com>

* Update optimizely/optimizely_user_context.py

Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com>

* Update optimizely/optimizely_user_context.py

Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com>

* make rule key optional in OptimizelyDecisionContext

* Mutex lock and testcases added

* Update optimizely/optimizely_user_context.py

Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com>

* use get() vs [] in remove_forced_decision

* add missing colon

* fix displaying reasons

* Update optimizely/optimizely.py

Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com>

* address PR comments

* more PR review fixes

* fixed few more PR comments

* added bucket reasons

* FSC fixes

* addressed more PR comments, fixed FSC test failuer about impressin events

* address more PR comments

* use is_valid check on opti client

* addressed more PR comments

* reasons and key name fixed

* create get_default method for empty experiment object

* fixed further PR comments

* fix logger so we use the top logger in optimizely client

* Refact: Refactored Forced decision (#365)

* project config refactor

* use existing loop to generate flag_variation_map

* get_variation_from_experiment_rule and get_variation_from_delivery_rule removed

* fsc test fix

* comment addressed

* commented code removed

* comments from main forced decision PR resolved

Co-authored-by: ozayr-zaviar <uzairzaviar@gmail.com>

* coupl of corrections

* remove check on config

* remove redundant import

* remove redundant test about invalid datafile

* add reasons to return

Co-authored-by: ozayr-zaviar <uzairzaviar@gmail.com>
Co-authored-by: ozayr-zaviar <54209343+ozayr-zaviar@users.noreply.github.com>
Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com>
Co-authored-by: msohailhussain <mirza.sohailhussain@gmail.com>
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

Successfully merging this pull request may close these issues.

6 participants