Skip to content

feat: added enabled field in metadata. #409

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

Merged
merged 2 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void sendImpression(@Nonnull ProjectConfig projectConfig,
@Nonnull Map<String, ?> filteredAttributes,
@Nonnull Variation variation,
@Nonnull String ruleType) {
sendImpression(projectConfig, experiment, userId, filteredAttributes, variation, "", ruleType);
sendImpression(projectConfig, experiment, userId, filteredAttributes, variation, "", ruleType, true);
}

/**
Expand All @@ -257,7 +257,8 @@ private void sendImpression(@Nonnull ProjectConfig projectConfig,
@Nonnull Map<String, ?> filteredAttributes,
@Nonnull Variation variation,
@Nonnull String flagKey,
@Nonnull String ruleType) {
@Nonnull String ruleType,
@Nonnull boolean enabled) {

UserEvent userEvent = UserEventFactory.createImpressionEvent(
projectConfig,
Expand All @@ -266,7 +267,8 @@ private void sendImpression(@Nonnull ProjectConfig projectConfig,
userId,
filteredAttributes,
flagKey,
ruleType);
ruleType,
enabled);

if (userEvent == null) {
return;
Expand Down Expand Up @@ -430,7 +432,8 @@ private Boolean isFeatureEnabled(@Nonnull ProjectConfig projectConfig,
copiedAttributes,
featureDecision.variation,
featureKey,
decisionSource.toString());
decisionSource.toString(),
featureEnabled);

if (featureDecision.variation != null) {
// This information is only necessary for feature tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public static ImpressionEvent createImpressionEvent(@Nonnull ProjectConfig proje
@Nonnull String userId,
@Nonnull Map<String, ?> attributes,
@Nonnull String flagKey,
@Nonnull String ruleType) {
@Nonnull String ruleType,
@Nonnull boolean enabled) {

if ((FeatureDecision.DecisionSource.ROLLOUT.toString().equals(ruleType) || variation == null) && !projectConfig.getSendFlagDecisions())
{
Expand Down Expand Up @@ -69,6 +70,7 @@ public static ImpressionEvent createImpressionEvent(@Nonnull ProjectConfig proje
.setRuleKey(experimentKey)
.setRuleType(ruleType)
.setVariationKey(variationKey)
.setEnabled(enabled)
.build();

return new ImpressionEvent.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ public class DecisionMetadata {
String ruleType;
@JsonProperty("variation_key")
String variationKey;
@JsonProperty("enabled")
boolean enabled;

@VisibleForTesting
public DecisionMetadata() {
}

public DecisionMetadata(String flagKey, String ruleKey, String ruleType, String variationKey) {
public DecisionMetadata(String flagKey, String ruleKey, String ruleType, String variationKey, boolean enabled) {
this.flagKey = flagKey;
this.ruleKey = ruleKey;
this.ruleType = ruleType;
this.variationKey = variationKey;
this.enabled = enabled;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add "getEnabled()"

Choose a reason for hiding this comment

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

why did we add it if it's not used?

}

public String getRuleType() {
Expand Down Expand Up @@ -67,6 +70,7 @@ public boolean equals(Object o) {
if (!ruleType.equals(that.ruleType)) return false;
if (!ruleKey.equals(that.ruleKey)) return false;
if (!flagKey.equals(that.flagKey)) return false;
if (enabled != that.enabled) return false;
return variationKey.equals(that.variationKey);
}

Expand All @@ -85,6 +89,12 @@ public static class Builder {
private String ruleKey;
private String flagKey;
private String variationKey;
private boolean enabled;

public Builder setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
}

public Builder setRuleType(String ruleType) {
this.ruleType = ruleType;
Expand All @@ -107,7 +117,7 @@ public Builder setVariationKey(String variationKey) {
}

public DecisionMetadata build() {
return new DecisionMetadata(flagKey, ruleKey, ruleType, variationKey);
return new DecisionMetadata(flagKey, ruleKey, ruleType, variationKey, enabled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void createImpressionEventPassingUserAgentAttribute() throws Exception {
Map<String, String> attributeMap = new HashMap<String, String>();
attributeMap.put(attribute.getKey(), "value");
attributeMap.put(ControlAttribute.USER_AGENT_ATTRIBUTE.toString(), "Chrome");
DecisionMetadata metadata = new DecisionMetadata(activatedExperiment.getKey(), activatedExperiment.getKey(), ruleType, "variationKey");
DecisionMetadata metadata = new DecisionMetadata(activatedExperiment.getKey(), activatedExperiment.getKey(), ruleType, "variationKey", true);
Decision expectedDecision = new Decision.Builder()
.setCampaignId(activatedExperiment.getLayerId())
.setExperimentId(activatedExperiment.getId())
Expand Down Expand Up @@ -1062,7 +1062,8 @@ public static LogEvent createImpressionEvent(ProjectConfig projectConfig,
userId,
attributes,
activatedExperiment.getKey(),
"experiment");
"experiment",
true);

return EventFactory.createLogEvent(userEvent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class UserEventFactoryTest {
public void setUp() {
experiment = new Experiment(EXPERIMENT_ID, EXPERIMENT_KEY, LAYER_ID);
variation = new Variation(VARIATION_ID, VARIATION_KEY);
decisionMetadata = new DecisionMetadata("", EXPERIMENT_KEY, "experiment", VARIATION_KEY);
decisionMetadata = new DecisionMetadata("", EXPERIMENT_KEY, "experiment", VARIATION_KEY, true);
}

@Test
Expand All @@ -80,7 +80,8 @@ public void createImpressionEventNull() {
USER_ID,
ATTRIBUTES,
EXPERIMENT_KEY,
"rollout"
"rollout",
false
);
assertNull(actual);
}
Expand All @@ -94,7 +95,8 @@ public void createImpressionEvent() {
USER_ID,
ATTRIBUTES,
"",
"experiment"
"experiment",
true
);

assertTrue(actual.getTimestamp() > 0);
Expand Down