Skip to content

List intersection action for conditions in feature flags #3531

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

Closed
1 of 2 tasks
Rogalek opened this issue Dec 18, 2023 · 16 comments · Fixed by #3692
Closed
1 of 2 tasks

List intersection action for conditions in feature flags #3531

Rogalek opened this issue Dec 18, 2023 · 16 comments · Fixed by #3692
Assignees
Labels
feature_flags Feature Flags utility feature-request feature request

Comments

@Rogalek
Copy link

Rogalek commented Dec 18, 2023

Use case

I was thinking if there is a way to write action for condition in feature flags that can do list Intersection.
https://www.geeksforgeeks.org/python-intersection-two-lists/

Solution/User Experience

So user could provide key: [A, B] and inside AWS Appconfig json there will be stored value: [B, C]
And if at least one elements match for both list that this will match criteria.

Alternative solutions

No response

Acknowledgment

@Rogalek Rogalek added feature-request feature request triage Pending triage from maintainers labels Dec 18, 2023
Copy link

boring-cyborg bot commented Dec 18, 2023

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@rubenfonseca
Copy link
Contributor

Interesting, the existing KEY_IN_VALUE does not cover a scenario where both items are lists. Is this something you would be able to contribute with a pull request? I would love to help you merge it.

@rubenfonseca rubenfonseca added feature_flags Feature Flags utility and removed triage Pending triage from maintainers labels Dec 18, 2023
@rubenfonseca rubenfonseca moved this from Triage to Backlog in Powertools for AWS Lambda (Python) Dec 18, 2023
@Rogalek
Copy link
Author

Rogalek commented Dec 21, 2023

Yes, sure I can try to create PR after Christmas and New Year

@gwlester
Copy link
Contributor

May want a couple of intersections:

  • ANY_IN_VALUE
  • ALL_IN_VALUE
  • NONE_IN_VALUE

@leandrodamascena
Copy link
Contributor

Hi @Rogalek and @gwlester! Thanks for sharing this idea to add more features to our Feature Flags utility. For me, it makes a lot of sense to expand this support. After all, we open up more opportunities to use this utility, such as checking if, given an array, ANY of those elements are present, something that we don't support nowadays because we don't check individual values passed in the context.

Just a small comment:

  • ALL_IN_VALUE

We already support it if you use EQUALS.

Do you still have plans to send a PR with these changes @Rogalek? Please let me know and we can work together to get it merged.

@leandrodamascena leandrodamascena moved this from Backlog to Pending customer in Powertools for AWS Lambda (Python) Jan 29, 2024
@gwlester
Copy link
Contributor

@leandrodamascena
You wrote:
ALL_IN_VALUE
We already support it if you use EQUALS.

They are not the same -- All_IN_VALUE would mean that all in the list are in the value, but does not also mean that all in the value are in the list. EQUAL means that all in the list are in the value and also that all in the value are in the list.

@gwlester
Copy link
Contributor

I think I may be taking a shot at implementing this over the next couple of weeks -- does anyone have any issues with that?

@heitorlessa , @leandrodamascena

@gwlester
Copy link
Contributor

gwlester commented Jan 31, 2024

I have the code at https://github.com/gwlester/aws-lambda-powertools-python/tree/feature-3531 -- but not sure what to do about the tests. With the way they are organized now, I don't see a good way to add ones for these three actions (there is another ticket to refactor them).

Can I get some feedback about the tests?

@leandrodamascena
Copy link
Contributor

@leandrodamascena You wrote: ALL_IN_VALUE We already support it if you use EQUALS.

They are not the same -- All_IN_VALUE would mean that all in the list are in the value, but does not also mean that all in the value are in the list. EQUAL means that all in the list are in the value and also that all in the value are in the list.

Hey @gwlester! Yep, you're right, I agree!

I have the code at gwlester/aws-lambda-powertools-python@feature-3531 -- but not sure what to do about the tests.

Do you want to open a PR without testing and we can work together to add these tests? We can do some code reviews until we reach the ideal code for merge. It makes sense?

Thanks

@gwlester
Copy link
Contributor

gwlester commented Feb 1, 2024

@leandrodamascena pull request created: #3692

Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@heitorlessa
Copy link
Contributor

Adding a sample schema for reference as I didn't find them earlier.


ALL_IN_VALUE

context=["Gerald"]

{
    "my_feature": {
        "default": false,
        "rules": {
            "tenant_id is in allowed list": {
                "when_match": true,
                "conditions": [
                    {
                        "action": "ALL_IN_VALUE",
                        "key": "tenant_id",
                        "value": [
                            "Łukasz",
                            "Gerald",
                            "Leandro",
                            "Heitor"
                        ]
                    }
                ]
            }
        }
    }
}

ANY_IN_VALUE

context=["Gerald"]

{
    "my_feature": {
        "default": false,
        "rules": {
            "tenant_id is in allowed list": {
                "when_match": true,
                "conditions": [
                    {
                        "action": "ANY_IN_VALUE",
                        "key": "tenant_id",
                        "value": [
                            "Łukasz",
                            "Gerald",
                            "Leandro",
                            "Heitor"
                        ]
                    }
                ]
            }
        }
    }
}

NONE_IN_VALUE

context=["Simon"]

{
    "my_feature": {
        "default": false,
        "rules": {
            "tenant_id is in allowed list": {
                "when_match": true,
                "conditions": [
                    {
                        "action": "NONE_IN_VALUE",
                        "key": "tenant_id",
                        "value": [
                            "Łukasz",
                            "Gerald",
                            "Leandro",
                            "Heitor"
                        ]
                    }
                ]
            }
        }
    }
}

@heitorlessa heitorlessa reopened this Feb 16, 2024
@github-project-automation github-project-automation bot moved this from Coming soon to Pending review in Powertools for AWS Lambda (Python) Feb 16, 2024
@heitorlessa
Copy link
Contributor

@Rogalek @gwlester I've noticed this is our first built-in condition that an input may not be a list and a silent error (False flag) may not be ideal -- instead of failing flat causing further disruption to other flags, I'm gonna add an exception handler that you could use to trap ANY exception.

I'm refactoring the last bits oft the implementation, and will work on the exception handler. For that reason, we'll release early next week only - mon/tue.

@heitorlessa heitorlessa self-assigned this Feb 16, 2024
@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Feb 19, 2024
@heitorlessa
Copy link
Contributor

Closing as it's coming in this week's release. PR merged w/ refactorings.

@github-project-automation github-project-automation bot moved this from Pending review to Coming soon in Powertools for AWS Lambda (Python) Feb 19, 2024
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

Copy link
Contributor

This is now released under 2.34.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Feb 21, 2024
@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Mar 18, 2024
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
Status: Shipped
Development

Successfully merging a pull request may close this issue.

5 participants