-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Percentage-based Enablement for Feature Toggle #1952
Percentage-based Enablement for Feature Toggle #1952
Conversation
self.account_id = account_id | ||
self.region = region | ||
|
||
def is_enabled(self, feature_name): |
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.
Why is this method needed? e.g. instead of moving the if
to the actual call?
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 renamed is_enabled_for_account_in_region
to this one, removed is_enabled_for_stage_in_region
. What is_enabled_for_stage_in_region
does is already done in is_enabled_for_account_in_region
.
I also made stage
, account_id
, region
required when instanciating FeatureToggle
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.
Nice! Turned out really nice! 👍
# if partition < enabled_percent, we consider the feature is enabled for this given account_id | ||
enabled_percent = region_config["enabled-%"] | ||
partition = int(account_id) % 100 | ||
is_enabled = partition < enabled_percent |
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 automate this dial up or enablement by specifiying start and end time in UTC. this way its automatically controlled dialup once the config is on appconfig, without needing any pushes for dialup.
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.
If we have plans for dial-up/down, we could make this generic from the get-go. The percentage is linear between start/end percentages during the time interval, and an always-on dial is an open interval (e.g. end is infinite).
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.
Let's just handle the simple percentage-based enablement in this PR first. We can consider automated dial up later
else: | ||
region_config = stage_config[region] if region in stage_config else stage_config.get("default", {}) | ||
|
||
if "enabled-%" in region_config: |
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.
Would it make sense to refactor this if-else block away so that it's easier to reason about the core logic and adapt to more complex toggles (e.g. linear)?
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.
Yeah that makes sense
Codecov Report
@@ Coverage Diff @@
## develop #1952 +/- ##
===========================================
+ Coverage 93.88% 94.12% +0.24%
===========================================
Files 90 91 +1
Lines 5954 5995 +41
Branches 1213 1214 +1
===========================================
+ Hits 5590 5643 +53
+ Misses 168 159 -9
+ Partials 196 193 -3
Continue to review full report at Codecov.
|
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.
Just some nits, otherwise looks good.
* Percentage-based Enablement for Feature Toggle * Update Feature Toggle to accept stage, account_id and region during instanciation * remove unnecessary uses of dict.get method * Refactor feature toggle methods * Update test names * black reformat * Update FeatureToggle to require stage, region and account_id to instanciate * Update log message * Implement calculating account percentile based on hash of account_id and feature_name * Refactor _is_feature_enabled_for_region_config * Refactor dialup logic into its own classes * Add comments for dialup classes * Rename NeverEnabledDialup to DisabledDialup
* test: New test group to test for side effects (#2046) * test: New test group to test for side effects * refactor: Updated to use _compare_transform and test CN and GOV partitions * docs: fix dead link (#2045) * Percentage-based Enablement for Feature Toggle (#1952) * Percentage-based Enablement for Feature Toggle * Update Feature Toggle to accept stage, account_id and region during instanciation * remove unnecessary uses of dict.get method * Refactor feature toggle methods * Update test names * black reformat * Update FeatureToggle to require stage, region and account_id to instanciate * Update log message * Implement calculating account percentile based on hash of account_id and feature_name * Refactor _is_feature_enabled_for_region_config * Refactor dialup logic into its own classes * Add comments for dialup classes * Rename NeverEnabledDialup to DisabledDialup * chore(tests): Adding any tests (#2053) * Adding api_request_model any tests * Add any to api_request_model_openapi_3 cases * Add rest of relevant any test cases * Fix hashing to match python2 * add api_with_swagger_authorizer_none to be run * fix py2 hashes in api_with_swagger_authorizer_none tests Co-authored-by: Jacob Fuss <[email protected]> * Add modes support for RestApi (#2055) * Adding Mode passthrough property to RestApi with unit tests. * Adding integration test for Mode * Fixing sam-translate for manual translation. * running black formatting * Running black formatting, again. * Clearing pip-wheel-metadata. * Clearing tmp folder created by integ test. Co-authored-by: Tarun Mall <[email protected]> * chore: bump version to 1.38.0 (#2081) Co-authored-by: Mathieu Grandis <[email protected]> Co-authored-by: Chris Rehn <[email protected]> Co-authored-by: Wing Fung Lau <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Tarun Mall <[email protected]> Co-authored-by: Raymond Wang <[email protected]>
* test: New test group to test for side effects (#2046) * test: New test group to test for side effects * refactor: Updated to use _compare_transform and test CN and GOV partitions * docs: fix dead link (#2045) * Percentage-based Enablement for Feature Toggle (#1952) * Percentage-based Enablement for Feature Toggle * Update Feature Toggle to accept stage, account_id and region during instanciation * remove unnecessary uses of dict.get method * Refactor feature toggle methods * Update test names * black reformat * Update FeatureToggle to require stage, region and account_id to instanciate * Update log message * Implement calculating account percentile based on hash of account_id and feature_name * Refactor _is_feature_enabled_for_region_config * Refactor dialup logic into its own classes * Add comments for dialup classes * Rename NeverEnabledDialup to DisabledDialup * chore(tests): Adding any tests (#2053) * Adding api_request_model any tests * Add any to api_request_model_openapi_3 cases * Add rest of relevant any test cases * Fix hashing to match python2 * add api_with_swagger_authorizer_none to be run * fix py2 hashes in api_with_swagger_authorizer_none tests Co-authored-by: Jacob Fuss <[email protected]> * Add modes support for RestApi (#2055) * Adding Mode passthrough property to RestApi with unit tests. * Adding integration test for Mode * Fixing sam-translate for manual translation. * running black formatting * Running black formatting, again. * Clearing pip-wheel-metadata. * Clearing tmp folder created by integ test. Co-authored-by: Tarun Mall <[email protected]> * chore: bump version to 1.38.0 (#2081) Co-authored-by: Mathieu Grandis <[email protected]> Co-authored-by: Chris Rehn <[email protected]> Co-authored-by: Wing Fung Lau <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Tarun Mall <[email protected]> Co-authored-by: Raymond Wang <[email protected]> Co-authored-by: Mathieu Grandis <[email protected]> Co-authored-by: Chris Rehn <[email protected]> Co-authored-by: Wing Fung Lau <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Tarun Mall <[email protected]> Co-authored-by: Raymond Wang <[email protected]>
Issue #, if available:
Description of changes:
Add support for Percentage-based Enablement for Feature Toggle.
When
enabled-%
is set (instead ofenabled
) under a region config,is_enabled_for_account_in_region(...)
will determine whether the givenaccount_id
falls in the percentage range for feature enablement.Description of how you validated changes:
Added more tests
Checklist:
make pr
passesExamples?
Please reach out in the comments, if you want to add an example. Examples will be
added to
sam init
through https://github.com/awslabs/aws-sam-cli-app-templates/By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.