Skip to content
Merged
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
5 changes: 4 additions & 1 deletion Sources/eppo/Assignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Assignment: CustomStringConvertible {
public var subjectAttributes: SubjectAttributes
public var metaData: [String: String]
public var extraLogging: [String: String]
public var entityId: Int?

public var description: String {
return "Subject " + subject + " assigned to variation " + variation + " in experiment " + experiment
Expand All @@ -21,7 +22,8 @@ public class Assignment: CustomStringConvertible {
timestamp: String,
subjectAttributes: SubjectAttributes,
metaData: [String: String] = [:],
extraLogging: [String: String] = [:]
extraLogging: [String: String] = [:],
entityId: Int? = nil
) {
self.allocation = allocationKey
self.experiment = flagKey + "-" + allocationKey
Expand All @@ -32,5 +34,6 @@ public class Assignment: CustomStringConvertible {
self.subjectAttributes = subjectAttributes
self.metaData = metaData
self.extraLogging = extraLogging
self.entityId = entityId
}
}
2 changes: 1 addition & 1 deletion Sources/eppo/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// todo: make this a build argument (FF-1944)
public let sdkName = "ios"
public let sdkVersion = "4.3.0"
public let sdkVersion = "4.4.0"

public let defaultHost = "https://fscdn.eppo.cloud/api"
10 changes: 7 additions & 3 deletions Sources/eppo/EppoClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ public class EppoClient {
subjectKey: subjectKey,
subjectAttributes: subjectAttributes,
flagEvaluationCode: .flagUnrecognizedOrDisabled,
flagEvaluationDescription: "Unrecognized or disabled flag: \(flagKey)"
flagEvaluationDescription: "Unrecognized or disabled flag: \(flagKey)",
entityId: nil
)
}

Expand All @@ -360,7 +361,8 @@ public class EppoClient {
flagEvaluationCode: .typeMismatch,
flagEvaluationDescription: "Variation value does not have the correct type. Found \(flagConfig.variationType.rawValue.uppercased()), but expected \(expectedVariationType.rawValue.uppercased()) for flag \(flagKey)",
unmatchedAllocations: [],
unevaluatedAllocations: allAllocations
unevaluatedAllocations: allAllocations,
entityId: flagConfig.entityId
)
}

Expand Down Expand Up @@ -391,6 +393,7 @@ public class EppoClient {
} else {
// Either the cache is not defined, or the assignment hasn't been logged yet
// Perform assignment.
let entityId = flagEvaluation.entityId
let assignment = Assignment(
flagKey: flagKey,
allocationKey: allocationKey,
Expand All @@ -403,7 +406,8 @@ public class EppoClient {
"sdkName": sdkName,
"sdkVersion": sdkVersion
],
extraLogging: flagEvaluation.extraLogging
extraLogging: flagEvaluation.extraLogging,
entityId: entityId
)

assignmentLogger(assignment)
Expand Down
13 changes: 9 additions & 4 deletions Sources/eppo/FlagEvaluation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public struct FlagEvaluation {
let unevaluatedAllocations: [AllocationEvaluation]
let flagEvaluationCode: EppoClient.FlagEvaluationCode
let flagEvaluationDescription: String
let entityId: Int?

static func matchedResult(
flagKey: String,
Expand All @@ -30,7 +31,8 @@ public struct FlagEvaluation {
matchedAllocation: AllocationEvaluation? = nil,
allocation: UFC_Allocation? = nil,
unmatchedAllocations: [AllocationEvaluation] = [],
unevaluatedAllocations: [AllocationEvaluation] = []
unevaluatedAllocations: [AllocationEvaluation] = [],
entityId: Int? = nil
) -> FlagEvaluation {
// If the config is obfuscated, we need to unobfuscate the allocation key.
var decodedAllocationKey: String = allocationKey ?? ""
Expand Down Expand Up @@ -97,7 +99,8 @@ public struct FlagEvaluation {
unmatchedAllocations: unmatchedAllocations,
unevaluatedAllocations: unevaluatedAllocations,
flagEvaluationCode: .match,
flagEvaluationDescription: flagEvaluationDescription
flagEvaluationDescription: flagEvaluationDescription,
entityId: entityId
)
}

Expand All @@ -108,7 +111,8 @@ public struct FlagEvaluation {
flagEvaluationCode: EppoClient.FlagEvaluationCode = .flagUnrecognizedOrDisabled,
flagEvaluationDescription: String? = nil,
unmatchedAllocations: [AllocationEvaluation] = [],
unevaluatedAllocations: [AllocationEvaluation] = []
unevaluatedAllocations: [AllocationEvaluation] = [],
entityId: Int? = nil
) -> FlagEvaluation {
return FlagEvaluation(
flagKey: flagKey,
Expand All @@ -124,7 +128,8 @@ public struct FlagEvaluation {
unmatchedAllocations: unmatchedAllocations,
unevaluatedAllocations: unevaluatedAllocations,
flagEvaluationCode: flagEvaluationCode,
flagEvaluationDescription: flagEvaluationDescription ?? "Unrecognized or disabled flag: \(flagKey)"
flagEvaluationDescription: flagEvaluationDescription ?? "Unrecognized or disabled flag: \(flagKey)",
entityId: entityId
)
}
}
Expand Down
30 changes: 20 additions & 10 deletions Sources/eppo/RuleEvaluator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class FlagEvaluator {
return FlagEvaluation.noneResult(
flagKey: flag.key,
subjectKey: subjectKey,
subjectAttributes: subjectAttributes
subjectAttributes: subjectAttributes,
entityId: flag.entityId
)
}

Expand All @@ -44,7 +45,8 @@ public class FlagEvaluator {
return FlagEvaluation.noneResult(
flagKey: flag.key,
subjectKey: subjectKey,
subjectAttributes: subjectAttributes
subjectAttributes: subjectAttributes,
entityId: flag.entityId
)
}

Expand All @@ -55,7 +57,8 @@ public class FlagEvaluator {
subjectKey: subjectKey,
subjectAttributes: subjectAttributes,
flagEvaluationCode: .flagUnrecognizedOrDisabled,
flagEvaluationDescription: "Unrecognized or disabled flag: \(flag.key)"
flagEvaluationDescription: "Unrecognized or disabled flag: \(flag.key)",
entityId: flag.entityId
)
return result
}
Expand Down Expand Up @@ -171,7 +174,8 @@ public class FlagEvaluator {
unmatchedAllocations: unmatchedAllocations,
unevaluatedAllocations: unevaluatedAllocations,
flagEvaluationCode: .assignmentError,
flagEvaluationDescription: "Variation (\(variation.key)) is configured for type INTEGER, but is set to incompatible value (\(doubleValue))"
flagEvaluationDescription: "Variation (\(variation.key)) is configured for type INTEGER, but is set to incompatible value (\(doubleValue))",
entityId: flag.entityId
)
return evaluation
}
Expand All @@ -194,7 +198,8 @@ public class FlagEvaluator {
matchedAllocation: matchedAllocation,
allocation: allocation,
unmatchedAllocations: unmatchedAllocations,
unevaluatedAllocations: unevaluatedAllocations
unevaluatedAllocations: unevaluatedAllocations,
entityId: flag.entityId
)
}

