-
Notifications
You must be signed in to change notification settings - Fork 36
feat: add decide api #309
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
feat: add decide api #309
Changes from 22 commits
35a6eac
509ff50
0ef34ee
61fe356
c8cabbd
dc226c1
366030e
fd99ec1
36b0328
19b7fae
ffa40d6
13ec677
5feca2c
4c4b4a4
460c904
0d4ec50
8b5d56d
a1cbc68
67fc4f2
f3e3854
c38dbfc
2c1f8b0
9517442
4f00cb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Copyright 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 | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright 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 | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| class DecideOption(object): | ||
| DISABLE_DECISION_EVENT = 'DISABLE_DECISION_EVENT' | ||
| ENABLED_FLAGS_ONLY = 'ENABLED_FLAGS_ONLY' | ||
| IGNORE_USER_PROFILE_SERVICE = 'IGNORE_USER_PROFILE_SERVICE' | ||
| INCLUDE_REASONS = 'INCLUDE_REASONS' | ||
| EXCLUDE_VARIABLES = 'EXCLUDE_VARIABLES' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Copyright 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 | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| class Decision(object): | ||
|
||
| def __init__(self, variation_key=None, enabled=None, | ||
| variables=None, rule_key=None, flag_key=None, user_context=None, reasons=None): | ||
| self.variation_key = variation_key | ||
| self.enabled = enabled or False | ||
| self.variables = variables or {} | ||
| self.rule_key = rule_key | ||
| self.flag_key = flag_key | ||
| self.user_context = user_context | ||
| self.reasons = reasons or [] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Copyright 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 | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| class DecisionMessage(object): | ||
| SDK_NOT_READY = 'Optimizely SDK not configured properly yet.' | ||
| FLAG_KEY_INVALID = 'No flag was found for key "%s".' | ||
| VARIABLE_VALUE_INVALID = 'Variable value for key "%s" is invalid or wrong type.' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -301,6 +301,7 @@ def get_variation_for_rollout(self, project_config, rollout, user_id, attributes | |
| rollout: Rollout for which we are getting the variation. | ||
| user_id: ID for user. | ||
| attributes: Dict representing user attributes. | ||
| ignore_user_profile: True if we should bypass the user profile service | ||
|
|
||
| Returns: | ||
| Decision namedtuple consisting of experiment and variation for the user. | ||
|
|
@@ -390,14 +391,15 @@ def get_experiment_in_group(self, project_config, group, bucketing_id): | |
|
|
||
| return None | ||
|
|
||
| def get_variation_for_feature(self, project_config, feature, user_id, attributes=None): | ||
| def get_variation_for_feature(self, project_config, feature, user_id, attributes=None, ignore_user_profile=False): | ||
|
Contributor
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. It's interesting - I see that python-sdk already has "ignore_user_profile" option. We can keep the current structure to reuse it, but I'm concerned we may need to add options to support other options later. |
||
| """ Returns the experiment/variation the user is bucketed in for the given feature. | ||
|
|
||
| Args: | ||
| project_config: Instance of ProjectConfig. | ||
| feature: Feature for which we are determining if it is enabled or not for the given user. | ||
| user_id: ID for user. | ||
| attributes: Dict representing user attributes. | ||
| ignore_user_profile: True if you want to bypass the user profile service | ||
|
|
||
| Returns: | ||
| Decision namedtuple consisting of experiment and variation for the user. | ||
|
|
@@ -411,7 +413,7 @@ def get_variation_for_feature(self, project_config, feature, user_id, attributes | |
| if group: | ||
| experiment = self.get_experiment_in_group(project_config, group, bucketing_id) | ||
| if experiment and experiment.id in feature.experimentIds: | ||
| variation = self.get_variation(project_config, experiment, user_id, attributes) | ||
| variation = self.get_variation(project_config, experiment, user_id, attributes, ignore_user_profile) | ||
|
|
||
| if variation: | ||
| return Decision(experiment, variation, enums.DecisionSources.FEATURE_TEST) | ||
|
|
@@ -423,7 +425,7 @@ def get_variation_for_feature(self, project_config, feature, user_id, attributes | |
| # If an experiment is not in a group, then the feature can only be associated with one experiment | ||
| experiment = project_config.get_experiment_from_id(feature.experimentIds[0]) | ||
| if experiment: | ||
| variation = self.get_variation(project_config, experiment, user_id, attributes) | ||
| variation = self.get_variation(project_config, experiment, user_id, attributes, ignore_user_profile) | ||
|
|
||
| if variation: | ||
| return Decision(experiment, variation, enums.DecisionSources.FEATURE_TEST) | ||
|
|
||
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.
Can we change the name to "OptimizelyDecideOption"?
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.
that is not consistent with the rest of the sdk
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.
Done in 314