Skip to content

feat(feature_flags): add in feature_flags RE_* actions and update tests/docs #692

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

Conversation

whardier
Copy link
Contributor

@whardier whardier commented Sep 23, 2021

Issue #, if available:

#690

Description of changes:

Extend feature_toggles to enable regular expression actions... next step - lets just use embedded lua!

Checklist

Breaking change checklist

Nope

RFC issue #:

Nope

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

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


View rendered docs/utilities/feature_flags.md


View rendered docs/utilities/feature_flags.md

@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 23, 2021
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels Sep 23, 2021
@codecov-commenter
Copy link

codecov-commenter commented Sep 23, 2021

Codecov Report

Merging #692 (74f8759) into develop (79414c8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #692   +/-   ##
========================================
  Coverage    99.97%   99.97%           
========================================
  Files          116      116           
  Lines         4855     4862    +7     
  Branches       267      267           
========================================
+ Hits          4854     4861    +7     
  Partials         1        1           
Impacted Files Coverage Δ
...owertools/utilities/feature_flags/feature_flags.py 100.00% <100.00%> (ø)
...ambda_powertools/utilities/feature_flags/schema.py 100.00% <100.00%> (ø)

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 79414c8...74f8759. Read the comment docs.

@heitorlessa
Copy link
Contributor

Hey @whardier that's a great idea!

I’m returning from vacation next week and can help review, if that's okay.

At a quick glance, I'd suggest receiving a re.compile object so customers to favour performance -- they can compile outside the handler for a full CPU power and we can use it on every invocation.

Thank you!!

@whardier
Copy link
Contributor Author

whardier commented Sep 23, 2021 via email

@whardier
Copy link
Contributor Author

Alternative approach using user mappings:

develop...whardier:feat/feature-flags-user-mapping-by-action

@heitorlessa
Copy link
Contributor

Alternative approach using user mappings:

develop...whardier:feat/feature-flags-user-mapping-by-action

This is awesome -- we're taking a look at it this week. Feel free to change this PR for a user-defined action that we can call it. If it is returns a falsy value or an exception we can say the rule didn't match.

That should give more flexibility to define what they'd like with a simple contract.

thoughts @risenberg-cyberark @michaelbrewer?

@ran-isenberg
Copy link
Contributor

I like the regex action. I think we'r missing tests - 6 actions require 12 tests - one for match, one for no match.

Regarding the user actions - i'm the fence regarding this one, because they might override the default action by mistake. If we were to add such a support, the logic in the match by action should be - try to find the action in the default mapping, if it's None, check user mappings (not merge the dicts like i saw in the branch develop...whardier:feat/feature-flags-user-mapping-by-action)

@heitorlessa
Copy link
Contributor

heitorlessa commented Sep 29, 2021 via email

@ran-isenberg
Copy link
Contributor

I think it's a bit over-kill. After we add the regex and more 'not' actions, It will probably cover most of the use cases for most users. It would be really great if we could have some poll/feedback as to what actions are missing.

@heitorlessa
Copy link
Contributor

heitorlessa commented Sep 30, 2021 via email

@gwlester
Copy link
Contributor

Strongly suggest renaming the rules so it is clear which is the pattern (the value or the key) and which is the string.

I'd also suggest that it may be appropriate to have conditions that match the other way around to what is being proposed (i.e. swap what is the pattern and what is the string).

@whardier
Copy link
Contributor Author

whardier commented Sep 30, 2021 via email

@whardier
Copy link
Contributor Author

whardier commented Sep 30, 2021 via email

@gwlester
Copy link
Contributor

If we go for RE instead to handle most cases we just need a precompiler

Requiring a precompiler does not sound like a good idea.

@whardier
Copy link
Contributor Author

It is fairly typical to use re.compile in situations like this. It would have to happen between after or during configuration load and use.. possibly part of validation

@gwlester
Copy link
Contributor

Here is an example use case an RE would not cover -- compare if a key (e.g. current date in YYYY.MM.DD format) is greater than a given value (i.e. the general go-live date). The feature might also have anoter rule to see if the user is in a group of beta users and thus has access to the feature prior to the general go-live date.

@ran-isenberg
Copy link
Contributor

ran-isenberg commented Oct 1, 2021

"The default rules aren’t overridden and are last in the rules dict update." - what if someone uses the same keys as the default rules? maybe it's ok?

@ran-isenberg
Copy link
Contributor

Here is an example use case an RE would not cover -- compare if a key (e.g. current date in YYYY.MM.DD format) is greater than a given value (i.e. the general go-live date). The feature might also have anoter rule to see if the user is in a group of beta users and thus has access to the feature prior to the general go-live date.

if we added greater than action that you could use unix epoch time, i know its less readable but it works

@gwlester
Copy link
Contributor

gwlester commented Oct 1, 2021

Here is an example use case an RE would not cover -- compare if a key (e.g. current date in YYYY.MM.DD format) is greater than a given value (i.e. the general go-live date). The feature might also have anoter rule to see if the user is in a group of beta users and thus has access to the feature prior to the general go-live date.

if we added greater than action that you could use unix epoch time, i know its less readable but it works

As long as the key and value are formatted either as epoch time or as a string suggested the compares work. See:

>>> def test(a,b):
...     if a > b:
...             print("Greater")
...     else:
...             print("Less than or equal")
... 
>>> sa = "2021.10.01"
>>> na = 1633064400
>>> test(sa,"2021.11.01")
Less than or equal
>>> test(sa,"2021.09.01")
Greater
>>> test(na,1635742800)
Less than or equal
>>> test(na,1630472400)
Greater
>>> 

@heitorlessa
Copy link
Contributor

hey everyone - could we get the conflicts resolved as I'd like to have a second look at bringing RE actions instead of user defined?

We'd also need to receive a compiled pattern (re.Pattern) to improve perf.

Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

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

resolve conflicts and accept re.Pattern> so customers can provide compiled patterns to take advantage of full CPU during cold start.

@gwlester
Copy link
Contributor

@heitorlessa , if no one gets to it prior to this weekend I'll take a look at pulling down the branch and resolving conflicts. I'm slammed at work this week and that is the earliest I can get to it.

@heitorlessa heitorlessa added the need-more-information Pending information to continue label Oct 29, 2021
@heitorlessa heitorlessa added the p3 label Dec 8, 2021
@heitorlessa
Copy link
Contributor

Due to the lack of activity, I'm gonna close this for now - Once we merge #804, this will make it harder to maintain. Instead, let's focus on support Bring Your Own Action so customers can use anything they'd like to validate features.

@heitorlessa heitorlessa closed this Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation need-more-information Pending information to continue p3 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants