|
22 | 22 | using OptimizelySDK.Logger;
|
23 | 23 | using OptimizelySDK.OptimizelyDecisions;
|
24 | 24 | using OptimizelySDK.Utils;
|
| 25 | +using static OptimizelySDK.Entity.Holdout; |
25 | 26 |
|
26 | 27 | namespace OptimizelySDK.Bucketing
|
27 | 28 | {
|
@@ -754,7 +755,22 @@ OptimizelyDecideOption[] options
|
754 | 755 | {
|
755 | 756 | var reasons = new DecisionReasons();
|
756 | 757 | reasons += upsReasons;
|
| 758 | + var holdouts = projectConfig.GetHoldoutsForFlag(featureFlag.Key); |
| 759 | + foreach (var holdout in holdouts) |
| 760 | + { |
| 761 | + var holdoutDecision = GetVariationForHoldout(holdout, user, projectConfig); |
| 762 | + reasons += holdoutDecision.DecisionReasons; |
757 | 763 |
|
| 764 | + if (holdoutDecision.ResultObject != null) |
| 765 | + { |
| 766 | + Logger.Log(LogLevel.INFO, |
| 767 | + reasons.AddInfo( |
| 768 | + $"The user \"{userId}\" is bucketed into holdout \"{holdout.Key}\" for feature flag \"{featureFlag.Key}\".")); |
| 769 | + decisions.Add(Result<FeatureDecision>.NewResult(holdoutDecision.ResultObject, |
| 770 | + reasons)); |
| 771 | + continue; |
| 772 | + } |
| 773 | + } |
758 | 774 | // Check if the feature flag has an experiment and the user is bucketed into that experiment.
|
759 | 775 | var decisionResult = GetVariationForFeatureExperiment(featureFlag, user,
|
760 | 776 | filteredAttributes, projectConfig, options, userProfileTracker);
|
@@ -856,6 +872,76 @@ private Result<string> GetBucketingId(string userId, UserAttributes filteredAttr
|
856 | 872 | return Result<string>.NewResult(bucketingId, reasons);
|
857 | 873 | }
|
858 | 874 |
|
| 875 | + private Result<FeatureDecision> GetVariationForHoldout( |
| 876 | + Holdout holdout, |
| 877 | + OptimizelyUserContext user, |
| 878 | + ProjectConfig config |
| 879 | + ) |
| 880 | + { |
| 881 | + var userId = user.GetUserId(); |
| 882 | + var reasons = new DecisionReasons(); |
| 883 | + |
| 884 | + if (!holdout.IsActivated) |
| 885 | + { |
| 886 | + reasons.AddInfo("Holdout ({0}) is not running.", holdout.Key); |
| 887 | + return Result<FeatureDecision>.NewResult( |
| 888 | + new FeatureDecision(null, null, FeatureDecision.DECISION_SOURCE_HOLDOUT), |
| 889 | + reasons |
| 890 | + ); |
| 891 | + } |
| 892 | + |
| 893 | + var audienceResult = ExperimentUtils.DoesUserMeetAudienceConditions( |
| 894 | + config, |
| 895 | + holdout, |
| 896 | + user, |
| 897 | + LOGGING_KEY_TYPE_EXPERIMENT, |
| 898 | + holdout.Key, |
| 899 | + Logger |
| 900 | + ); |
| 901 | + reasons += audienceResult.DecisionReasons; |
| 902 | + |
| 903 | + if (!audienceResult.ResultObject) |
| 904 | + { |
| 905 | + reasons.AddInfo( |
| 906 | + "User ({0}) does not meet conditions for holdout ({1}).", |
| 907 | + userId, |
| 908 | + holdout.Key |
| 909 | + ); |
| 910 | + return Result<FeatureDecision>.NewResult( |
| 911 | + new FeatureDecision(null, null, FeatureDecision.DECISION_SOURCE_HOLDOUT), |
| 912 | + reasons |
| 913 | + ); |
| 914 | + } |
| 915 | + |
| 916 | + var attributes = user.GetAttributes(); |
| 917 | + var bucketingIdResult = GetBucketingId(userId, attributes); |
| 918 | + var bucketedVariation = Bucketer.Bucket(config, holdout, bucketingIdResult.ResultObject, userId); |
| 919 | + reasons += bucketedVariation.DecisionReasons; |
| 920 | + |
| 921 | + if (bucketedVariation.ResultObject != null) |
| 922 | + { |
| 923 | + reasons.AddInfo( |
| 924 | + "User ({0}) is bucketed into holdout variation ({1}).", |
| 925 | + userId, |
| 926 | + bucketedVariation.ResultObject.Key |
| 927 | + ); |
| 928 | + return Result<FeatureDecision>.NewResult( |
| 929 | + new FeatureDecision(holdout, bucketedVariation.ResultObject, FeatureDecision.DECISION_SOURCE_HOLDOUT), |
| 930 | + reasons |
| 931 | + ); |
| 932 | + } |
| 933 | + |
| 934 | + reasons.AddInfo( |
| 935 | + "User ({0}) is not bucketed into holdout variation ({1}).", |
| 936 | + userId, |
| 937 | + holdout.Key |
| 938 | + ); |
| 939 | + |
| 940 | + return Result<FeatureDecision>.NewResult( |
| 941 | + new FeatureDecision(null, null, FeatureDecision.DECISION_SOURCE_HOLDOUT), |
| 942 | + reasons |
| 943 | + ); |
| 944 | + } |
859 | 945 | /// <summary>
|
860 | 946 | /// Finds a validated forced decision.
|
861 | 947 | /// </summary>
|
|
0 commit comments