Skip to content
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

Merged
merged 12 commits into from
Jan 20, 2021

Conversation

msohailhussain
Copy link
Contributor

Summary

  • returning reasons and removed from args
  • added overloaded operator in DecisionReasons
  • Now only one class is using DecisionReasons, toReport filters based on the DecisionOptions.

Test plan

  • All unit tests and FSC must pass.

msohailhussain and others added 3 commits December 22, 2020 23:30
…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);
Copy link
Contributor Author

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);
Copy link
Contributor Author

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;
Copy link
Contributor Author

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)
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

Copy link
Contributor

@jaeopt jaeopt left a 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);
Copy link
Contributor

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
Copy link
Contributor

@jaeopt jaeopt left a 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reasons += variationResult?.DecisionReasons;
reasons += variationResult.DecisionReasons;

# Conflicts:
#	OptimizelySDK.Tests/BucketerTest.cs
#	OptimizelySDK.Tests/UtilsTests/ExperimentUtilsTest.cs
@jaeopt jaeopt merged commit d990004 into master Jan 20, 2021
@jaeopt jaeopt deleted the sohail/decisionresultrefactoring branch January 20, 2021 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants