Skip to content

feat: Add support for high resolution fractional#1740

Open
chrfwow wants to merge 24 commits intoopen-feature:mainfrom
chrfwow:high-resolution-fractional
Open

feat: Add support for high resolution fractional#1740
chrfwow wants to merge 24 commits intoopen-feature:mainfrom
chrfwow:high-resolution-fractional

Conversation

@chrfwow
Copy link
Contributor

@chrfwow chrfwow commented Mar 12, 2026

This PR

Adds high resolution fractional support

Related Issues

Fixes #1738

Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
@chrfwow chrfwow requested a review from a team as a code owner March 12, 2026 14:20
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 significantly enhances the fractional targeting mechanism by extending its compatibility to include Number and Boolean types as bucketing keys, in addition to the existing String support. The core change involves a refactored hashing and bucketing algorithm that utilizes a high-resolution approach, aiming to provide more precise and consistent fractional evaluations across diverse input types.

Highlights

  • Expanded Input Types for Fractional Targeting: The fractional targeting mechanism now supports Number and Boolean types as bucketing keys, in addition to the existing String support. This allows for more flexible and diverse input values when determining fractional distributions.
  • High-Resolution Fractional Bucketing: Implemented a new high-resolution fractional bucketing algorithm. This enhancement utilizes MurmurHash3 and bit shifting operations to provide more precise and consistent fractional evaluations, especially for large numbers.
  • Robust Number to Byte Array Conversion: Introduced a utility method, numberToByteArray, to consistently convert various numeric types (including Integer, Double, Long, BigInteger, Byte, Short, Float, and BigDecimal) into byte arrays. This ensures uniform input for the hashing function, improving reliability across different number representations.
Changelog
  • tools/flagd-core/src/main/java/dev/openfeature/contrib/tools/flagd/core/targeting/Fractional.java
    • Updated the bucketBy variable type from String to byte[] to accommodate various input types.
    • Added logic to convert Number and Boolean arguments into byte arrays for consistent hashing.
    • Introduced a numberToByteArray helper method to handle conversions for different numeric types.
    • Modified the distributeValue method to use a new high-resolution bucketing algorithm based on MurmurHash3 and bitwise operations.
    • Adjusted the FractionProperty constructor's error message formatting.
  • tools/flagd-core/src/test/resources/fractional/boolean.json
    • Added a new test case for boolean input in fractional targeting.
  • tools/flagd-core/src/test/resources/fractional/largeDouble.json
    • Added a new test case for large double input in fractional targeting.
  • tools/flagd-core/src/test/resources/fractional/largeInt.json
    • Added a new test case for large integer input in fractional targeting.
  • tools/flagd-core/src/test/resources/fractional/selfContainedFractionalB.json
    • Modified the expected result in a fractional targeting test case.
  • tools/flagd-core/src/test/resources/fractional/string.json
    • Added a new test case for string input in fractional targeting.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

]
],
"result": "blue"
"result": "red"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In some cases, we will compute a different bucket now

@chrfwow
Copy link
Contributor Author

chrfwow commented Mar 12, 2026

Do we want more tests for this? I stuck to the current test suite

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the fractional targeting logic to support various input types (numbers, booleans) for bucketing by converting them to byte arrays and introduces a new numberToByteArray helper. The core bucketing algorithm was also revised to use an integer-based bit shift operation. Review comments highlight two key areas for improvement: the numberToByteArray method has a potential precision loss issue for BigDecimal and could be made more concise using ByteBuffer, and the bucketing logic has a subtle bug related to handling signed vs. unsigned integers from the MurmurHash3 function, which requires a bitmask for correct range mapping.

Comment on lines +127 to +128
long mmrHash = MurmurHash3.hash32x86(hashKey, 0, hashKey.length, 0);
int bucket = (int) (((mmrHash * totalWeight) >> 32) & 0xFFFFFFFFL);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The bucketing logic has a subtle issue with signed vs. unsigned integers. MurmurHash3.hash32x86 returns a signed int. To correctly use it for range mapping as an unsigned 32-bit value, it should be converted to a long using a bitmask to avoid sign extension. This ensures the bucketing is fair and consistent across different hash values.

        long mmrHash = MurmurHash3.hash32x86(hashKey, 0, hashKey.length, 0) & 0xFFFFFFFFL;
        int bucket = (int) ((mmrHash * totalWeight) >> 32);

chrfwow added 4 commits March 12, 2026 15:30
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
@chrfwow chrfwow marked this pull request as draft March 12, 2026 16:34
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
@chrfwow
Copy link
Contributor Author

chrfwow commented Mar 12, 2026

Idk why there are PMD errors, but I think they are unrelated and false positives

@chrfwow chrfwow marked this pull request as ready for review March 12, 2026 16:48
@chrfwow chrfwow marked this pull request as draft March 13, 2026 07:28
chrfwow added 2 commits March 13, 2026 12:24
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Integer.MIN_VALUE,
Integer.MIN_VALUE + 1
})
void edgeCasesDoNotThrow(int hash) throws JsonLogicException {
Copy link
Contributor Author

@chrfwow chrfwow Mar 13, 2026

Choose a reason for hiding this comment

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

This only tests that we will find a bucket for edge case inputs, but it will not validate the correctness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed, validated through the gherkin suite

}

@Test
void statistics() throws JsonLogicException {
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 tests the statistical distribution. The test takes 340ms on my machine, I think we can live with it, but I can also delete or disable it if we want to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
@chrfwow chrfwow changed the title feat: Add support for high resolution fractional feat: Add support for high resolution fractional and arbitrary targeting key types Mar 13, 2026
@chrfwow chrfwow marked this pull request as ready for review March 13, 2026 11:52
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
chrfwow added 2 commits March 16, 2026 10:58
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
chrfwow added 4 commits March 16, 2026 11:45
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
# Conflicts:
#	providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunInProcessTest.java
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
"type": "object",
"properties": {
"flags": {
"$ref": "#/definitions/providerConfig",
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 don't understand why there are changes in this file. They seem to be auto-generated when running the flagd-core test target

Copy link
Member

Choose a reason for hiding this comment

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

could be that those are copied from the flagd-schema repo

Copy link
Member

Choose a reason for hiding this comment

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

Ya I think that's what it is - I believe it's coming from there.

I think maybe we should gitignore it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it already is gitignored 🤔

Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
@chrfwow
Copy link
Contributor Author

chrfwow commented Mar 17, 2026

Waiting for open-feature/flagd-testbed#340

chrfwow added 3 commits March 18, 2026 11:20
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
@chrfwow chrfwow changed the title feat: Add support for high resolution fractional and arbitrary targeting key types feat: Add support for high resolution fractional Mar 18, 2026
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
@toddbaert
Copy link
Member

@chrfwow there was some e2e test failures but I fixed them by updating to the latest git submodule in the testkit module, and adding the v1 exclusion to the file mode suite, and excluding v2 in the RPC suite (since flagd doesn't support this yet).

I will coordinate the release of flagd, then update the RPC suite here and release everything simultaneously.

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
@toddbaert toddbaert self-requested a review March 18, 2026 17:43
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.

[FEATURE] High-resolution fractional bucketing in flagd provider

6 participants