open-feature/flagd

[FEATURE] Allow nested operators in fractional schema

Closed this issue · 0 comments

Requirements

According to the published JSON schema, only "flat" schemas are allowed with fractional operator:

"targeting": {
  "fractional": [
    { "var": "user.name" },
    [ "clubs", 25 ],
    [ "diamonds", 25 ],
    [ "hearts", 25 ],
    [ "spades", 25 ]
  ]
}

In reality, more complex scenarios work fine based on the recursive evaluation and integration with jsonLogic. Since jsonLogic resolves everything before passing to our custom operators, the schema only needs to be enforced and the resolved result, not the entire document.

Could we update the schemas and docs to account for this greater flexibility to solve more complex use-cases?

Here are some scenarios I've tested for reference:

// complex hash key formulation
"targeting": {
  "fractional": [
    { "cat": [
      "my-prefix:",
      { "var": "user.name" },
      { "var": "user.id" },
    ]},
    [ "clubs", 25 ],
    [ "diamonds", 25 ],
    [ "hearts", 25 ],
    [ "spades", 25 ]
  ]
}

// nested randomisation in two equal population groups with different variant exposures
"targeting": {
  "fractional": [
    { "var": "populationKey" },
    [ 
      {
        "fractional": [
          { "var": "user.name" },
          [ "group-a:clubs", 25 ],
          [ "group-a:diamonds", 75 ]
        ]
      }, 
      50 
    ],
    [ 
      {
        "fractional": [
          { "var": "user.name" },
          [ "group-b:clubs", 75 ],
          [ "group-b:diamonds", 25 ]
        ]
      },
      50 
    ]
  ]
}