Skip to content

Refine variant reason computation to include SPLIT and STATIC#11037

Open
typotter wants to merge 2 commits intomasterfrom
typo/openfeature-reason
Open

Refine variant reason computation to include SPLIT and STATIC#11037
typotter wants to merge 2 commits intomasterfrom
typo/openfeature-reason

Conversation

@typotter
Copy link
Copy Markdown
Contributor

@typotter typotter commented Apr 2, 2026

What Does This Do

Computes the correct OpenFeature evaluation reason from the UFC allocation structure instead of hardcoding TARGETING_MATCH for all successful evaluations.

Three-way logic in resolveVariant():

  • STATIC — no rules, no shards (unconditional allocation)
  • SPLIT — no rules, shards present (percentage-based traffic split)
  • TARGETING_MATCH — rules present (flag matched a targeting rule)

Also fixes one test assertion that needed updating after rebasing onto #10990: a null targeting key on a static flag now correctly evaluates as STATIC rather than TARGETING_MATCH.

Motivation

System tests Test_FFE_Eval_Metric_Basic (expects reason=static) and Test_FFE_Eval_Reason_Split (expects reason=split) were failing because the evaluator hardcoded TARGETING_MATCH regardless of allocation structure. This aligns Java behavior with the Python and Go SDK reference implementations.

Co-authored-by: Leo Romanovsky leo.romanovsky@datadoghq.com (original fix in #10971)

Additional Notes

The split object is passed into resolveVariant() so the reason can be derived at resolution time without additional lookups.

The semantic question of whether a catch-all (no-rules, no-shards) allocation inside a multi-allocation flag should return STATIC vs another reason is out of scope here — that's a pre-existing behavior question tracked separately.

Contributor Checklist

…ng TARGETING_MATCH

- Add Split parameter to resolveVariant for three-way reason computation
- Return STATIC for flags with no rules and no shards (simple flags)
- Return SPLIT for flags with no rules but with shards (shard-based flags)
- Return TARGETING_MATCH for flags with rules (rule-based flags)
- Update 9 test assertions: 7 to STATIC, 2 to SPLIT
@typotter typotter marked this pull request as ready for review April 2, 2026 12:33
@typotter typotter requested a review from a team as a code owner April 2, 2026 12:33
@typotter typotter requested review from dd-oleksii and sameerank and removed request for a team April 2, 2026 12:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Add at least one type, and one component or instrumentation label to the pull request

If you need help, please check our contributing guidelines.

@typotter typotter changed the title fix(openfeature): compute correct reason from allocation structure Refine variant reason computation to include SPLIT and STATIC Apr 2, 2026
@typotter typotter requested a review from leoromanovsky April 2, 2026 12:35
Comment on lines +362 to +365
.reason(
!isEmpty(allocation.rules)
? Reason.TARGETING_MATCH.name()
: !isEmpty(split.shards) ? Reason.SPLIT.name() : Reason.STATIC.name())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

@dd-oleksii dd-oleksii added type: enhancement Enhancements and improvements comp: openfeature OpenFeature labels Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: openfeature OpenFeature type: enhancement Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants