-
Notifications
You must be signed in to change notification settings - Fork 20
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: return reasons and remove from args. #255
Conversation
…w and added TODO above to come up with logic of setting it using decide option Fixed unit tests and resolved minor null pointer exceptions
|
||
} | ||
|
||
// success! | ||
variation = config.GetVariationFromId(experiment.Key, variationId); | ||
message = $"User [{userId}] is in variation [{variation.Key}] of experiment [{experiment.Key}]."; | ||
Logger.Log(LogLevel.INFO, reasons.AddInfo(message)); | ||
return variation; | ||
return Result<Variation>.NewResult(variation, reasons); |
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.
EOL.
if (!ExperimentUtils.IsExperimentActive(experiment, Logger)) return null; | ||
|
||
// check if a forced variation is set | ||
var forcedVariation = GetForcedVariation(experiment.Key, userId, config, reasons); | ||
var forcedVariation = GetForcedVariation(experiment.Key, userId, 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.
call it forcedVariationResult
if (forcedVariation != null) | ||
return forcedVariation; | ||
{ | ||
reasons += forcedVariation?.DecisionReasons; |
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.
append before if condition.
if (!ExperimentUtils.IsExperimentActive(experiment, Logger)) return null; | ||
|
||
// check if a forced variation is set | ||
var forcedVariation = GetForcedVariation(experiment.Key, userId, config, reasons); | ||
var forcedVariation = GetForcedVariation(experiment.Key, userId, config); | ||
if (forcedVariation != 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.
must check result object.
@@ -558,9 +554,9 @@ public void SaveVariation(Experiment experiment, Variation variation, UserProfil | |||
/// <param name = "filteredAttributes" >The user's attributes. This should be filtered to just attributes in the Datafile.</param> | |||
/// <returns>null if the user is not bucketed into any variation or the FeatureDecision entity if the user is | |||
/// successfully bucketed.</returns> | |||
public virtual FeatureDecision GetVariationForFeature(FeatureFlag featureFlag, string userId, ProjectConfig config, UserAttributes filteredAttributes) | |||
public virtual Result<FeatureDecision> GetVariationForFeature(FeatureFlag featureFlag, string userId, ProjectConfig config, UserAttributes filteredAttributes) |
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.
I think we should remove this method. No use of it.
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.
Overall looks good.
I suggest to add tests validating core messages of reasons returned from decision to make sure reason collecting works as expected. See my comments.
LoggerMock.Verify(l => l.Log(LogLevel.ERROR, | ||
string.Format("Variation \"{0}\" is not in the datafile. Not activating user \"{1}\".", invalidVariationKey, userId)), | ||
Times.Once); | ||
|
||
BucketerMock.Verify(_ => _.Bucket(It.IsAny<ProjectConfig>(), It.IsAny<Experiment>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IDecisionReasons>()), Times.Never); | ||
BucketerMock.Verify(_ => _.Bucket(It.IsAny<ProjectConfig>(), It.IsAny<Experiment>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never); |
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.
Need to validate reasons messages as well
Removed unnecessary ? marks
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 with nits
@@ -461,20 +461,15 @@ public void SaveVariation(Experiment experiment, Variation variation, UserProfil | |||
if (userMeetConditionsResult.ResultObject) | |||
{ | |||
variationResult = Bucketer.Bucket(config, rolloutRule, bucketingIdResult.ResultObject, userId); | |||
|
|||
reasons += variationResult?.DecisionReasons; |
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.
reasons += variationResult?.DecisionReasons; | |
reasons += variationResult.DecisionReasons; |
@@ -486,9 +481,10 @@ public void SaveVariation(Experiment experiment, Variation variation, UserProfil | |||
if (userMeetConditionsResultEveryoneElse.ResultObject) | |||
{ | |||
variationResult = Bucketer.Bucket(config, everyoneElseRolloutRule, bucketingIdResult.ResultObject, userId); | |||
reasons += variationResult?.DecisionReasons; |
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.
reasons += variationResult?.DecisionReasons; | |
reasons += variationResult.DecisionReasons; |
# Conflicts: # OptimizelySDK.Tests/BucketerTest.cs # OptimizelySDK.Tests/UtilsTests/ExperimentUtilsTest.cs
Summary
Test plan