-
Notifications
You must be signed in to change notification settings - Fork 20
feat(dfm): Integrate DFM with optimizely #161
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
Conversation
…rojectConfig as its implementation. Created StaticProjectConfigManager and HttpProjectConfigManager for handling datafile retrievel. Created PollingProjectConfigManager for retrieving ProjectConfig on the specified interval. Added OnReady future in PollingProjectConfigManager class. Added unit tests.
# Conflicts: # OptimizelySDK/DatafileManagement/DatafileProjectConfig.cs
# Conflicts: # OptimizelySDK/DatafileManagement/ProjectConfigManager.cs # OptimizelySDK/Optimizely.cs
# Conflicts: # OptimizelySDK.Net40/OptimizelySDK.Net40.csproj # OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj # OptimizelySDK.Tests/DecisionServiceTest.cs # OptimizelySDK.Tests/OptimizelySDK.Tests.csproj # OptimizelySDK.Tests/OptimizelyTest.cs # OptimizelySDK/Config/DatafileProjectConfig.cs # OptimizelySDK/Config/FallbackProjectConfigManager.cs # OptimizelySDK/Optimizely.cs # OptimizelySDK/OptimizelySDK.csproj # OptimizelySDK/ProjectConfig.cs
mjc1283
left a comment
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 it possible to move forced variations to decision service in a separate PR? This one is large.
|
OK, I will separate out ForcedVariation, infact @mfahadahmed will do it. |
| /// <summary> | ||
| /// Implementation of ProjectConfigManager interface that simply | ||
| /// returns the stored ProjectConfig instance. | ||
| /// </summary> |
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.
nit: Also mention that it is static and the config it holds cannot change
OptimizelySDK/Optimizely.cs
Outdated
| Initialize(eventDispatcher, logger, errorHandler, userProfileService); | ||
| } | ||
|
|
||
| private void Initialize(IEventDispatcher eventDispatcher = null, |
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.
nit: InitializeComponents?
OptimizelySDK/Optimizely.cs
Outdated
| var config = ProjectConfigManager?.GetConfig(); | ||
| if (!IsValid && config == null) { | ||
|
|
||
| Logger.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'GetVariation'."); |
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.
... Failing 'IsFeatureEnabled'
OptimizelySDK/Optimizely.cs
Outdated
| return null; | ||
| } | ||
|
|
||
| return GetFeatureVariableValueForType<bool?>(featureKey, variableKey, userId, userAttributes, FeatureVariable.VariableType.BOOLEAN, config); |
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.
Why do we need to pass the config to it? Why not have the GetFeatureVariableValueForType method use the ProjectConfigManager?
OptimizelySDK/Optimizely.cs
Outdated
| var config = ProjectConfigManager?.GetConfig(); | ||
|
|
||
| if (!IsValid && config == null) { | ||
| Logger.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'activate'."); |
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.
Not activate but GetFeatureVariableBoolean
| private void SendImpressionEvent(Experiment experiment, Variation variation, string userId, | ||
| UserAttributes userAttributes) | ||
| private void SendImpressionEvent(Experiment experiment, Variation variation, string userId, | ||
| UserAttributes userAttributes, ProjectConfig config) |
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.
We don't need to take in the ProjectConfig as a param. We can use the ProjectConfigManager in here
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.
This method is used by Activate, if we use ProjectConfigManager inside SendImpressionEvent, there are chances ProjectConfig used to get variation from DecisionService may not be same when get from ProjectConfigManagr inside this method.
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.
Hmm, ok that could actually happen.
OptimizelySDK/OptimizelyFactory.cs
Outdated
| namespace OptimizelySDK | ||
| { | ||
|
|
||
| /// TODO: Need to check with Mike, no need of this class |
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.
This is not the case anymore right?
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.
Yes, will add unit test and more convenience methods in separate PR. Removing this comment.
OptimizelySDK/OptimizelyFactory.cs
Outdated
| var errorHandler = new DefaultErrorHandler(); | ||
| var eventDispatcher = new DefaultEventDispatcher(logger); | ||
| var builder = new HttpProjectConfigManager.Builder(); | ||
| // don't block |
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.
What is this doc comment for?
OptimizelySDK/Optimizely.cs
Outdated
| { | ||
| if (!IsValid) | ||
| var config = ProjectConfigManager?.GetConfig(); | ||
| if (!IsValid && config == null) |
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.
Should this (and the same check elsewhere) be using an or operator instead of and operator? I.e., !IsValid || config == null
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.
It should be AND, if isValid is false and also Config is null, then it's invalid.
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.
ProjectConfigManager.GetConfig can return null. When it does, we must return null early, otherwise attempting to access config.GetExperimentFromKey could crash. If I'm misunderstanding, let me know.
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.
So IsValid will always be false if we are using ProjectConfigManager to initialize Optimizely instance.
Please let me know we can chat for more clarity.
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.
Since we are opening up the ProjectConfigManager to be overriden, we should guard against the custom implementation not returning null or not setting isValid to false. Therefore I think the right apporach is to be more careful and use !IsValid || config == null like @mjc1283 suggested.
OptimizelySDK/Optimizely.cs
Outdated
|
|
||
| var config = ProjectConfigManager?.GetConfig(); | ||
| if (!IsValid && config == null) { | ||
| Logger.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'activate'."); |
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.
This still refers to activate. Please make sure it references the right API name.
| /// <summary> | ||
| /// Implementation of ProjectConfigManager interface that simply | ||
| /// returns the stored ProjectConfig instance. | ||
| /// returns the stored ProjectConfig instance which is mutable and cannot be changed. |
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.
Hmm this is confusing. The ProjectConfig in this manager should not be mutable.
|
@mikeng13 Please check my last commit, feedback addressed. |
OptimizelySDK/Optimizely.cs
Outdated
| { | ||
| if (!IsValid) | ||
| var config = ProjectConfigManager?.GetConfig(); | ||
| if (!IsValid && config == null) |
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.
ProjectConfigManager.GetConfig can return null. When it does, we must return null early, otherwise attempting to access config.GetExperimentFromKey could crash. If I'm misunderstanding, let me know.
mikeproeng37
left a comment
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.
lgtm
mjc1283
left a comment
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.
LGTM, isValid changes look good.
Summary
TODO:
Test plan
Issues