Skip to content

feat: allow computed fractional bucket variants #1988

In review

Description

@toddbaert

A fractional bucket variant can be any JSON Logic expression, not only a literal:

{
  "state": "ENABLED",
  "defaultVariant": "blue",
  "variants": {
    "red": "#FF0000",
    "blue": "#0000FF"
  },
  "targeting": {
    "fractional": [
      [{ "cat": ["r", "ed"] }, 50],
      ["blue", 50]
    ]
  }
}
  • Evaluate each variant expression once, before bucketing, and return the result for the selected bucket.
  • Accept a primitive (string, number, boolean, null) or the resolve result as the variant. Any other result (e.g. an object or array) makes fractional return null, so the flag falls back to its default variant.
  • Bucketing doesn't change; it depends only on the bucketing value and the weights.

This may already work, or only need a variant type check adjusted. Either way, please add tests for a computed variant and for a non-primitive result.

Why: this allows the new resolve operator as a bucket variant (e.g. [{ "resolve": ["red", "SPLIT"] }, 50]), so each bucket can set its own reason and metadata.

References:

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions