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

Switch to longs for hash values for percent condition evaluation #2507

Merged
merged 54 commits into from
Apr 4, 2024

Conversation

amanda-xia
Copy link

@amanda-xia amanda-xia commented Mar 22, 2024

Discussion

We discovered that for a given seed and ID, the hash outputted for percent condition evaluation is inconsistent with the hash outputted in the targeting service that handles percent condition evaluation for client side templates. This PR fixes the inconsistency by importing a Longjs library so we can represent hashes as a long, which is consistent with what the targeting service does.

Longjs is a new dependency and is under the Apache 2.0 license.

Testing

Ran npm test and all tests pass.
Manually tested using a local server.

API Changes

None

erikeldridge and others added 30 commits March 7, 2024 18:08
Co-authored-by: jen_h <harveyjen@google.com>
@amanda-xia amanda-xia marked this pull request as draft March 22, 2024 23:56
@lahirumaramba
Copy link
Member

Thanks @amanda-xia ! For the CI error, could you try removing the package-lock file and node_modules locally and running npm install again?

@amanda-xia
Copy link
Author

Hey @lahirumaramba! I gave your suggestion a try, but the error is still persisting. Additionally, there is actually one unit test that is failing when I run npm test locally, and it seems unrelated to my change (the stack trace points to a test at test/unit/app/firebase-app.spec.ts:185:18). I ran git pull recently so I am up-to-date as well. This is my first time contributing to the Admin SDK - do you have pointers on what I could be missing?

@amanda-xia amanda-xia marked this pull request as ready for review March 26, 2024 22:30
@amanda-xia
Copy link
Author

With @erikeldridge's guidance, I locally switched to using Node v14, and then repeated @lahirumaramba's steps, and this resolved the CI check :)

Copy link
Contributor

@erikeldridge erikeldridge left a comment

Choose a reason for hiding this comment

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

LGTM, with a couple requests for minor changes. Nice work!

Copy link
Member

@lahirumaramba lahirumaramba left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@amanda-xia amanda-xia merged commit 36db280 into ssrc Apr 4, 2024
5 checks passed
@amanda-xia amanda-xia deleted the ssrc-longjs branch April 4, 2024 16:45
trekforever added a commit that referenced this pull request Apr 4, 2024
* Get And condition passing

* Support and.or condition

* Support true condition

* Support false condition, and fix tests

* Use or.and, not the other way around

* Integrate conditional values into evaluate method

* Test handling for multiple conditions

* Clean up logs

* Extract condition evaluation to class for testing

* Namespace condition names

* Iterate over ordered condition list

* Test condition ordering

* Differentiate named conditions

* Document condition types

* Generalize condition eval test and fix styling

* Replace log statement with todo

* Implement evaluate percent condition for RC server-side

* Apply lint fixes

* Add context param to evaluate method

* Add tests for percent condition eval

* Update evaluator tests to use context

* Increase threshold to +/- 500 for percent condition eval tests
to prevent some flaky tests.

* Clean up percentCondition tests a bit and add note on the tolerance used

* Apply suggestions from code review

Co-authored-by: jen_h <harveyjen@google.com>

* Update copyright date and remove stray log statement

* Mock farmhash in tests

* Add Math.abs for farmhash - to be consistent with the internal implementation

* Regenerate package-lock to fix Node 14 CI error re busboy

* Fix lint errors

* Rename "id" to "randomizationId" per discussion

* Extract API

* Only return false in cases of uknown template evaluation

* Remove product prefix from type names

* Remove product prefix from exported types

* Remove unused "expression" field from server condition

* Extract API

* Remove prefix from impl classes, for consistency

* Remove prefix from new internal classes

* Remove "server" prefix

* Remove prefix from NamedCondition

* Rename "or" and "and" fields to match API

* Rename "operator" field to "percentOperator" to match API

* Extract API after "and" and "or" rename

* use longjs library for hash

* re-run npm install

* re-attempt

* use node 14, re-attempt

* remove file

* Add comment, switch from lte to lt

---------

Co-authored-by: Erik Eldridge <erikeldridge@google.com>
Co-authored-by: Xin Wei <xinwei@google.com>
Co-authored-by: jen_h <harveyjen@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.

None yet

4 participants