-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat(flag-decisions): Add support for sending flag decisions along with decision metadata. #370
Merged
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5bdd20b
Initial commit.
yasirfolio3 7a935f7
Tests added.
yasirfolio3 116a6fb
fixes.
yasirfolio3 69d6e22
Merge branch 'master' into yasir/flag-decisions
pawels-optimizely 9712a60
1. Updated flag_type to rule_type.
yasirfolio3 974f4d9
fixes.
yasirfolio3 0b501a3
suggested changes made.
yasirfolio3 1bd30c8
fixed by reverting some changes.
yasirfolio3 79a9241
fixes as per discussion.
yasirfolio3 08d2abe
nit fixed.
yasirfolio3 4753176
fixing indentation issues.
yasirfolio3 1dc28ac
indentation fixes.
yasirfolio3 4f3f06f
suggested changes made.
yasirfolio3 7c0f6ef
indentation fixed.
yasirfolio3 397a51d
nit fixed.
yasirfolio3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
/**************************************************************************** | ||
* Copyright 2019-2020, Optimizely, Inc. and contributors * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); * | ||
* you may not use this file except in compliance with the License. * | ||
* You may obtain a copy of the License at * | ||
* * | ||
* http://www.apache.org/licenses/LICENSE-2.0 * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
***************************************************************************/ | ||
* Copyright 2019-2020, Optimizely, Inc. and contributors * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); * | ||
* you may not use this file except in compliance with the License. * | ||
* You may obtain a copy of the License at * | ||
* * | ||
* http://www.apache.org/licenses/LICENSE-2.0 * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
***************************************************************************/ | ||
|
||
import Foundation | ||
|
||
|
@@ -34,7 +34,7 @@ open class OptimizelyClient: NSObject { | |
atomicConfig.property = newValue | ||
} | ||
} | ||
|
||
public var version: String { | ||
return Utils.sdkVersion | ||
} | ||
|
@@ -48,7 +48,7 @@ open class OptimizelyClient: NSObject { | |
return false | ||
} | ||
} | ||
|
||
// MARK: - Customizable Services | ||
|
||
lazy var logger = OPTLoggerFactory.getLogger() | ||
|
@@ -70,7 +70,7 @@ open class OptimizelyClient: NSObject { | |
public var notificationCenter: OPTNotificationCenter? { | ||
return HandlerRegistryService.shared.injectNotificationCenter(sdkKey: self.sdkKey) | ||
} | ||
|
||
// MARK: - Public interfaces | ||
|
||
/// OptimizelyClient init | ||
|
@@ -184,7 +184,7 @@ open class OptimizelyClient: NSObject { | |
func configSDK(datafile: Data) throws { | ||
do { | ||
self.config = try ProjectConfig(datafile: datafile) | ||
|
||
datafileHandler?.startUpdates(sdkKey: self.sdkKey) { data in | ||
// new datafile came in | ||
self.updateConfigFromBackgroundFetch(data: data) | ||
|
@@ -223,10 +223,10 @@ open class OptimizelyClient: NSObject { | |
for component in HandlerRegistryService.shared.lookupComponents(sdkKey: self.sdkKey) ?? [] { | ||
HandlerRegistryService.shared.reInitializeComponent(service: component, sdkKey: self.sdkKey) | ||
} | ||
|
||
self.sendDatafileChangeNotification(data: data) | ||
} | ||
|
||
/** | ||
* Use the activate method to start an experiment. | ||
* | ||
|
@@ -259,7 +259,7 @@ open class OptimizelyClient: NSObject { | |
variation: variation, | ||
userId: userId, | ||
attributes: attributes, | ||
flagKey: experimentKey, | ||
flagKey: "", | ||
ruleType: "experiment") | ||
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. Do we have this new ruleType "experiment"? If so, can we add it to DecisionSource enum? |
||
|
||
return variation.key | ||
|
@@ -374,32 +374,27 @@ open class OptimizelyClient: NSObject { | |
return false | ||
} | ||
|
||
guard let pair = decisionService.getVariationForFeature(config: config, | ||
let pair = decisionService.getVariationForFeature(config: config, | ||
featureFlag: featureFlag, | ||
userId: userId, | ||
attributes: attributes ?? OptimizelyAttributes()) else { | ||
sendDecisionNotification(decisionType: .feature, | ||
userId: userId, | ||
attributes: attributes, | ||
feature: featureFlag, | ||
featureEnabled: false) | ||
return false | ||
} | ||
let featureEnabled = pair.variation.featureEnabled ?? false | ||
attributes: attributes ?? OptimizelyAttributes()) | ||
|
||
let source = pair?.source ?? Constants.DecisionSource.rollout.rawValue | ||
let featureEnabled = pair?.variation.featureEnabled ?? false | ||
if featureEnabled { | ||
logger.i(.featureEnabledForUser(featureKey, userId)) | ||
} else { | ||
logger.i(.featureNotEnabledForUser(featureKey, userId)) | ||
} | ||
|
||
sendImpressionEvent(experiment: pair.experiment, variation: pair.variation, userId: userId, attributes: attributes, flagKey: featureKey, ruleType: pair.source) | ||
|
||
sendImpressionEvent(experiment: pair?.experiment, variation: pair?.variation, userId: userId, attributes: attributes, flagKey: featureKey, ruleType: source) | ||
sendDecisionNotification(decisionType: .feature, | ||
userId: userId, | ||
attributes: attributes, | ||
experiment: pair.experiment, | ||
variation: pair.variation, | ||
source: pair.source, | ||
experiment: pair?.experiment, | ||
variation: pair?.variation, | ||
source: source, | ||
feature: featureFlag, | ||
featureEnabled: featureEnabled) | ||
|
||
|
@@ -479,7 +474,7 @@ open class OptimizelyClient: NSObject { | |
variableKey: String, | ||
userId: String, | ||
attributes: OptimizelyAttributes? = nil) throws -> String { | ||
|
||
return try getFeatureVariable(featureKey: featureKey, | ||
variableKey: variableKey, | ||
userId: userId, | ||
|
@@ -571,8 +566,8 @@ open class OptimizelyClient: NSObject { | |
} | ||
|
||
guard let value = valueParsed, | ||
type?.rawValue == variable.type else { | ||
throw OptimizelyError.variableValueInvalid(variableKey) | ||
type?.rawValue == variable.type else { | ||
throw OptimizelyError.variableValueInvalid(variableKey) | ||
} | ||
|
||
// Decision Notification | ||
|
@@ -656,7 +651,7 @@ open class OptimizelyClient: NSObject { | |
break | ||
} | ||
} | ||
|
||
if let value = valueParsed { | ||
variableMap[v.key] = value | ||
} else { | ||
|
@@ -723,7 +718,7 @@ open class OptimizelyClient: NSObject { | |
|
||
sendConversionEvent(eventKey: eventKey, userId: userId, attributes: attributes, eventTags: eventTags) | ||
} | ||
|
||
/// Read a copy of project configuration data model. | ||
/// | ||
/// This call returns a snapshot of the current project configuration. | ||
|
@@ -736,7 +731,7 @@ open class OptimizelyClient: NSObject { | |
/// - Throws: `OptimizelyError` if SDK is not ready | ||
public func getOptimizelyConfig() throws -> OptimizelyConfig { | ||
guard let config = self.config else { throw OptimizelyError.sdkNotReady } | ||
|
||
return OptimizelyConfigImp(projectConfig: config) | ||
} | ||
} | ||
|
@@ -745,7 +740,7 @@ open class OptimizelyClient: NSObject { | |
|
||
extension OptimizelyClient { | ||
|
||
func sendImpressionEvent(experiment: Experiment, | ||
func sendImpressionEvent(experiment: Experiment?, | ||
variation: Variation?, | ||
userId: String, | ||
attributes: OptimizelyAttributes? = nil, | ||
|
@@ -755,34 +750,34 @@ extension OptimizelyClient { | |
// non-blocking (event data serialization takes time) | ||
eventLock.async { | ||
guard let config = self.config else { return } | ||
|
||
guard let body = BatchEventBuilder.createImpressionEvent(config: config, | ||
experiment: experiment, | ||
variation: variation, | ||
userId: userId, | ||
attributes: attributes, | ||
flagKey: flagKey, | ||
ruleType: ruleType) else { | ||
self.logger.e(OptimizelyError.eventBuildFailure(DispatchEvent.activateEventKey)) | ||
return | ||
self.logger.e(OptimizelyError.eventBuildFailure(DispatchEvent.activateEventKey)) | ||
return | ||
} | ||
|
||
let event = EventForDispatch(body: body) | ||
self.sendEventToDispatcher(event: event, completionHandler: nil) | ||
|
||
// send notification in sync mode (functionally same as async here since it's already in background thread), | ||
// but this will make testing simpler (timing control) | ||
|
||
if let tmpVariation = variation { | ||
self.sendActivateNotification(experiment: experiment, | ||
if let tmpExperiment = experiment, let tmpVariation = variation { | ||
self.sendActivateNotification(experiment: tmpExperiment, | ||
variation: tmpVariation, | ||
userId: userId, | ||
attributes: attributes, | ||
event: event, | ||
async: false) | ||
} | ||
} | ||
|
||
} | ||
|
||
func sendConversionEvent(eventKey: String, | ||
|
@@ -793,22 +788,22 @@ extension OptimizelyClient { | |
// non-blocking (event data serialization takes time) | ||
eventLock.async { | ||
guard let config = self.config else { return } | ||
|
||
guard let body = BatchEventBuilder.createConversionEvent(config: config, | ||
eventKey: eventKey, | ||
userId: userId, | ||
attributes: attributes, | ||
eventTags: eventTags) else { | ||
self.logger.e(OptimizelyError.eventBuildFailure(eventKey)) | ||
return | ||
self.logger.e(OptimizelyError.eventBuildFailure(eventKey)) | ||
return | ||
} | ||
|
||
let event = EventForDispatch(body: body) | ||
self.sendEventToDispatcher(event: event, completionHandler: nil) | ||
|
||
// send notification in sync mode (functionally same as async here since it's already in background thread), | ||
// but this will make testing simpler (timing control) | ||
|
||
self.sendTrackNotification(eventKey: eventKey, | ||
userId: userId, | ||
attributes: attributes, | ||
|
@@ -968,7 +963,7 @@ extension OptimizelyClient { | |
notify() | ||
} | ||
} | ||
|
||
} | ||
|
||
// MARK: - For test support | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove this empty line