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

Percentage-based Enablement for Feature Toggle #1952

Merged

Conversation

hawflau
Copy link
Contributor

@hawflau hawflau commented Mar 3, 2021

Issue #, if available:

Description of changes:
Add support for Percentage-based Enablement for Feature Toggle.
When enabled-% is set (instead of enabled) under a region config, is_enabled_for_account_in_region(...) will determine whether the given account_id falls in the percentage range for feature enablement.

Description of how you validated changes:
Added more tests

Checklist:

  • Write/update tests
  • make pr passes
  • Update documentation
  • Verify transformed template deploys and application functions as expected

Examples?

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.

c2tarun
c2tarun previously requested changes Mar 3, 2021
samtranslator/feature_toggle/feature_toggle.py Outdated Show resolved Hide resolved
self.account_id = account_id
self.region = region

def is_enabled(self, feature_name):
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 method needed? e.g. instead of moving the if to the actual call?

Copy link
Contributor Author

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

Copy link
Contributor

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! 👍

@hawflau hawflau requested review from hoffa and c2tarun March 4, 2021 00:56
# 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
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 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.

Copy link
Contributor

@hoffa hoffa Mar 4, 2021

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).

Copy link
Contributor Author

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

@hawflau hawflau requested a review from sriram-mv March 6, 2021 04:36
else:
region_config = stage_config[region] if region in stage_config else stage_config.get("default", {})

if "enabled-%" in region_config:
Copy link
Contributor

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)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that makes sense

samtranslator/feature_toggle/feature_toggle.py Outdated Show resolved Hide resolved
samtranslator/feature_toggle/feature_toggle.py Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Mar 11, 2021

Codecov Report

Merging #1952 (8ab6be3) into develop (68a3e1c) will increase coverage by 0.24%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
samtranslator/feature_toggle/dialup.py 100.00% <100.00%> (ø)
samtranslator/feature_toggle/feature_toggle.py 100.00% <100.00%> (+12.16%) ⬆️
samtranslator/translator/translator.py 98.52% <100.00%> (ø)
samtranslator/translator/logical_id_generator.py 100.00% <0.00%> (+9.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68a3e1c...8ab6be3. Read the comment docs.

@hawflau hawflau requested a review from sriram-mv March 11, 2021 23:32
Copy link
Contributor

@sriram-mv sriram-mv left a 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.

samtranslator/feature_toggle/dialup.py Outdated Show resolved Hide resolved
@hawflau hawflau dismissed c2tarun’s stale review May 28, 2021 17:49

request is already outdated

@hawflau hawflau merged commit 69d910d into aws:develop Jun 9, 2021
c2tarun pushed a commit to c2tarun/serverless-application-model that referenced this pull request Jul 7, 2021
* 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
c2tarun added a commit that referenced this pull request Jul 8, 2021
* 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]>
@c2tarun c2tarun mentioned this pull request Jul 16, 2021
4 tasks
c2tarun added a commit that referenced this pull request Jul 19, 2021
* 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]>
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