Skip to content

Implemented flagd-specific JSONLogic operators#92

Open
m-olko wants to merge 6 commits intomainfrom
jsonlogic_flagd_operators
Open

Implemented flagd-specific JSONLogic operators#92
m-olko wants to merge 6 commits intomainfrom
jsonlogic_flagd_operators

Conversation

@m-olko
Copy link
Copy Markdown
Contributor

@m-olko m-olko commented Mar 25, 2026

This PR

Implements all flagd-specific JSONLogic operators: starts_with, ends_with, semver and fractional.

The semver operator supports out of the box the v and V prefixes, partial versions and correctly returns on parse errors according to open-feature/flagd#1873

The fractional operator supports out of the box the high precision bucketing according to open-feature/flagd#1800
The PR also introduces testcases copied from flagd-testbed, as we don't have Gherkin suite introduced here, but written in C++ to ensure that the hashing is consistent.

Third-party Code: MurmurHash3

The MurmurHash3 implementation in providers/flagd/src/evaluator/murmur_hash/ has been copied from the aappleby/smhasher (https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp) repository.

License & Attribution:

  • Author: Austin Appleby
  • License: Public Domain. The author disclaims all copyright to this source code.
  • Reasoning: This approach was chosen to avoid unnecessary dependencies and a large repository download, as there is no official Bazel package for MurmurHash3. This is a common practice for projects requiring this specific hashing function.

Related Issues

Fixes #19

How to test

bazelisk test //...

Signed-off-by: Marcin Olko <molko@google.com>
@gemini-code-assist
Copy link
Copy Markdown
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 flagd's evaluation capabilities by introducing a suite of new JSONLogic operators. These operators, including starts_with, ends_with, sem_ver, and fractional, enable more sophisticated and precise flag targeting logic, allowing for advanced string comparisons, semantic versioning checks, and weighted fractional distributions. This expansion provides developers with greater flexibility in defining complex flag rules.

Highlights

  • New JSONLogic Operators: Added four new flagd-specific JSONLogic operators: "starts_with", "ends_with", "sem_ver", and "fractional" to enhance flag evaluation capabilities.
  • Operator Integration: Integrated the newly implemented operators into the JsonLogicEvaluator to make them available for use in flag evaluation logic.
  • Hashing Algorithm Inclusion: Included a MurmurHash3 implementation to support the advanced bucketing logic required by the "fractional" operator.
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.

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.

Copy link
Copy Markdown
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

This pull request introduces new JsonLogic operations (starts_with, ends_with, sem_ver, fractional) to the flagd evaluator, along with their implementation, a SemanticVersion class, and integration of MurmurHash3. Review feedback highlights several issues: the SemVer parsing needs to enforce leading zero rules for version components and pre-release identifiers as per SemVer 2.0.0, the Fractional operation requires validation for non-negative weights to prevent underflow, and its sum_of_weights limit should be adjusted for broader compatibility. Additionally, it's recommended to use Abseil's StartsWith and EndsWith for idiomatic code and to refine an unreachable return statement in the Fractional operation.

m-olko added 2 commits March 25, 2026 16:14
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
@m-olko
Copy link
Copy Markdown
Contributor Author

m-olko commented Mar 26, 2026

/gemini review

Copy link
Copy Markdown
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

This pull request introduces new JSON logic operations (starts_with, ends_with, sem_ver, fractional) to the flagd evaluator, implemented within a new flagd_ops library. These operations include semantic version comparison and fractional bucketing using MurmurHash3. Feedback suggests refactoring duplicated SemVer parsing logic, using int32_t for weight in fractional evaluation for consistency, and adding a newline to the fractional ops test file.

m-olko added 2 commits March 26, 2026 10:42
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
@m-olko m-olko marked this pull request as ready for review March 26, 2026 10:57
@m-olko m-olko requested review from alichka06 and oxddr March 26, 2026 10:59
Copy link
Copy Markdown

@tangenti tangenti left a comment

Choose a reason for hiding this comment

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

IIUC the hash code is copied from https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp

Is this best way we can do to import it?

@m-olko
Copy link
Copy Markdown
Contributor Author

m-olko commented Mar 26, 2026

This library is public domain and doesn't have any library with it's implementation in bazel registry nor any other known to me c++ resources. If we would like to download it from the source, we would also download multiple different hashing functions and whole smhasher test suite which is completely unnecessary for our usecase. This way of using this library is common for numerous projects I inspected and best solution according to gemini. As the code is public domain, I don't think there will be any issues with using it like this. From official source:

All MurmurHash versions are public domain software, and the author disclaims all copyright to their code.

@tangenti
Copy link
Copy Markdown

This library is public domain and doesn't have any library with it's implementation in bazel registry nor any other known to me c++ resources. If we would like to download it from the source, we would also download multiple different hashing functions and whole smhasher test suite which is completely unnecessary for our usecase. This way of using this library is common for numerous projects I inspected and best solution according to gemini. As the code is public domain, I don't think there will be any issues with using it like this. From official source:

All MurmurHash versions are public domain software, and the author disclaims all copyright to their code.

Thanks. Could you document this in the directory and also in the PR description?

Signed-off-by: Marcin Olko <molko@google.com>
@m-olko
Copy link
Copy Markdown
Contributor Author

m-olko commented Mar 26, 2026

Thanks. Could you document this in the directory and also in the PR description?

Done

@tangenti tangenti requested a review from cupofcat March 30, 2026 07:42
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.

[flagd] Implement flagd-specific part of Evaluation Engine

2 participants