-
Notifications
You must be signed in to change notification settings - Fork 32
refact(audience-logs): Added and refactored audience and feature variable evaluation logs #380
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
Changes from all commits
7e01dfb
1070b0f
5e90af7
e95ec2d
5c0df79
1cef659
7112762
b7e064c
46de92d
40b565f
d916aa5
36a0b48
be289b1
56b36d4
77aba54
238bfeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/**************************************************************************** | ||
* Copyright 2017-2019, Optimizely, Inc. and contributors * | ||
* Copyright 2017-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. * | ||
|
@@ -17,7 +17,6 @@ | |
|
||
import com.optimizely.ab.OptimizelyRuntimeException; | ||
import com.optimizely.ab.config.*; | ||
import com.optimizely.ab.config.audience.Audience; | ||
import com.optimizely.ab.error.ErrorHandler; | ||
import com.optimizely.ab.internal.ExperimentUtils; | ||
import com.optimizely.ab.internal.ControlAttribute; | ||
|
@@ -32,6 +31,9 @@ | |
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
import static com.optimizely.ab.internal.LoggingConstants.LoggingEntityType.EXPERIMENT; | ||
import static com.optimizely.ab.internal.LoggingConstants.LoggingEntityType.RULE; | ||
|
||
/** | ||
* Optimizely's decision service that determines which variation of an experiment the user will be allocated to. | ||
* | ||
|
@@ -133,7 +135,7 @@ public Variation getVariation(@Nonnull Experiment experiment, | |
userProfile = new UserProfile(userId, new HashMap<String, Decision>()); | ||
} | ||
|
||
if (ExperimentUtils.isUserInExperiment(projectConfig, experiment, filteredAttributes)) { | ||
if (ExperimentUtils.doesUserMeetAudienceConditions(projectConfig, experiment, filteredAttributes, EXPERIMENT, experiment.getKey())) { | ||
String bucketingId = getBucketingId(userId, filteredAttributes); | ||
variation = bucketer.bucket(experiment, bucketingId, projectConfig); | ||
|
||
|
@@ -221,25 +223,24 @@ FeatureDecision getVariationForFeatureInRollout(@Nonnull FeatureFlag featureFlag | |
Variation variation; | ||
for (int i = 0; i < rolloutRulesLength - 1; i++) { | ||
Experiment rolloutRule = rollout.getExperiments().get(i); | ||
Audience audience = projectConfig.getAudienceIdMapping().get(rolloutRule.getAudienceIds().get(0)); | ||
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. was it additional? 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. yes as we removed the audience name this became redundant. |
||
if (ExperimentUtils.isUserInExperiment(projectConfig, rolloutRule, filteredAttributes)) { | ||
if (ExperimentUtils.doesUserMeetAudienceConditions(projectConfig, rolloutRule, filteredAttributes, RULE, Integer.toString(i + 1))) { | ||
variation = bucketer.bucket(rolloutRule, bucketingId, projectConfig); | ||
if (variation == null) { | ||
break; | ||
} | ||
return new FeatureDecision(rolloutRule, variation, | ||
FeatureDecision.DecisionSource.ROLLOUT); | ||
} else { | ||
logger.debug("User \"{}\" did not meet the conditions to be in rollout rule for audience \"{}\".", | ||
userId, audience.getName()); | ||
logger.debug("User \"{}\" does not meet conditions for targeting rule \"{}\".", userId, i + 1); | ||
} | ||
} | ||
|
||
// get last rule which is the fall back rule | ||
Experiment finalRule = rollout.getExperiments().get(rolloutRulesLength - 1); | ||
if (ExperimentUtils.isUserInExperiment(projectConfig, finalRule, filteredAttributes)) { | ||
if (ExperimentUtils.doesUserMeetAudienceConditions(projectConfig, finalRule, filteredAttributes, RULE, "Everyone Else")) { | ||
variation = bucketer.bucket(finalRule, bucketingId, projectConfig); | ||
if (variation != null) { | ||
logger.debug("User \"{}\" meets conditions for targeting rule \"Everyone Else\".", userId); | ||
return new FeatureDecision(finalRule, variation, | ||
FeatureDecision.DecisionSource.ROLLOUT); | ||
} | ||
|
@@ -394,7 +395,6 @@ public boolean setForcedVariation(@Nonnull Experiment experiment, | |
@Nullable String variationKey) { | ||
|
||
|
||
|
||
Variation variation = null; | ||
|
||
// keep in mind that you can pass in a variationKey that is null if you want to | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,9 +74,9 @@ public Boolean evaluate(ProjectConfig config, Map<String, ?> attributes) { | |
logger.error("Audience {} could not be found.", audienceId); | ||
return null; | ||
} | ||
logger.debug("Starting to evaluate audience {} with conditions: \"{}\"", audience.getName(), audience.getConditions()); | ||
logger.debug("Starting to evaluate audience \"{}\" with conditions: {}.", audience.getId(), audience.getConditions()); | ||
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. Let's get rid of this log message. I don't see this in other places. 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. Actually this log is getting logged in all other sdks, including python (which we followed). |
||
Boolean result = audience.getConditions().evaluate(config, attributes); | ||
logger.debug("Audience {} evaluated to {}", audience.getName(), result); | ||
logger.debug("Audience \"{}\" evaluated to {}.", audience.getId(), result); | ||
return result; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* | ||
* Copyright 2020, Optimizely 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. | ||
*/ | ||
package com.optimizely.ab.internal; | ||
|
||
public class LoggingConstants { | ||
public static class LoggingEntityType { | ||
public static final String EXPERIMENT = "experiment"; | ||
public static final String RULE = "rule"; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.