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

Feature request: Time based feature flags actions #1554

Closed
1 of 2 tasks
ran-isenberg opened this issue Sep 29, 2022 · 11 comments
Closed
1 of 2 tasks

Feature request: Time based feature flags actions #1554

ran-isenberg opened this issue Sep 29, 2022 · 11 comments
Assignees
Labels
feature_flags Feature Flags utility feature-request feature request

Comments

@ran-isenberg
Copy link
Contributor

ran-isenberg commented Sep 29, 2022

Use case

I've got a few use cases for feature flags rule actions. It's possible to due that today but its really finicky.

  1. I'd like to turn on/enable a feature flags rule only during a certain time of the day (between 10:00-23:00 24 hours clock)
  2. i'd like to turn on/enable a feature flags rule during a certain date range (UTC time)
  3. i'd like to turn on/enable a feature flags rule only during weekends, or just weekdays
  4. i'd like to turn on/enable a feature flags rule during certain week days and certain hours

I'd like to be able to do combine these conditions with other conditions.

I think the implementation is simple, just need to define the UX.

Solution/User Experience

Time based conditions are sorely missing from the current solution.

Alternative solutions

use regular actions. Use rules that define time as unix time ints and define actions like KEY_GREATER_THAN_VALUE and KEY_LESS_THAN_VALUE.
Not really readable when using unix time ints but it can work.
Not agreat UX.

Acknowledgment

@ran-isenberg ran-isenberg added feature-request feature request triage Pending triage from maintainers labels Sep 29, 2022
@ran-isenberg ran-isenberg changed the title Time based feature flags rules Time based feature flags actions Sep 29, 2022
@ran-isenberg
Copy link
Contributor Author

@heitorlessa I think I can create a PR if we agree about necessity/basic user experience, i.e how the rule will look like in the JSON. The actions and their tests should be simple enough to create.

@heitorlessa heitorlessa self-assigned this Oct 4, 2022
@heitorlessa
Copy link
Contributor

Assigning to myself so I can read it fully tomorrow

@heitorlessa
Copy link
Contributor

It sounds sensible to me, thanks for pulling this together as a user story format! I have three immediate concerns:

  1. This may not be precise due to clock differences so messaging must set the right expectations.
    • [Suggestion] Any maintainer can help with that.
  2. Depending on how the data is in the schema, we need to be careful with the algorithm to avoid a performance bottleneck (type conversion * N condition). Be prepared for potential compromises.
    • [Suggestion] Load testing would be a requirement to understand the impact on more realistic use cases.
  3. I'd love to see some UX examples before going full blown on the implementation.
    • [Suggestion] Start with a fork, and let's keep this issue going before a PR. We need to get V2 out of the door ASAP, so I'd like to avoid increasing context switching on maintainers leading to sub-optimal UX here and V2 launch.

@heitorlessa heitorlessa added area/feature_flags and removed triage Pending triage from maintainers labels Oct 5, 2022
@heitorlessa heitorlessa changed the title Time based feature flags actions Feature request: Time based feature flags actions Oct 5, 2022
@ran-isenberg
Copy link
Contributor Author

@heitorlessa take a look at this branch:
992371f

I think the UX is nice. Note that you dont need to supply any key to the context.
I think we can optimize the current date/time calculation at the start of the evaluate if we know we have date conditions and also store the string based full date into unix time int.

WDYT?

@ran-isenberg
Copy link
Contributor Author

btw, if we used pydantic to store & parse the conf, this feature could have even simpler :)
maybe sometime in the future ;)

@heitorlessa heitorlessa added the triage Pending triage from maintainers label Oct 24, 2022
@heitorlessa
Copy link
Contributor

Updating here as @leandrodamascena will dedicate the next days reviewing, testing, load testing, and co-authoring this feature with you Ran!

I'll be looking after everything else that's coming to the repo for the next two weeks, as Ruben will be away.

@leandrodamascena
Copy link
Contributor

Hi @heitorlessa and @ran-isenberg!
First of all, thank you so much for sharing your code with us Ran! This made the initial steps much easier.

I'm still at the beginning of the code but I can already validate a feature flag with a condition for specific days of the week. What do you think about me opening a PR in the next few days and we can work to improve and validate that @ran-isenberg? There will definitely be things to change or improve and we can work together on that.

For now, see this example:

SAM app.py

from aws_lambda_powertools.utilities.feature_flags import FeatureFlags, AppConfigStore
from aws_lambda_powertools import Logger

logger = Logger(sampling_rate=1,level="DEBUG")

app_config = AppConfigStore(
    environment="dev",
    application="comments",
    name="features",
    logger=logger
)

feature_flags = FeatureFlags(store=app_config, logger=logger)

def lambda_handler(event, context):

    ctx = { "tier": "premium", "CURRENT_DAY_UTC": ["tHuRsDaY","MONDAY"]}
    has_premium_features: bool = feature_flags.evaluate(name="premium_features",
                                                        context=ctx, default=False)
    print(has_premium_features)
    if has_premium_features:
        print("RULE MATCH")

JSON

{
  "premium_features": {
    "default": false,
    "rules": {
      "customer tier equals premium": {
        "when_match": true,
        "conditions": [
          {
            "action": "EQUALS",
            "key": "tier",
            "value": "premium"
          },
          {
            "action": "TIME_SELECTED_DAYS",
            "key": "CURRENT_DAY_UTC",
            "value": "THURSDAY"
          }
        ]
      }
    }
  }
}

Lambda execution
image

@ran-isenberg
Copy link
Contributor Author

@leandrodamascena I've also been working on a PR. I'll create a PR later today so we could merge the code.

@ran-isenberg
Copy link
Contributor Author

see my comments on #1666

@heitorlessa heitorlessa added triage Pending triage from maintainers and removed triage Pending triage from maintainers labels Oct 31, 2022
@heitorlessa heitorlessa added feature_flags Feature Flags utility and removed area/feature_flags labels Nov 9, 2022
@heitorlessa heitorlessa linked a pull request Nov 10, 2022 that will close this issue
12 tasks
@heitorlessa
Copy link
Contributor

heitorlessa commented Nov 14, 2022

Finishing leftover tasks today and blocked tomorrow morning to start catch up on the history @leandrodamascena and you discussed, and do a proper review/contribute this week

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jan 19, 2023
@github-actions
Copy link
Contributor

This is now released under 2.7.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jan 24, 2023
@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature_flags Feature Flags utility feature-request feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants