Skip to content

feat: added enabled field in metadata. #249

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 1 commit into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 17 additions & 8 deletions OptimizelySDK.Tests/EventTests/EventFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public void TestCreateImpressionEventNoAttributes()
{ "rule_type", "experiment" },
{ "rule_key", "test_experiment" },
{ "flag_key", "test_experiment" },
{ "variation_key", "control" }
{ "variation_key", "control" },
{"enabled", false }
} }
}
}
Expand Down Expand Up @@ -168,7 +169,9 @@ public void TestCreateImpressionEventWithAttributes()
{ "rule_type", "experiment" },
{ "rule_key", "test_experiment" },
{ "flag_key", "test_experiment" },
{ "variation_key", "control" }
{ "variation_key", "control" },
{"enabled", false }

}
}
}
Expand Down Expand Up @@ -268,7 +271,8 @@ public void TestCreateImpressionEventWithTypedAttributes()
{ "rule_type", "experiment" },
{ "rule_key", "test_experiment" },
{ "flag_key", "test_experiment" },
{ "variation_key", "control" }
{ "variation_key", "control" },
{"enabled", false }
}
}
}
Expand Down Expand Up @@ -390,7 +394,8 @@ public void TestCreateImpressionEventRemovesInvalidAttributesFromPayload()
{ "rule_type", "experiment" },
{ "rule_key", "test_experiment" },
{ "flag_key", "test_experiment" },
{ "variation_key", "control" }
{ "variation_key", "control" },
{"enabled", false }
}
}
}
Expand Down Expand Up @@ -512,7 +517,8 @@ public void TestCreateImpressionEventRemovesInvalidAttributesFromPayloadRollout(
{ "rule_type", "rollout" },
{ "rule_key", "" },
{ "flag_key", "test_feature" },
{ "variation_key", "" }
{ "variation_key", "" },
{ "enabled", false }
}
}
}
Expand Down Expand Up @@ -1526,7 +1532,8 @@ public void TestCreateImpressionEventWithBucketingIDAttribute()
{ "rule_type", "experiment" },
{ "rule_key", "test_experiment" },
{ "flag_key", "test_experiment" },
{ "variation_key", "control" }
{ "variation_key", "control" },
{"enabled", false }
}
}
}
Expand Down Expand Up @@ -1633,7 +1640,8 @@ public void TestCreateImpressionEventWhenBotFilteringIsProvidedInDatafile()
{ "rule_type", "experiment" },
{ "rule_key", "test_experiment" },
{ "flag_key", "test_experiment" },
{ "variation_key", "control" }
{ "variation_key", "control" },
{"enabled", false }
}
}
}
Expand Down Expand Up @@ -1736,7 +1744,8 @@ public void TestCreateImpressionEventWhenBotFilteringIsNotProvidedInDatafile()
{ "rule_type", "experiment" },
{ "rule_key", "test_experiment" },
{ "flag_key", "test_experiment" },
{ "variation_key", "control" }
{ "variation_key", "control" },
{"enabled", false }
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion OptimizelySDK/Event/Entity/DecisionMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ public class DecisionMetadata
public string RuleType { get; private set; }
[JsonProperty("variation_key")]
public string VariationKey { get; private set; }
[JsonProperty("enabled")]
public bool Enabled { get; private set; }

public DecisionMetadata(string flagKey, string ruleKey, string ruleType, string variationKey = "")
public DecisionMetadata(string flagKey, string ruleKey, string ruleType, string variationKey = "", bool enabled = false)
{
FlagKey = flagKey;
RuleKey = ruleKey;
RuleType = ruleType;
VariationKey = variationKey;
Enabled = enabled;
}
}
}
10 changes: 6 additions & 4 deletions OptimizelySDK/Event/UserEventFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public static ImpressionEvent CreateImpressionEvent(ProjectConfig projectConfig,
string userId,
UserAttributes userAttributes,
string flagKey,
string ruleType)
string ruleType,
bool enabled = false)
{
Variation variation = projectConfig.GetVariationFromId(activatedExperiment?.Key, variationId);
return CreateImpressionEvent(projectConfig, activatedExperiment, variation, userId, userAttributes, flagKey, ruleType);
return CreateImpressionEvent(projectConfig, activatedExperiment, variation, userId, userAttributes, flagKey, ruleType, enabled);
}

