-
Notifications
You must be signed in to change notification settings - Fork 0
Thread FlagDetails.metadata into ProviderEvaluation flagMetadata #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
f859586
f237aef
4142e2a
9bd3ea3
841d6b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,10 @@ let package = Package( | |
| name: "DatadogOpenFeatureProvider", | ||
| platforms: [ | ||
| .iOS(.v14), | ||
| .macOS(.v12), | ||
| .macOS("12.6"), | ||
| .watchOS(.v7), | ||
| .tvOS(.v14), | ||
| .visionOS(.v1), | ||
| ], | ||
| products: [ | ||
| .library( | ||
|
|
@@ -19,7 +20,7 @@ let package = Package( | |
| ], | ||
| dependencies: [ | ||
| .package(url: "https://github.com/open-feature/swift-sdk.git", "0.3.0"..<"0.4.0"), | ||
| .package(url: "https://github.com/DataDog/dd-sdk-ios.git", from: "3.2.0"), | ||
| .package(url: "https://github.com/DataDog/dd-sdk-ios.git", branch: "typo/thread-allocation-key-to-flag-details-metadata"), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This Useful? React with 👍 / 👎.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remember to change this back before merging |
||
| ], | ||
| targets: [ | ||
| .target( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,33 @@ import Foundation | |
| import DatadogFlags | ||
| import OpenFeature | ||
|
|
||
| // MARK: - Private Helpers | ||
|
|
||
| private extension [String: AnyValue] { | ||
| /// Converts an AnyValue metadata dictionary to the OpenFeature FlagMetadataValue map. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, looks like you were already expecting |
||
| /// Complex types (.dictionary, .array, .null) are dropped since FlagMetadataValue | ||
| /// only supports Bool, String, Int64, and Double primitives. | ||
| func toOpenFeatureFlagMetadata() -> [String: FlagMetadataValue] { | ||
| reduce(into: [:]) { result, pair in | ||
| switch pair.value { | ||
| case .string(let s): result[pair.key] = FlagMetadataValue.of(s) | ||
| case .bool(let b): result[pair.key] = FlagMetadataValue.of(b) | ||
| case .int(let i): result[pair.key] = FlagMetadataValue.of(Int64(i)) | ||
| case .double(let d): result[pair.key] = FlagMetadataValue.of(d) | ||
| default: break // .dictionary, .array, .null not representable as FlagMetadataValue | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // MARK: - ProviderEvaluation Extensions | ||
|
|
||
| extension ProviderEvaluation where T == Bool { | ||
| /// Creates ProviderEvaluation<Bool> from DatadogFlags FlagDetails<Bool> | ||
| init(_ details: FlagDetails<Bool>) { | ||
| self.init( | ||
| value: details.value, | ||
| flagMetadata: [:], | ||
| flagMetadata: details.metadata.toOpenFeatureFlagMetadata(), | ||
| variant: details.variant, | ||
| reason: details.reason | ||
| ) | ||
|
|
@@ -27,7 +46,7 @@ extension ProviderEvaluation where T == String { | |
| init(_ details: FlagDetails<String>) { | ||
| self.init( | ||
| value: details.value, | ||
| flagMetadata: [:], | ||
| flagMetadata: details.metadata.toOpenFeatureFlagMetadata(), | ||
| variant: details.variant, | ||
| reason: details.reason | ||
| ) | ||
|
|
@@ -39,7 +58,7 @@ extension ProviderEvaluation where T == Double { | |
| init(_ details: FlagDetails<Double>) { | ||
| self.init( | ||
| value: details.value, | ||
| flagMetadata: [:], | ||
| flagMetadata: details.metadata.toOpenFeatureFlagMetadata(), | ||
| variant: details.variant, | ||
| reason: details.reason | ||
| ) | ||
|
|
@@ -52,7 +71,7 @@ extension ProviderEvaluation where T == Int64 { | |
| init(_ details: FlagDetails<Int>) { | ||
| self.init( | ||
| value: Int64(details.value), | ||
| flagMetadata: [:], | ||
| flagMetadata: details.metadata.toOpenFeatureFlagMetadata(), | ||
| variant: details.variant, | ||
| reason: details.reason | ||
| ) | ||
|
|
@@ -65,7 +84,7 @@ extension ProviderEvaluation where T == Value { | |
| init(_ details: FlagDetails<AnyValue>) { | ||
| self.init( | ||
| value: Value(details.value), | ||
| flagMetadata: [:], | ||
| flagMetadata: details.metadata.toOpenFeatureFlagMetadata(), | ||
| variant: details.variant, | ||
| reason: details.reason | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,6 +207,39 @@ internal struct ComplexValueEvaluationTests { | |
| } | ||
| } | ||
|
|
||
| @Suite("ProviderEvaluation Metadata") | ||
| internal struct ProviderEvaluationMetadataTests { | ||
| @Test("Metadata threaded into flagMetadata") | ||
| func metadataThreadedIntoFlagMetadata() async throws { | ||
| let flagDetails = FlagDetails<Bool>( | ||
| key: "test-flag", | ||
| value: true, | ||
| variant: "on", | ||
| reason: "targeting_match", | ||
| metadata: ["allocationKey": .string("alloc-abc"), "version": .string("2")] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would add a few more types in here for more test coverage: int, double, bool, etc
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| ) | ||
|
|
||
| let evaluation = ProviderEvaluation(flagDetails) | ||
|
|
||
| #expect(evaluation.flagMetadata["allocationKey"] == FlagMetadataValue.string("alloc-abc")) | ||
| #expect(evaluation.flagMetadata["version"] == FlagMetadataValue.string("2")) | ||
| } | ||
|
|
||
| @Test("Empty metadata produces empty flagMetadata") | ||
| func emptyMetadataProducesEmptyFlagMetadata() async throws { | ||
| let flagDetails = FlagDetails<Bool>( | ||
| key: "test-flag", | ||
| value: true, | ||
| variant: "on", | ||
| reason: "default" | ||
| ) | ||
|
|
||
| let evaluation = ProviderEvaluation(flagDetails) | ||
|
|
||
| #expect(evaluation.flagMetadata.isEmpty) | ||
| } | ||
| } | ||
|
|
||
| @Suite("ProviderEvaluation Edge Cases") | ||
| internal struct ProviderEvaluationEdgeCaseTests { | ||
| @Test("Evaluation with nil variant and reason") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this version bump related to the
metadatachange?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the latest dd-sdk-ios
package.swifthas bumped to12.6so too must we here