Expand Down Expand Up @@ -225,7 +230,8 @@ public class FlagEvaluator {
unmatchedAllocations: unmatchedAllocations,
unevaluatedAllocations: unevaluatedAllocations,
flagEvaluationCode: .assignmentError,
flagEvaluationDescription: "Variation (\(variation.key)) is configured for type INTEGER, but is set to incompatible value (\(doubleValue))"
flagEvaluationDescription: "Variation (\(variation.key)) is configured for type INTEGER, but is set to incompatible value (\(doubleValue))",
entityId: flag.entityId
)
}
// Create a new variation with the decoded value
Expand All @@ -247,7 +253,8 @@ public class FlagEvaluator {
matchedAllocation: matchedAllocation,
allocation: allocation,
unmatchedAllocations: unmatchedAllocations,
unevaluatedAllocations: unevaluatedAllocations
unevaluatedAllocations: unevaluatedAllocations,
entityId: flag.entityId
)
}
}
Expand All @@ -265,7 +272,8 @@ public class FlagEvaluator {
unmatchedAllocations: unmatchedAllocations,
unevaluatedAllocations: unevaluatedAllocations,
flagEvaluationCode: .assignmentError,
flagEvaluationDescription: "Variation (\(variation.key)) is configured for type INTEGER, but is set to incompatible value"
flagEvaluationDescription: "Variation (\(variation.key)) is configured for type INTEGER, but is set to incompatible value",
entityId: flag.entityId
)
} else {
return FlagEvaluation.noneResult(
Expand All @@ -292,7 +300,8 @@ public class FlagEvaluator {
matchedAllocation: matchedAllocation,
allocation: allocation,
unmatchedAllocations: unmatchedAllocations,
unevaluatedAllocations: unevaluatedAllocations
unevaluatedAllocations: unevaluatedAllocations,
entityId: flag.entityId
)
}
}
Expand All @@ -311,7 +320,8 @@ public class FlagEvaluator {
subjectKey: subjectKey,
subjectAttributes: subjectAttributes,
unmatchedAllocations: unmatchedAllocations,
unevaluatedAllocations: unevaluatedAllocations
unevaluatedAllocations: unevaluatedAllocations,
entityId: flag.entityId
)
}

Expand Down
1 change: 1 addition & 0 deletions Sources/eppo/UniversalFlagConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public struct UFC_Flag: Codable {
let variations: [String: UFC_Variation]
let allocations: [UFC_Allocation]
let totalShards: Int
let entityId: Int?
}

public struct UFC_Variation: Codable {
Expand Down
Loading
Loading