/// <summary>
Expand All @@ -63,7 +64,8 @@ public static ImpressionEvent CreateImpressionEvent(ProjectConfig projectConfig,
string userId,
UserAttributes userAttributes,
string flagKey,
string ruleType)
string ruleType,
bool enabled = false)
{
if ((ruleType == FeatureDecision.DECISION_SOURCE_ROLLOUT || variation == null) && !projectConfig.SendFlagDecisions)
{
Expand All @@ -84,7 +86,7 @@ public static ImpressionEvent CreateImpressionEvent(ProjectConfig projectConfig,
variationKey = variation.Key;
ruleKey = activatedExperiment.Key;
}
var metadata = new DecisionMetadata(flagKey, ruleKey, ruleType, variationKey);
var metadata = new DecisionMetadata(flagKey, ruleKey, ruleType, variationKey, enabled);

return new ImpressionEvent.Builder()
.WithEventContext(eventContext)
Expand Down
13 changes: 7 additions & 6 deletions OptimizelySDK/Optimizely.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public Variation Activate(string experimentKey, string userId, UserAttributes us
return null;
}

SendImpressionEvent(experiment, variation, userId, userAttributes, config, SOURCE_TYPE_EXPERIMENT);
SendImpressionEvent(experiment, variation, userId, userAttributes, config, SOURCE_TYPE_EXPERIMENT, true);

return variation;
}
Expand Down Expand Up @@ -475,7 +475,6 @@ public virtual bool IsFeatureEnabled(string featureKey, string userId, UserAttri
var variation = decision.Variation;
var decisionSource = decision?.Source ?? FeatureDecision.DECISION_SOURCE_ROLLOUT;

SendImpressionEvent(decision.Experiment, variation, userId, userAttributes, config, featureKey, decisionSource);

if (variation != null)
{
Expand Down Expand Up @@ -507,6 +506,8 @@ public virtual bool IsFeatureEnabled(string featureKey, string userId, UserAttri
{ "sourceInfo", sourceInfo },
};

SendImpressionEvent(decision.Experiment, variation, userId, userAttributes, config, featureKey, decisionSource, featureEnabled);

NotificationCenter.SendNotifications(NotificationCenter.NotificationType.Decision, DecisionNotificationTypes.FEATURE, userId,
userAttributes ?? new UserAttributes(), decisionInfo);
return featureEnabled;
Expand Down Expand Up @@ -692,9 +693,9 @@ public OptimizelyJSON GetFeatureVariableJSON(string featureKey, string variableK
/// <param name="ruleType">It can either be experiment in case impression event is sent from activate or it's feature-test or rollout</param>
private void SendImpressionEvent(Experiment experiment, Variation variation, string userId,
UserAttributes userAttributes, ProjectConfig config,
string ruleType)
string ruleType, bool enabled)
{
SendImpressionEvent(experiment, variation, userId, userAttributes, config, "", ruleType);
SendImpressionEvent(experiment, variation, userId, userAttributes, config, "", ruleType, enabled);
}

/// <summary>
Expand All @@ -708,14 +709,14 @@ private void SendImpressionEvent(Experiment experiment, Variation variation, str
/// <param name="ruleType">It can either be experiment in case impression event is sent from activate or it's feature-test or rollout</param>
private void SendImpressionEvent(Experiment experiment, Variation variation, string userId,
UserAttributes userAttributes, ProjectConfig config,
string flagKey, string ruleType)
string flagKey, string ruleType, bool enabled)
{
if (experiment != null && !experiment.IsExperimentRunning)
{
Logger.Log(LogLevel.ERROR, @"Experiment has ""Launched"" status so not dispatching event during activation.");
}

var userEvent = UserEventFactory.CreateImpressionEvent(config, experiment, variation, userId, userAttributes, flagKey, ruleType);
var userEvent = UserEventFactory.CreateImpressionEvent(config, experiment, variation, userId, userAttributes, flagKey, ruleType, enabled);
if (userEvent == null)
{
return;
Expand Down