Skip to content

Conversation

leandrodamascena
Copy link
Contributor

@leandrodamascena leandrodamascena commented Jan 19, 2023

Issue number: #1554

This PR was created from this other PR: #1666. Click to read the entire interaction.

Summary

Use cases:

  • Enable maintenance mode during a weekend
  • Disable support/chat feature after working hours
  • Launch a new feature on a specific date and time

Changes

  1. Added new condition actions, key and values (see user experience examples)
  2. Added tests
  3. Added documentation
  4. Added new schema validation

New actions: SCHEDULE_BETWEEN_TIME_RANGE, SCHEDULE_BETWEEN_DATETIME_RANGE, SCHEDULE_BETWEEN_DAYS_OF_WEEK

New keys: CURRENT_TIME, CURRENT_DATETIME, CURRENT_DAY_OF_WEEK

New values : a dict of START and END string values and a list of all weekdays. Also an optional TIMEZONE field supporting IANA Time zones. When not specified, we assume UTC.

Assumption: time is in 24 hours format, start time is always smaller than end time and it does not overlap a day.

User experience

  1. Time range

As a customer, I'd like to flip a static flag value when evaluated between 11:11 and 23:59.

{
    "my_feature": {
        "default": false,
        "rules": {
            "lambda time is between UTC 11:11-23:59": {
                "when_match": true,
                "conditions": [
                    {
                        "action": "SCHEDULE_BETWEEN_TIME_RANGE",
                        "key": "CURRENT_TIME",
                        "value": {
                            "START_TIME": "11:11",
                            "END_TIME": "23:59",
                            "TIMEZONE": "Europe/Copenahgen"
                        }
                    }
                ]
            }
        }
    }
}
  1. Date range

As a customer, I'd like to flip a static flag when evaluated between full datetime ranges 2022-10-05T12:15:00Z to 2022-10-10T12:15:00Z.

{
    "my_feature": {
        "default": false,
        "rules": {
            "lambda time is between UTC october 5th 2022 12:14:32PM to october 10th 2022 12:15:00 PM": {
                "when_match": true,
                "conditions": [
                    {
                        "action": "SCHEDULE_BETWEEN_DATETIME_RANGE",
                        "key": "CURRENT_DATETIME",
                        "value": {
                            "START_TIME": "2022-10-05T12:15:00",
                            "END_TIME": "2022-10-10T12:15:00",
                            "TIMEZONE": "America/Los_Angeles"
                        }
                    }
                ]
            }
        }
    }
}

Selected days

As a customer, I'd like to flip a static flag when evaluated between Monday to Friday.

{
    "my_feature": {
        "default": false,
        "rules": {
            "match only monday through friday": {
                "when_match": true,
                "conditions": [
                    {
                        "action": "SCHEDULE_BETWEEN_DAYS_OF_WEEK",
                        "key": "CURRENT_DAY_OF_WEEK",
                        "value": {
                            "DAYS": [
                               "MONDAY",
                               "TUESDAY",
                               "WEDNESDAY",
                               "THURSDAY",
                               "FRIDAY"
                             ],
                             "TIMEZONE": "America/New_York" 
                        }
                    }
                ]
            }
        }
    }
}

Day and time range combined

As a customer, I'd like to flip a static flag when evaluated Monday-Friday between 11:00 and 23:00 (UTC).

{
    "my_feature": {
        "default": false,
        "rules": {
            "match when lambda time is between UTC 11:00-23:00 and day is either monday or thursday": {
                "when_match": true,
                "conditions": [
                    {
                        "action": "SCHEDULE_BETWEEN_TIME_RANGE",
                        "key": "CURRENT_TIME",
                        "value": {
                            "START_TIME": "11:00",
                            "END_TIME": "23:00"
                        }
                    },
                    {
                        "action": "SCHEDULE_BETWEEN_DAYS_OF_WEEK",
                        "key": "CURRENT_DAY_OF_WEEK",
                        "value": 
                            "DAYS": [
                                "MONDAY",
                                "THURSDAY"
                            ]
                    }
                ]
            }
        }
    }
}

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

Tasks

  • Update documentation with realistic use cases
  • Rename _UTC suffix in keys, and implement the timezone field on the value (use python-dateutil)
  • Run a performance assessment
  • Review logging information
  • Review docstrings and comments

@leandrodamascena leandrodamascena requested a review from a team as a code owner January 19, 2023 14:11
@leandrodamascena leandrodamascena requested review from heitorlessa and removed request for a team January 19, 2023 14:11
@boring-cyborg boring-cyborg bot added dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation tests labels Jan 19, 2023
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jan 19, 2023
@github-actions github-actions bot added the feature New feature or functionality label Jan 19, 2023
@github-actions
Copy link
Contributor

No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure.

@github-actions github-actions bot added do-not-merge need-issue PRs that are missing related issues labels Jan 19, 2023
@leandrodamascena leandrodamascena removed do-not-merge need-issue PRs that are missing related issues labels Jan 19, 2023
@github-actions
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

1 similar comment
@github-actions
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@codecov-commenter
Copy link

codecov-commenter commented Jan 19, 2023

Codecov Report

Base: 97.59% // Head: 97.51% // Decreases project coverage by -0.08% ⚠️

Coverage data is based on head (08d2e29) compared to base (d4feaed).
Patch coverage: 93.75% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1846      +/-   ##
===========================================
- Coverage    97.59%   97.51%   -0.08%     
===========================================
  Files          142      143       +1     
  Lines         6444     6567     +123     
  Branches       444      465      +21     
===========================================
+ Hits          6289     6404     +115     
- Misses         123      128       +5     
- Partials        32       35       +3     
Impacted Files Coverage Δ
...ambda_powertools/utilities/feature_flags/schema.py 97.19% <93.54%> (-2.81%) ⬇️
...ertools/utilities/feature_flags/time_conditions.py 93.54% <93.54%> (ø)
...owertools/utilities/feature_flags/feature_flags.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@github-actions
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

1 similar comment
@github-actions
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@leandrodamascena leandrodamascena merged commit 5dc0f25 into aws-powertools:develop Jan 19, 2023
@leandrodamascena leandrodamascena deleted the feat/feature-flags-time-based branch January 19, 2023 17:26
royygael added a commit to royygael/aws-lambda-powertools-python that referenced this pull request Feb 8, 2023
The PR aws-powertools#1846 added a breaking change to RuleAction which not serializes the enum thus when used as an enum it breaks.

Signed-off-by: royygael <116807865+royygael@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation feature New feature or functionality size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants