-
Notifications
You must be signed in to change notification settings - Fork 36
[AI-FSSDK] [FSSDK-12337] Add Feature Rollout support #499
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
Open
FarhanAnjum-opti
wants to merge
9
commits into
master
Choose a base branch
from
ai/farhananjum-opti/FSSDK-12337-feature-rollouts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+483
−1
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
159ee1b
[AI-FSSDK] [FSSDK-12337] Add Feature Rollout support to project confi…
FarhanAnjum-opti 2fba50e
[AI-FSSDK] [FSSDK-12337] Fix test structure, mypy and ruff compliance
FarhanAnjum-opti d7387ad
[AI-FSSDK] [FSSDK-12337] Simplify feature rollout config parsing
FarhanAnjum-opti ff06d05
[AI-FSSDK] [FSSDK-12337] Restore _get_everyone_else_variation as method
FarhanAnjum-opti 397bacd
[AI-FSSDK] [FSSDK-12337] Add ExperimentTypes constants for type field
FarhanAnjum-opti d95f1e8
[AI-FSSDK] [FSSDK-12337] Type-restrict Experiment.type to ExperimentType
FarhanAnjum-opti 3f05ad8
[AI-FSSDK] [FSSDK-12337] Remove ExperimentTypes class, simplify type …
FarhanAnjum-opti c73f410
[AI-FSSDK] [FSSDK-12337] Return Variation entity from _get_everyone_e…
FarhanAnjum-opti 147b0da
[AI-FSSDK] [FSSDK-12337] Remove redundant tests, keep 6 essential ones
FarhanAnjum-opti 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -232,6 +232,37 @@ def __init__(self, datafile: str | bytes, logger: Logger, error_handler: Any): | |
| self.experiment_feature_map[exp_id] = [feature.id] | ||
| rules.append(self.experiment_id_map[exp_id]) | ||
|
|
||
| # Feature Rollout support: inject the "everyone else" variation | ||
| # into any experiment with type == "feature_rollout" | ||
| everyone_else_variation = self._get_everyone_else_variation(feature) | ||
| if everyone_else_variation is not None: | ||
| for experiment in rules: | ||
| if experiment.type == 'feature_rollout': | ||
| experiment.variations.append({ | ||
| 'id': everyone_else_variation.id, | ||
| 'key': everyone_else_variation.key, | ||
| 'featureEnabled': everyone_else_variation.featureEnabled, | ||
| 'variables': cast( | ||
| list[types.VariableDict], | ||
| everyone_else_variation.variables, | ||
| ), | ||
| }) | ||
| experiment.trafficAllocation.append({ | ||
| 'entityId': everyone_else_variation.id, | ||
| 'endOfRange': 10000, | ||
| }) | ||
| self.variation_key_map[experiment.key][everyone_else_variation.key] = everyone_else_variation | ||
| self.variation_id_map[experiment.key][everyone_else_variation.id] = everyone_else_variation | ||
| self.variation_id_map_by_experiment_id[experiment.id][everyone_else_variation.id] = ( | ||
| everyone_else_variation | ||
| ) | ||
| self.variation_key_map_by_experiment_id[experiment.id][everyone_else_variation.key] = ( | ||
| everyone_else_variation | ||
| ) | ||
| self.variation_variable_usage_map[everyone_else_variation.id] = self._generate_key_map( | ||
| everyone_else_variation.variables, 'id', entities.Variation.VariableUsage | ||
| ) | ||
|
|
||
| flag_id = feature.id | ||
| applicable_holdouts: list[entities.Holdout] = [] | ||
|
|
||
|
|
@@ -667,6 +698,41 @@ def get_rollout_from_id(self, rollout_id: str) -> Optional[entities.Layer]: | |
| self.logger.error(f'Rollout with ID "{rollout_id}" is not in datafile.') | ||
| return None | ||
|
|
||
| def _get_everyone_else_variation(self, flag: entities.FeatureFlag) -> Optional[entities.Variation]: | ||
| """ Get the "everyone else" variation for a feature flag. | ||
|
|
||
| The "everyone else" rule is the last experiment in the flag's rollout, | ||
| and its first variation is the "everyone else" variation. | ||
|
|
||
| Args: | ||
| flag: The feature flag to get the everyone else variation for. | ||
|
|
||
| Returns: | ||
| The "everyone else" Variation entity, or None if not available. | ||
| """ | ||
| if not flag.rolloutId: | ||
| return None | ||
|
|
||
| rollout = self.get_rollout_from_id(flag.rolloutId) | ||
| if not rollout or not rollout.experiments: | ||
| return None | ||
|
|
||
| everyone_else_rule = rollout.experiments[-1] | ||
| variations = everyone_else_rule.get('variations', []) | ||
| if not variations: | ||
| return None | ||
|
|
||
| variation_dict = variations[0] | ||
|
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. Is it save to access? What happen if it is empty |
||
| return entities.Variation( | ||
| id=variation_dict['id'], | ||
| key=variation_dict['key'], | ||
| featureEnabled=bool(variation_dict.get('featureEnabled', False)), | ||
| variables=cast( | ||
| Optional[list[entities.Variable]], | ||
| variation_dict.get('variables'), | ||
| ), | ||
| ) | ||
|
|
||
| def get_variable_value_for_variation( | ||
| self, variable: Optional[entities.Variable], variation: Optional[Union[entities.Variation, VariationDict]] | ||
| ) -> Optional[str]: | ||
|
|
||
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.
We need this condition to the ticket prompt -
if everyone_else is null, we need handle specially. Let's discuss.