Skip to content

refactor: moved validated forced decision to decision service. #293

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

Merged
merged 5 commits into from
Jan 7, 2022

Conversation

ozayr-zaviar
Copy link
Contributor

Summary

  • find_validated_forced_decision moved to decision service.

Test plan

  • All unit tests and FSC should pass.

@coveralls
Copy link

coveralls commented Dec 22, 2021

Coverage Status

Coverage increased (+7.0e-05%) to 99.453% when pulling 27bf929 on uzair/move-validate-forced-decision into be870fe on master.

@@ -199,7 +199,7 @@ def decide(user_context, key, decide_options = [])
experiment = nil
decision_source = Optimizely::DecisionService::DECISION_SOURCES['ROLLOUT']
context = Optimizely::OptimizelyUserContext::OptimizelyDecisionContext.new(key, nil)
variation, reasons_received = user_context.find_validated_forced_decision(context)
variation, reasons_received = @decision_service.validated_forced_decision(context, user_context)
Copy link
Contributor

Choose a reason for hiding this comment

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

please keep the method name find_validated_forced_decision

Comment on lines +422 to +423
flag_key = context[:flag_key]
rule_key = context[:rule_key]
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move this code inside the if block since it is only used there?

Comment on lines +431 to +432
reasons.push(reason)
return variation, reasons
Copy link
Contributor

Choose a reason for hiding this comment

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

this code can be moved to line 436, that way we won't have reasons.push(reason) twice.

@@ -26,6 +26,7 @@ class OptimizelyUserContext
attr_reader :forced_decisions
attr_reader :OptimizelyDecisionContext
attr_reader :OptimizelyForcedDecision
attr_reader :optimizely_client
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this needed when we are only removing a method here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also update the Copyright header with 2020-2021

@@ -26,6 +26,7 @@ class OptimizelyUserContext
attr_reader :forced_decisions
attr_reader :OptimizelyDecisionContext
attr_reader :OptimizelyForcedDecision
attr_reader :optimizely_client
Copy link
Contributor

Choose a reason for hiding this comment

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

Also update the Copyright header with 2020-2021

@msohailhussain msohailhussain requested a review from jaeopt January 5, 2022 23:55
@msohailhussain msohailhussain marked this pull request as ready for review January 5, 2022 23:55
@msohailhussain msohailhussain requested a review from a team as a code owner January 5, 2022 23:55
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.

A couple of changes suggested

@@ -417,6 +417,28 @@ def get_forced_variation(project_config, experiment_key, user_id)
[variation, decide_reasons]
end

def validated_forced_decision(context, user_context)
decision = user_context.find_forced_decision(context)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove find_forced_decision and use get_forced_decision. Since we remove sanity checking, they're now identical.

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.

See comments

reasons = []
target = rule_key ? "flag (#{flag_key}), rule (#{rule_key})" : "flag (#{flag_key})"
if variation_key
variation = user_context.optimizely_client.get_flag_variation(flag_key, variation_key, 'key')
Copy link
Contributor

@jaeopt jaeopt Jan 6, 2022

Choose a reason for hiding this comment

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

I don't know what happened to my previous comments on this line. github bug? :)
We need to change this line to same as other SDKs - pass 'config' as a parameter and move get_flag_variation to config, so we can remove dependency to user_context.optimizely_client here.

@msohailhussain msohailhussain requested a review from jaeopt January 6, 2022 20:17
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

@msohailhussain msohailhussain merged commit 2a75b42 into master Jan 7, 2022
@msohailhussain msohailhussain deleted the uzair/move-validate-forced-decision branch January 7, 2022 06:03
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.

5 participants