feat(fractional): support nested JSON Logic expressions as bucket variant names#31
feat(fractional): support nested JSON Logic expressions as bucket variant names#31
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces significant enhancements to the fractional targeting mechanism by enabling the use of nested JSON Logic expressions as bucket variant names. This change allows for highly dynamic and context-aware feature flag evaluations, aligning the Rust core with capabilities already present in other SDKs. The update primarily involves a schema modification to permit these expressions and is thoroughly validated with new integration tests covering various complex scenarios, including nested Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly implements support for nested JSON Logic expressions as variant names in fractional bucketing. The schema change is appropriate, and the new integration tests provide good coverage for various nesting scenarios, including if, var, and nested fractional operators. The addition of statistical and boundary tests is also a great improvement. I have one suggestion to improve the performance of a new statistical test to prevent potential CI timeouts.
4c8c039 to
3a4789e
Compare
…iant names The operator already recurses into array elements via evaluator.evaluate(), so nested expressions (if, var, fractional) in bucket variant positions worked at runtime. The only blocker was the JSON Schema enforcing "type": "string" for fractionalWeightArg[0]. Change fractionalWeightArg first element to oneOf[string, anyRule] so the schema accepts JSON Logic objects as variant names in strict mode. Also: - pub mod fractional (was private) to allow direct access in tests - Add integration tests for nested if, nested fractional, and var as bucket variant names (closes #30) - Add statistical distribution uniformity test (mirrors Java PR #1740) - Add boundary-key test (mirrors Java PR #1740 edgeCasesDoNotThrow) Signed-off-by: Simon Schrottner <simon.schrottner@aepfli.at> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
3a4789e to
09faeef
Compare
Summary
Implements flagd#1676 for the Rust core, mirroring the Java work in java-sdk-contrib#1737.
Allow arbitrary JSON Logic expressions as the variant name inside a fractional bucket definition:
{"fractional": [ {"var": "email"}, [{"if": [{"in": [{"var": "locale"}, ["us", "ca"]]}, "red", "grey"]}, 50], ["blue", 50] ]}Nested
fractionalinsidefractionalis also supported:{"fractional": [ {"var": "email"}, [{"fractional": [{"var": "tier"}, ["red", 50], ["blue", 50]]}, 50], [{"fractional": [{"var": "tier"}, ["green", 50], ["yellow", 50]]}, 50] ]}Investigation
The operator already recurses into array elements via
evaluator.evaluate(), so nested expressions worked at runtime. The only blocker was the JSON Schema enforcing"type": "string"on bucket variant names in strict mode, preventing configs from loading at all.Changes
schemas/targeting.jsonfractionalWeightArgfirst element changed from{"type": "string"}to{"oneOf": [{"type": "string"}, {"\": "#/definitions/anyRule"}]}, accepting any JSON Logic expression as a variant name.src/operators/mod.rsmod fractional→pub mod fractionalto exposefractional::fractionalfor direct use in integration tests.tests/integration_tests.rsFive new tests:
test_nested_if_in_bucket_variant_name—{"if": ...}resolves differently per locale contexttest_nested_fractional_inside_fractional— nested{"fractional": ...}inside outer bucketstest_nested_var_in_bucket_variant_name—{"var": "preferred_theme"}pulled from contexttest_fractional_distribution_uniformity— statistical uniformity across the hash space (mirrors java-sdk-contrib#1740)test_fractional_boundary_hashes_do_not_panic— boundary keys don't panic (mirrors Java PR #1740)Closes #30