Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Evaluations include flag metadata for the LaunchDarkly specific parts of the eva
|---------------------|---------|--------------------------------------------------------------------|
| `variationIndex` | integer | The index of the returned variation. Absent for default values. |
| `inExperiment` | boolean | Present, and `true`, when the evaluation was part of an experiment. |
| `overrideAffected` | boolean | Present, and `true`, when a flag override affected the evaluation. Requires a LaunchDarkly Ruby SDK version with flag overrides. |
| `ruleIndex` | integer | The index of the rule that matched. |
| `ruleId` | string | The identifier of the rule that matched. |
| `prerequisiteKey` | string | The key of the prerequisite flag that failed. |
Expand Down
7 changes: 5 additions & 2 deletions lib/ldclient-openfeature/impl/details_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ module Impl
class ResolutionDetailsConverter
VARIATION_INDEX_KEY = 'variationIndex'
IN_EXPERIMENT_KEY = 'inExperiment'
OVERRIDE_AFFECTED_KEY = 'overrideAffected'
RULE_INDEX_KEY = 'ruleIndex'
RULE_ID_KEY = 'ruleId'
PREREQUISITE_KEY_KEY = 'prerequisiteKey'
BIG_SEGMENTS_STATUS_KEY = 'bigSegmentsStatus'

private_constant :VARIATION_INDEX_KEY, :IN_EXPERIMENT_KEY, :RULE_INDEX_KEY, :RULE_ID_KEY,
:PREREQUISITE_KEY_KEY, :BIG_SEGMENTS_STATUS_KEY
private_constant :VARIATION_INDEX_KEY, :IN_EXPERIMENT_KEY, :OVERRIDE_AFFECTED_KEY, :RULE_INDEX_KEY,
:RULE_ID_KEY, :PREREQUISITE_KEY_KEY, :BIG_SEGMENTS_STATUS_KEY

#
# @param detail [LaunchDarkly::EvaluationDetail]
Expand Down Expand Up @@ -61,6 +62,8 @@ def to_resolution_details(detail)

metadata[VARIATION_INDEX_KEY] = variation_index unless variation_index.nil?
metadata[IN_EXPERIMENT_KEY] = true if reason.in_experiment
# Only LaunchDarkly Ruby SDK versions with flag overrides define override_affected.
metadata[OVERRIDE_AFFECTED_KEY] = true if reason.respond_to?(:override_affected) && reason.override_affected
metadata[RULE_INDEX_KEY] = reason.rule_index unless reason.rule_index.nil?
metadata[RULE_ID_KEY] = reason.rule_id unless reason.rule_id.nil?
metadata[PREREQUISITE_KEY_KEY] = reason.prerequisite_key unless reason.prerequisite_key.nil?
Expand Down
25 changes: 25 additions & 0 deletions spec/impl/details_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@
expect(resolution_details.flag_metadata).not_to have_key('inExperiment')
end

it "includes override affected in the flag metadata for override-affected evaluations" do
reason = LaunchDarkly::EvaluationReason::rule_match(2, 'the-rule-id', false)
allow(reason).to receive(:override_affected).and_return(true)
detail = LaunchDarkly::EvaluationDetail.new(true, 1, reason)
resolution_details = details_converter.to_resolution_details(detail)

expect(resolution_details.flag_metadata).to include('overrideAffected' => true)
end

it "omits override affected from the flag metadata for evaluations not affected by an override" do
reason = LaunchDarkly::EvaluationReason::rule_match(2, 'the-rule-id', false)
allow(reason).to receive(:override_affected).and_return(false)
detail = LaunchDarkly::EvaluationDetail.new(true, 1, reason)
resolution_details = details_converter.to_resolution_details(detail)

expect(resolution_details.flag_metadata).not_to have_key('overrideAffected')
end

it "omits override affected from the flag metadata when the LaunchDarkly SDK does not support overrides" do
detail = LaunchDarkly::EvaluationDetail.new(true, 1, LaunchDarkly::EvaluationReason::fallthrough(false))
resolution_details = details_converter.to_resolution_details(detail)

expect(resolution_details.flag_metadata).not_to have_key('overrideAffected')
end

it "includes the rule in the flag metadata for rule matches" do
detail = LaunchDarkly::EvaluationDetail.new(true, 1, LaunchDarkly::EvaluationReason::rule_match(2, 'the-rule-id', false))
resolution_details = details_converter.to_resolution_details(detail)
Expand Down
Loading