question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Time based feature flags actions

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ran-isenbergcommented, Oct 28, 2022

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

1reaction
leandrodamascenacommented, Oct 27, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Time-Based Features with Feature Flags - Reflectoring
Time -based features in a software application are a pain to test. To test such a feature, you can (and should) write unit...
Read more >
Feature Flags: The Hidden Switch Behind Continuous ...
Feature flags allows you to ship code more frequently, test on production, and wow your users by revealing the feature at the right...
Read more >
Feature Toggles (aka Feature Flags) - Martin Fowler
These are feature flags used to enable trunk-based development for teams practicing Continuous Delivery. They allow in-progress features to be checked into a ......
Read more >
How we ship code faster and safer with feature flags
Using feature flags allows us to work on features incrementally. Only staff members working on the project have the corresponding feature flag ......
Read more >
Feature Flags Best Practices (Feature Toggles) - Harness
We recommend giving feature flags human-readable names to help make feature flag management easier over time. While this won't solve the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found