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(flag-decisions): Add support for sending flag decisions along with decision metadata. #405

Merged
merged 8 commits into from
Oct 23, 2020

Conversation

mnoman09
Copy link
Contributor

@mnoman09 mnoman09 commented Oct 1, 2020

Summary

  • Add experiment/feature flag key, variation key and type to impression events.
  • Send events for ALL decision types.
  • Add Metadata field to EventBatch.Decisions to capture flag type, key and variation key.

Test plan

  • All FSC and unit tests should pass

@coveralls
Copy link

coveralls commented Oct 1, 2020

Pull Request Test Coverage Report for Build 1580

  • 91 of 98 (92.86%) changed or added relevant lines in 11 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 89.735%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core-api/src/main/java/com/optimizely/ab/Optimizely.java 10 11 90.91%
core-api/src/main/java/com/optimizely/ab/event/internal/payload/Decision.java 6 7 85.71%
core-api/src/main/java/com/optimizely/ab/event/internal/payload/DecisionMetadata.java 29 34 85.29%
Files with Coverage Reduction New Missed Lines %
core-api/src/main/java/com/optimizely/ab/event/internal/UserEventFactory.java 1 97.92%
Totals Coverage Status
Change from base Build 1565: 0.03%
Covered Lines: 4126
Relevant Lines: 4598

💛 - Coveralls

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

please address.

@@ -216,7 +216,7 @@ private Variation activate(@Nullable ProjectConfig projectConfig,
return null;
}

sendImpression(projectConfig, experiment, userId, copiedAttributes, variation);
sendImpression(projectConfig, experiment, userId, copiedAttributes, variation, experiment.getKey(), "experiment");
Copy link
Contributor

Choose a reason for hiding this comment

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

please make experiment const or enum

logger.info("Experiment has \"Launched\" status so not dispatching event during activation.");
return;
}
@Nonnull Variation variation,
Copy link
Contributor

Choose a reason for hiding this comment

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

I will appreciate if you can add header doc because of no. of args.

return;
}
@Nonnull Variation variation,
@Nonnull String flagKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

it should be featureFlagKey or featureKey

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are calling it flagKey and flagType in all other sdks. So should I change it in java-sdk?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like flagKey which we use in Decide-API

}
@Nonnull Variation variation,
@Nonnull String flagKey,
@Nonnull String flagType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be featureSource,

@@ -386,16 +390,22 @@ private Boolean isFeatureEnabled(@Nonnull ProjectConfig projectConfig,
FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, userId, copiedAttributes, projectConfig);
Boolean featureEnabled = false;
SourceInfo sourceInfo = new RolloutSourceInfo();
if (featureDecision.decisionSource != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

in which case, decisionSource can be 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.

when experiment and variation is null.
the cases are

  1. When The feature flag is not used in a rollout
  2. The rollout with id was not found in the datafile for feature flag

added documentation of sendImpression
Copy link

@yasirfolio3 yasirfolio3 left a comment

Choose a reason for hiding this comment

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

Can we have a test checking if impression event's meta data has null variationKey when variation is null.

String layerID = null;
String experimentId = null;
String experimentKey = null;
if (activatedExperiment != null) {

Choose a reason for hiding this comment

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

This check for experiment shouldn't be required since it is already checked by the caller?

Copy link

@pawels-optimizely pawels-optimizely left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

lgtm

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 it looks good. Need some changes in tests and comments.

return;
}
@Nonnull Variation variation,
@Nonnull String flagKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

I like flagKey which we use in Decide-API

core-api/src/main/java/com/optimizely/ab/Optimizely.java Outdated Show resolved Hide resolved
Variation variation = optimizely.activate(launchedExperiment.getKey(), testUserId);
assertNotNull(variation);
assertThat(variation.getKey(), is(expectedVariation.getKey()));
eventHandler.expectImpression(launchedExperiment.getId(), expectedVariation.getId(), testUserId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if I miss it, but I do not see validation of new metadata in expected events.

Updated userEventFactory create impression test to avoid sending experiment key as flag key in case of ruletype experiment
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

@pawels-optimizely pawels-optimizely merged commit dcbf9b0 into master Oct 23, 2020
@pawels-optimizely pawels-optimizely deleted the mnoman/DecisionFlag branch October 23, 2020 17:46
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.

7 participants