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

Add logic for remaining custom signal operators #2633

Merged
merged 13 commits into from
Jul 22, 2024

Conversation

kjelko
Copy link
Contributor

@kjelko kjelko commented Jul 16, 2024

No description provided.

@kjelko kjelko marked this pull request as ready for review July 16, 2024 17:12
@kjelko kjelko requested a review from erikeldridge July 16, 2024 17:13
@@ -246,3 +271,23 @@ function compareStrings(
const actual = String(actualValue);
return targetValues.some((target) => predicateFn(target, actual));
}

// Compares numeric version strings against each other.
function compareNumericVersions(version1String: string|number, version2String: string): number {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given this is used for comparing semantic version strings, and we have other logic for comparing numbers, naming this compareSemanticVersions would be more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. This was a holdover from how things are named elsewhere :)

// TODO: add comparison logic for additional operators here.

case CustomSignalOperator.NUMERIC_LESS_THAN:
return Number(actualCustomSignalValue) < Number(targetCustomSignalValues[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Given we accept an array of target values, what's the plan for comparing the other values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For numeric and version operators, only one value is allowed. This is true for the client implementation as well. Added some comments here to document that.

customSignal: {
customSignalOperator: CustomSignalOperator.NUMERIC_EQUAL,
customSignalKey: 'user_prop',
targetCustomSignalValues: ['5.11.9-beta']
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking: this could be any non-numeric string.

});

it('should evaluate to false', () => {
const condition = createNamedCondition('is_enabled', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and below, we should also test non-numeric string handling, as we do above for NUMERIC_EQUAL.

customSignal: {
customSignalOperator: CustomSignalOperator.SEMANTIC_VERSION_EQUAL,
customSignalKey: 'user_prop',
targetCustomSignalValues: [' 5.12.3 ']
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this whitespace-ignoring behavior applies to all semver comparisons, it might be more efficient to test it explicitly.

customSignal: {
customSignalOperator: CustomSignalOperator.SEMANTIC_VERSION_LESS_EQUAL,
customSignalKey: 'user_prop',
targetCustomSignalValues: ['5.13']
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we're missing the case of comparing a single digit actual version with a multi-digit target version. For example, 1 <= 1.2.3. Since we wrote the semver comparison logic and it has a few conditional branches, I think it'd be worth testing that logic directly. Then these condition-level tests could just cover an example case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated a bunch of these tests. We've got pretty extensive coverage now

@@ -960,10 +960,17 @@ describe('ConditionEvaluator', () => {
targetCustomSignalValues: ['foo', 'bar']
}
});
const condition2 = createNamedCondition('is_active', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: naming the different test cases something more self-descriptive than "is_enabled" and "is_active" would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure sure. was just following convention in this file but I agree

@kjelko kjelko merged commit 5660462 into ssrc-targeting Jul 22, 2024
10 checks passed
@kjelko kjelko deleted the ssrc-targeting-draft branch July 22, 2024 14:53
kjelko added a commit that referenced this pull request Aug 20, 2024
* initial skeleton for custom signal evaluation logic

* adjust some formatting

* remove extra curly brace

* run lint

* Run apidocs

* Split EvaluationContext into UserProvidedSignals and PredefinedSignals

* rerun apidocs

* add logic for remaining custom signal operators

* more test cases

* test cases for numeric operators

* update tests to be way more robust and implement handling for a few edge cases

* update some comments

---------

Co-authored-by: Kevin Elko <kjelko@google.com>
kjelko added a commit that referenced this pull request Sep 5, 2024
* Initial set up and evaluation logic for server side custom signals (#2628)

initial skeleton for custom signal evaluation logic

---------

Co-authored-by: Kevin Elko <kjelko@google.com>

* Add logic for remaining custom signal operators (#2633)

* initial skeleton for custom signal evaluation logic

* adjust some formatting

* remove extra curly brace

* run lint

* Run apidocs

* Split EvaluationContext into UserProvidedSignals and PredefinedSignals

* rerun apidocs

* add logic for remaining custom signal operators

* more test cases

* test cases for numeric operators

* update tests to be way more robust and implement handling for a few edge cases

* update some comments

---------

Co-authored-by: Kevin Elko <kjelko@google.com>

* Ssrc targeting numeric version fixes (#2656)

* refactor numeric version parsing logic and add more test cases

* run lint

* test cases for max num segments

* run lint on tests

---------

Co-authored-by: Kevin Elko <kjelko@google.com>

* fix test ordering

* Export signal types and rerun apidocs

* update docstrings

* uber minor comment fix

---------

Co-authored-by: Kevin Elko <kjelko@google.com>
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