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

Evaluate targeting rules with semver string format (FF-1433) #38

Merged
merged 3 commits into from
Feb 6, 2024

Conversation

leoromanovsky
Copy link
Member

@leoromanovsky leoromanovsky commented Feb 4, 2024


labels: mergeable

Fixes: #issue

Motivation and Context

RAC API will start returning targeting rule values containing semver strings (https://github.com/Eppo-exp/eppo/pull/8697).

Our SDKs need to be able to parse these strings and perform rule evaluation on them.

Description

The operations lt, gt, lte, gte now only apply to numeric values; insert a higher priority step to check if the value is a semver string; if so apply the comparison with it. Otherwise fall through and attempt to evaluate using numerics.

behavior of un-upgraded SDKs

They will continue to assume that only numeric values will be present for the lt, gt, lte, gte operations - the compareNumber function will return false if both sides of the comparison are not numbers.

How has this been tested?

New unit tests.

Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

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

Nice job knocking this out!

{
operator: OperatorType.GTE,
attribute: 'version',
value: '1.0.0',
Copy link
Contributor

Choose a reason for hiding this comment

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

how about test data that makes sure sem ver comparisons are at play (vs string ones). Such as GTE 1.6.4 and then you can compare it against 1.12.3 or something like that

Comment on lines +3 to +7
valid as validSemver,
gt as semverGt,
lt as semverLt,
gte as semverGte,
lte as semverLte,
Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate the more explicit renaming

src/rule_evaluator.ts Outdated Show resolved Hide resolved
src/rule_evaluator.ts Outdated Show resolved Hide resolved
if (value != null) {
switch (condition.operator) {
case getMD5Hash(OperatorType.GTE):
if (conditionValueType === OperatorValueType.SEM_VER) {
Copy link
Contributor

Choose a reason for hiding this comment

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

not your code, but seems kind of crazy w have to duplicate the switch statement. If easy, consider cleaning it up by changing from a switch to a Map or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

Aaron do you mean the duplication between the evaluateCondition and evaluateObfuscatedCondition functions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah (had to expand the PR to confirm). Whenever I see the same business logic change being made in multiple places in a PR like that it triggers some spidey senses 🕷️ 🕸️

Copy link
Member Author

Choose a reason for hiding this comment

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

Aaron I gave it a shot but really didn't like the way the code turned out - a complicating factor is the difference behavior in the lt, gt.. and the one of, not on off branches. Want to pair for a few minutes?

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.

2 participants