Skip to content

flagd: Implement $evaluators/$ref resolution in in-process provider #101

Description

@jonathannorris

Summary

The flagd in-process provider does not implement $evaluators/$ref resolution. Flag configurations that use shared targeting rule fragments via $evaluators will silently fail — the raw {"$ref": "evaluatorName"} objects are left in the targeting rules and passed to the JSONLogic engine, where they cause evaluation errors.

All other SDKs with in-process evaluation (Go, Java, JS/TS, .NET, Python) implement this feature.

Expected Behavior

Given a flag configuration like:

{
  "$evaluators": {
    "emailSuffix": { "ends_with": [{ "var": "email" }, "@example.com"] }
  },
  "flags": {
    "my-flag": {
      "targeting": { "if": [{ "$ref": "emailSuffix" }, "variant-a", "variant-b"] }
    }
  }
}

The $ref should be replaced with the corresponding evaluator body at parse time, producing:

{ "if": [{ "ends_with": [{ "var": "email" }, "@example.com"] }, "variant-a", "variant-b"] }

Current Behavior

flag_parser.rs deserializes the flag configuration via serde_json::from_value with no evaluator transposition. The $evaluators block is ignored and $ref objects remain in targeting rules.

Implementation Notes

The approach used by all other SDKs is regex-based string replacement on the serialized JSON at parse time:

  1. Extract the $evaluators map from the configuration
  2. For each evaluator, build a regex matching "$ref": "<name>" (with the enclosing {})
  3. Replace matches with the serialized evaluator body (stripping outer braces)
  4. Deserialize the result

This should be added to crates/flagd/src/resolver/in_process/model/flag_parser.rs.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions