Skip to content

Add MatchRegistry for custom match implementations. #390

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

Merged
merged 15 commits into from
Sep 15, 2020

Conversation

mikecdavis
Copy link
Contributor

@mikecdavis mikecdavis commented Aug 7, 2020

Summary

  • Replace MatchType in favor of MatchRegistry
  • Add conditionValue to Match#match interface.
  • Remove the abstract AttributeMatch class.
  • Remove ExactNumberMatch class.
  • Add NumberComparator for standardizing Number comparisons
  • Refactor Semantic Versioning to use static convenience method

Incorporating a public MatchRegistry will allow consumers to provide their own implementations of the Match interface.

@coveralls
Copy link

coveralls commented Aug 7, 2020

Pull Request Test Coverage Report for Build 1544

  • 83 of 87 (95.4%) changed or added relevant lines in 17 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.1%) to 89.703%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core-api/src/main/java/com/optimizely/ab/config/audience/match/MatchRegistry.java 21 22 95.45%
core-api/src/main/java/com/optimizely/ab/config/audience/match/NumberComparator.java 4 5 80.0%
core-api/src/main/java/com/optimizely/ab/config/audience/UserAttribute.java 13 15 86.67%
Files with Coverage Reduction New Missed Lines %
core-api/src/main/java/com/optimizely/ab/config/audience/match/SubstringMatch.java 2 75.0%
Totals Coverage Status
Change from base Build 1539: 0.1%
Covered Lines: 4051
Relevant Lines: 4516

💛 - Coveralls

@mikecdavis
Copy link
Contributor Author

Currently failing a single scenario in the FSC:

@mikecdavis mikecdavis force-pushed the mikecdavis/matcher-registry branch 2 times, most recently from 1743c70 to f30e088 Compare September 9, 2020 21:41
@mikecdavis mikecdavis removed the chore label Sep 10, 2020
@mikecdavis mikecdavis force-pushed the mikecdavis/matcher-registry branch from ba30742 to fd41198 Compare September 15, 2020 17:49
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

eol

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

lgtm. few nits

private static final Map<String, Match> registry = new ConcurrentHashMap<>();
public static final String EXISTS = "exists";
public static final String EXACT = "exact";
public static final String GREATER_THAN = "gt";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: alphabetize.

throw new UnknownValueTypeException();
}

if (!isValidNumber(o2)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we merge into the above if condition?

return compareUnsafe(o1, o2);
}

public static int compareUnsafe(Object o1, Object o2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

doc string will be helpful here.

@@ -18,11 +18,9 @@

import javax.annotation.Nullable;

class SubstringMatch extends AttributeMatch<String> {
String value;
class SubstringMatch implements Match {
Copy link
Contributor

Choose a reason for hiding this comment

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

update Copyright year.

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

It looks great. One change suggested.

@@ -20,5 +20,5 @@

public interface Match {
@Nullable
Boolean eval(Object attributeValue);
Boolean eval(Object conditionValue, Object attributeValue) throws UnexpectedValueTypeException, UnknownValueTypeException;
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 need separate exception types for UnexpectedValueTypeException and UnknownValueTypeException?
They're similar and not much gain for additional complexity to differentiate them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for backwards compatibility, albeit I can update the names perhaps. The difference is in the logging behavior. One error is communicated as an SDK compatibility issue warning to upgrade on the condition value, while the other is saying that the attribute value type is unknown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The distinction is since the conditionValue comes from the datafile, so if a value is of an "unexpected" type then its likely the result of an out of date SDK. Since the attributeValue is provided at runtime via the user attributes, then we log that the type is "unknown".

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. We can consider adding some clarifications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added doc strings for all the exception classes in this package.

@mikecdavis mikecdavis merged commit c6da789 into master Sep 15, 2020
@mikecdavis mikecdavis deleted the mikecdavis/matcher-registry branch September 15, 2020 22:16
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.

4 participants