-
Notifications
You must be signed in to change notification settings - Fork 406
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 #1666
Conversation
@leandrodamascena & @heitorlessa FYI.
WDYT? i think we should start by merging our code and doing a quick CR |
# rule based actions have no user context. the context is the condition key | ||
if cond_action == schema.RuleAction.TIME_RANGE.value or schema.RuleAction.TIME_SELECTED_DAYS: | ||
context_value = condition.get(schema.CONDITION_KEY) | ||
|
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.
# rule based actions have no user context. the context is the condition key | |
if cond_action == schema.RuleAction.TIME_RANGE.value or schema.RuleAction.TIME_SELECTED_DAYS: | |
context_value = condition.get(schema.CONDITION_KEY) | |
# rule based actions have no user context. the context is the condition key | |
if cond_action == schema.RuleAction.TIME_RANGE.value or schema.RuleAction.TIME_SELECTED_DAYS: | |
context_value = condition.get(schema.CONDITION_KEY) | |
if cond_action == schema.RuleAction.TIME_SELECTED_DAYS: | |
if not isinstance(cond_value,list): | |
cond_value = [cond_value] |
With user experience in mind, a value for this condition can be a simple string or a list, so we convert it to a list if it's a string.
That makes sense?
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.
Not sure I agree with this one. I see this action as "IN" so it should be a list.
If you open it to duality of values, it's more confusing.
It also makes inputs such as 'MONDAY, TUESDAY' break the code since you will turn it into a ['MONDAY, TUESDAY' ] which is not correct. I think having it as a list, and validating it as a list will keep it simple.
aws_lambda_powertools/utilities/feature_flags/time_conditions.py
Outdated
Show resolved
Hide resolved
aws_lambda_powertools/utilities/feature_flags/time_conditions.py
Outdated
Show resolved
Hide resolved
Hi @ran-isenberg! Sorry for the delay in responding, but the days have been busy around here.
For these questions, @heitorlessa will help us work it out. I'll be on parental leave for the next few days 👶. |
I hope everything goes well @leandrodamascena ! I'll work on getting the time mocked properly and adding tests for fail use cases. That way when we refactor the code, it would be much easier. TDD for the win :) |
@heitorlessa @leandrodamascena added mocked time. added test for no match. fixed bugs. |
Looking into the UX this morning as promised - One thing to speed up PR reviews later is to add some UX example(s) in the PR body. |
Codecov ReportBase: 97.59% // Head: 97.51% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## develop #1666 +/- ##
===========================================
- Coverage 97.59% 97.51% -0.08%
===========================================
Files 142 143 +1
Lines 6444 6561 +117
Branches 444 464 +20
===========================================
+ Hits 6289 6398 +109
- Misses 123 128 +5
- Partials 32 35 +3
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. |
Adding this here so I can come back to it later today (and for @rubenfonseca after re:Invent) Stream of consciousness for now:
Discuss usage of `strptime` as it's the slowest way to convert ISO string to dateWe're converting ISO8601 strings to datetime objects. There are two known ways to do it:
The first option (currently implemented) is considered the slowest for various reasons (string interpolation, string to integer, etc.). The second option can be up to 40x faster (depending on Python version and machine; 3.9 on mine is 2x). However it doesn't parse the Why worry about this? We don't know how many combinations a single rule could have, so parsing many dates over on every execution can cause a significant slowdown in the execution. In large number of dates (thousands) the slowness can be measured in seconds. Did a super contrived single date parsing with snakeviz to visualize it.
Quick changes pushed as I looked to understand the logic from a high level
Current schema UX at time of writingTime range
{
"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_HOUR_UTC",
"value": {
"START_TIME": "11:11",
"END_TIME": "23:59"
}
}
]
}
}
}
} Date range
{
"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_TIME_UTC",
"value": {
"START_TIME": "2022-10-05T12:15:00Z",
"END_TIME": "2022-10-10T12:15:00Z"
}
}
]
}
}
}
} Selected days
{
"my_feature": {
"default": false,
"rules": {
"match only monday through friday": {
"when_match": true,
"conditions": [
{
"action": "SCHEDULE_BETWEEN_DAYS",
"key": "CURRENT_DAY_UTC",
"value": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY"
]
}
]
}
}
}
} Day and time range combined
{
"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": "TIME_RANGE",
"key": "CURRENT_HOUR_UTC",
"value": {
"START_TIME": "11:00",
"END_TIME": "23:00"
}
},
{
"action": "TIME_SELECTED_DAYS",
"key": "CURRENT_DAY_UTC",
"value": [
"MONDAY",
"THURSDAY"
]
}
]
}
}
}
} |
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.
@ran-isenberg UX wise, if I understood this right, this should support flags that should change state on time, datetime, and days - is that right?
If so, I'd keep TimeKeys
as is, but change RuleAction
to be more precise:
TIME_SELECTED_DAYS
->SCHEDULE_BETWEEN_DAYS
TIME_RANGE
->SCHEDULE_BETWEEN_TIME_RANGE
TIME_RANGE
for full dates ->SCHEDULE_BETWEEN_DATETIME_RANGE
The SCHEDULE
prefix makes it easier to spot what the rule is about (time or value based). The addition of DATETIME_RANGE
makes it explicit based on your logic - if I got it right - that you're comparing between the current_time, start_date, and end_date.
It'll become clearer any better variation (if any) when we write docs for it.
@heitorlessa Thank you for the feedback! |
@heitorlessa I think we need to fail with a schema validation error upon load. |
@heitorlessa @leandrodamascena XXL now :) |
@leandrodamascena will you have time this week to review and make suggestions for changes/optimizations? |
Hi @ran-isenberg I was the one meant to look into your PR this week, but unfortunately I got sick. I'm getting better now and should start looking into your work between today and tomorrow. Looking forward to review it! |
First time looking at this PR, with no context :) I'm very tired now, so I'll just add the main thing that worries me, and write more about it tomorrow: I find it very arbitrary that we're creating rules for matching DAYS, and TIMES, and even entire DATERANGES. However, I left wondering, what if I also want to match certain HOURS, MINUTES or MONTHS? Will we be keep adding rule types to cover all those scenarios in the future? OR, should we think of a better, generic way of representing (recurrent) time intervals and cover it in a just two calls (one-time time interval / recurrent time intervals)? Right now I'm re-reading ISO8601, as I feel this problem was solved before I was born :) |
The daterange is standard ISO definition UTC time. |
Hi @rubenfonseca and @ran-isenberg! One more PR to review and learn 😄 I started the review yesterday and hope to finish it on Monday! For now, I've created some scenarios to simulate a real use of this feature and so far so good. |
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.
Hi @rubenfonseca and @ran-isenberg!
I made some suggestions of what could be changed to improve this PR, but it's a great job indeed!
aws_lambda_powertools/utilities/feature_flags/time_conditions.py
Outdated
Show resolved
Hide resolved
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.
@rubenfonseca thanks for the fix and feedback! I have no further considerations, everything is working fine!
Hoping to hear something from @heitorlessa before merge it.
hey! back today and got a few internal escalations to handle - ship it if @leandrodamascena and @rubenfonseca are happy |
@rubenfonseca and @ran-isenberg! Before merging, we should rebase this branch to avoid unnecessary changes like this https://github.com/awslabs/aws-lambda-powertools-python/pull/1666/files#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed |
@heitorlessa @rubenfonseca @leandrodamascena Thank you guys so much for the time and effort you put into this major feature! |
when do you expect it to get merged and released? |
Hey Ran! Yesterday and today the team was in an internal workshop and we were not able to merge this. Tomorrow we can merge that and start planning the next release. |
…powertools#1832) Bumps [mypy-boto3-lambda](https://github.com/youtype/mypy_boto3_builder) from 1.26.18 to 1.26.49. - [Release notes](https://github.com/youtype/mypy_boto3_builder/releases) - [Commits](https://github.com/youtype/mypy_boto3_builder/commits) --- updated-dependencies: - dependency-name: mypy-boto3-lambda dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This PR was closed without merging due to the fact that there were some unnecessary changes in the files and the rebase would be complicated. In consensus with @ran-isenberg, the original author of this PR, it was agreed that a new PR would be opened. Closed in favor of #1846 |
#1554:
Feature request: Time based feature flags actions
Summary
Use cases:
Changes
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
As a customer, I'd like to flip a static flag value when evaluated between 11:11 and 23:59.
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.
Selected days
As a customer, I'd like to flip a static flag when evaluated between Monday to Friday.
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).
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
RFC issue number:
Checklist:
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
_UTC
suffix in keys, and implement thetimezone
field on the value (usepython-dateutil
)