Skip to content
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

feat: Add segment types, segment metadata, identity override segments support #198

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

khvn26
Copy link
Member

@khvn26 khvn26 commented Dec 7, 2023

Closes #197.

This PR adds the following:

  • meta: dict[str, str] | None field to the Segment model. It's intended to be used by Core and Edge API to store data specific for their Flagsmith implementations, unrelated to the engine and SDKs.
  • A special "_$identity.identifier" string literal can be now assigned to SegmentCondition.property_ to make the engine match segment condition rules against the identity identifier.

@khvn26 khvn26 requested a review from matthewelwell December 7, 2023 01:01
Copy link

github-actions bot commented Dec 7, 2023

File Coverage
All files 100%

Minimum allowed coverage is 100%

Generated by 🐒 cobertura-action against de8a1ba

Copy link
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

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

A few minor comments but looks pretty clean on the whole.

@@ -20,3 +20,5 @@
IS_SET: ConditionOperator = "IS_SET"
IS_NOT_SET: ConditionOperator = "IS_NOT_SET"
IN: ConditionOperator = "IN"

SEGMENT_IDENTIFIER_PROPERTY_NAME: str = "_$identity.identifier"
Copy link
Contributor

Choose a reason for hiding this comment

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

I kind of feel like we could generalise this to just the prefix? So e.g. _$identity.identity_uuid would also work? Maybe that's a bit YAGNI?

Copy link
Member Author

Choose a reason for hiding this comment

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

_$identity.identity_uuid would also work?

In the future, maybe we'll want it to. Maybe we'll have other entities participating in the matching, e.g. $_contexts.org.location.

@@ -39,3 +39,4 @@ class SegmentModel(BaseModel):
name: str
rules: typing.List[SegmentRuleModel] = Field(default_factory=list)
feature_states: typing.List[FeatureStateModel] = Field(default_factory=list)
meta: typing.Optional[typing.Dict[str, str]] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be at least a typed dict? Maybe one for a little further down the line when we know exactly what we need in the meta dict?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's two reasons I don't want to impose a typed dict here yet:

  1. The metadata schema is not settled yet.
  2. The engine does not need this metadata, APIs do. It's on Core/Edge to maintain the schema (could be a common library, just not the engine.)

@@ -148,3 +149,23 @@
)
],
)
segment_identity_override = SegmentModel(
id=7,
name="segment_identity_override",
Copy link
Contributor

Choose a reason for hiding this comment

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

We talked about this being unique in someway, right? Should we illustrate that even in this test data?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 167 to 170
meta={
"identity_identifier": identifier,
"type": "IDENTITY_OVERRIDE",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to add identity_uuid here too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@khvn26 khvn26 requested a review from matthewelwell December 7, 2023 10:45
Copy link
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

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

@khvn26 I think this PR is still valuable but probably needs some reworking to fit in with the changes we made to the data structures?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Identity-targeted segment conditions
2 participants