diff --git a/README.md b/README.md index debd045..71057dd 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ This matrix mirrors the [feature matrix of the OpenFeature SDK for Ruby](https:/ | ✅ | Tracking | `track` sends a LaunchDarkly custom event for the evaluation context, with the tracking event value and remaining details attached. | | ✅ | Transaction Context Propagation | Provided by the OpenFeature SDK, which merges the transaction context into the evaluation context before the provider is called; no provider support is required. | | ✅ | Extending | This provider is itself an extension of the OpenFeature SDK. The underlying LaunchDarkly client is available through `provider.client` for functionality with no OpenFeature equivalent. | -| ✅ | Flag metadata | LaunchDarkly evaluation reason details are returned as OpenFeature flag metadata. See [Flag Metadata](#flag-metadata). | +| ✅ | Flag metadata | LaunchDarkly evaluation reason details, including `overrideAffected`, are returned as OpenFeature flag metadata. See [Flag Metadata](#flag-metadata). | Supported: ✅ | Partially supported: ⚠️ | Not supported: ❌ @@ -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. | | `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. | diff --git a/launchdarkly-openfeature-server-sdk.gemspec b/launchdarkly-openfeature-server-sdk.gemspec index 824f8ec..c812dc7 100644 --- a/launchdarkly-openfeature-server-sdk.gemspec +++ b/launchdarkly-openfeature-server-sdk.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_runtime_dependency "launchdarkly-server-sdk", "~> 8.19" + spec.add_runtime_dependency "launchdarkly-server-sdk", "~> 8.20" spec.add_runtime_dependency "openfeature-sdk", ">= 0.6.1", "< 0.9" # For more information and examples about making a new gem, check out our diff --git a/lib/ldclient-openfeature/impl/details_converter.rb b/lib/ldclient-openfeature/impl/details_converter.rb index 353020b..79802b8 100644 --- a/lib/ldclient-openfeature/impl/details_converter.rb +++ b/lib/ldclient-openfeature/impl/details_converter.rb @@ -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] @@ -61,6 +62,7 @@ def to_resolution_details(detail) metadata[VARIATION_INDEX_KEY] = variation_index unless variation_index.nil? metadata[IN_EXPERIMENT_KEY] = true if reason.in_experiment + metadata[OVERRIDE_AFFECTED_KEY] = true if 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? diff --git a/spec/impl/details_converter_spec.rb b/spec/impl/details_converter_spec.rb index c4914f8..2b1c170 100644 --- a/spec/impl/details_converter_spec.rb +++ b/spec/impl/details_converter_spec.rb @@ -63,6 +63,37 @@ 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).with_override_affected(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).with_override_affected(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 reason does not mark it" 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 override affected in the flag metadata for error evaluations affected by an override" do + reason = LaunchDarkly::EvaluationReason::error(LaunchDarkly::EvaluationReason::ERROR_FLAG_NOT_FOUND).with_override_affected(true) + detail = LaunchDarkly::EvaluationDetail.new(true, nil, reason) + resolution_details = details_converter.to_resolution_details(detail) + + expect(resolution_details.flag_metadata).to eq({'overrideAffected' => true}) + 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)