Skip to content

feat(api): OnDecision Notification Listener #240

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

Closed
wants to merge 10 commits into from

Conversation

mfahadahmed
Copy link
Contributor

Summary

  • Implemented onDecisionListener in following APIs:
    isfeatureEnabled
    getEnabledFeatures
    getFeatureVariableString
    getFeatureVariableBoolean
    getFeatureVariableInteger
    getFeatureVariableDouble

Test plan

  • Unit testss for OnDecisionListener

@mfahadahmed mfahadahmed added the WIP label Mar 6, 2019
@mfahadahmed mfahadahmed changed the title Fahad/on decision listener feat(api): OnDecision Notification Listener Mar 6, 2019
ON_DECISION: 'ON_DECISION:type, user_id, attributes, decision_info',
};

exports.ON_DECISION_NOTIFICATION_TYPES = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets call this DECISION_INFO_TYPES

They aren't really NOTIFICATION_TYPES like the ones above.

Copy link
Contributor

@jordangarcia jordangarcia left a comment

Choose a reason for hiding this comment

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

Some changes for the structure of the decisionInfo.

I also echo'd these changes in the design document.

After these changes have been implemented I will review this PR again in more detail.

enums.NOTIFICATION_TYPES.ON_DECISION,
{
type: ON_DECISION_NOTIFICATION_TYPES.EXPERIMENT_VARIATION,
user_id: userId,
Copy link
Contributor

Choose a reason for hiding this comment

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

lets use camelCase property names to be consistent with other notification events.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we are using camelCase, then it must be reflected here as well for Activate, Track and ON_DECISION/Decision
https://github.com/optimizely/javascript-sdk/pull/240/files#diff-79c0858a5dc2611f6570afc1265258daR179

}

var decisionSource = decision.decisionSource || DECISION_SOURCES.ROLLOUT;
decisionSource += decisionSource === DECISION_SOURCES.EXPERIMENT ? sprintf(' {%s}', decision.experiment.key) : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets keep this the same as decision.decisionSource and add a new field to decision_info

      {
        type: ON_DECISION_NOTIFICATION_TYPES.FEATURE,
        user_id: userId,
        attributes: attributes,
        decisionInfo: {
          featureKey: featureKey,
          featureEnabled: featureEnabled,
          source: 'ROLLOUT',
          experimentKey: null,
        }

and

      {
        type: ON_DECISION_NOTIFICATION_TYPES.FEATURE,
        user_id: userId,
        attributes: attributes,
        decisionInfo: {
          featureKey: featureKey,
          featureEnabled: featureEnabled,
          source: 'EXPERIMENT',
          experimentKey: 'feature_exp_key',
        }

var decisionSource = decision.decisionSource || DECISION_SOURCES.ROLLOUT;
decisionSource += decisionSource === DECISION_SOURCES.EXPERIMENT ? sprintf(' {%s}', decision.experiment.key) : '';

console.log(sprintf('Feature: %s - Enabled: %s, Source: %s', featureKey, featureEnabled, decisionSource))
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this console log.

this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.USER_RECEIVED_VARIABLE_VALUE, MODULE_NAME, variableKey, featureFlag.key, variableValue, userId));
} else {
variableValue = variable.defaultValue;
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.USER_RECEIVED_DEFAULT_VARIABLE_VALUE, MODULE_NAME, userId, variableKey, featureFlag.key));
}

return projectConfig.getTypeCastValue(variableValue, variableType, this.logger);
var decisionSource = decision.decisionSource || DECISION_SOURCES.ROLLOUT;
decisionSource += decisionSource === DECISION_SOURCES.EXPERIMENT ? sprintf(' {%s}', decision.experiment.key) : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing as above. Let's keep decisionSource unmodified and add experimentKey to decisionInfo

@coveralls
Copy link

coveralls commented Mar 7, 2019

Coverage Status

Coverage increased (+0.08%) to 97.729% when pulling e61fb00 on fahad/on-decision-listener into 34ecdcc on master.

@aliabbasrizvi
Copy link
Contributor

@mfahadahmed I am going to request you to break this change into 2 separate PRs at least. One for feature enabled and one for feature variable. It will make reviewing go faster.

@@ -729,22 +729,22 @@ describe('lib/core/decision_service', function() {
'variables': [
{
'id': '4792309476491264',
'value': '10'
'value': '40'
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are making any change in the existing datafile, please add comments in the PR, why we changed it. Otherwise difficult for reviewers

Copy link
Contributor

Choose a reason for hiding this comment

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

same for all where you changed true, Buy me Later

@@ -34,6 +34,7 @@ var LOG_MESSAGES = enums.LOG_MESSAGES;
var MODULE_NAME = 'OPTIMIZELY';
var DECISION_SOURCES = enums.DECISION_SOURCES;
var FEATURE_VARIABLE_TYPES = enums.FEATURE_VARIABLE_TYPES;
var DECISION_INFO_TYPES = enums.DECISION_INFO_TYPES;
Copy link
Contributor

Choose a reason for hiding this comment

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

@jordangarcia shouldn't it be DECISION_TYPES?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think DECISION_INFO_TYPES is fine. It was confusing before when it was DECISION_NOTIFICATION_TYPES

};

exports.DECISION_INFO_TYPES = {
EXPERIMENT_VARIATION: 'experiment_variation',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why it's experiment_variation? It should be experiment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind checking with @aliabbasrizvi on whether this should be experiment_variation or experiment .

Right now it's still experiment_variation in the design doc

Copy link
Contributor

Choose a reason for hiding this comment

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

In th example, experiment was used. Added comment in the doc.

@@ -177,6 +178,13 @@ exports.NODE_CLIENT_VERSION = '3.0.1';
exports.NOTIFICATION_TYPES = {
ACTIVATE: 'ACTIVATE:experiment, user_id,attributes, variation, event',
TRACK: 'TRACK:event_key, user_id, attributes, event_tags, event',
ON_DECISION: 'ON_DECISION:type, user_id, attributes, decision_info',
Copy link
Contributor

Choose a reason for hiding this comment

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

It's been rename to Decision?

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think this change has been finalized. I'd keep it how it is today for consistency with the other NOTIFICATION_TYPES

this.notificationCenter.sendNotifications(
enums.NOTIFICATION_TYPES.ON_DECISION,
{
type: DECISION_INFO_TYPES.EXPERIMENT_VARIATION,
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no type EXPERIMENT_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 believe @aliabbasrizvi changed this to be just EXPERIMENT in the design doc

enums.NOTIFICATION_TYPES.ON_DECISION,
{
type: ON_DECISION_NOTIFICATION_TYPES.EXPERIMENT_VARIATION,
user_id: userId,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are using camelCase, then it must be reflected here as well for Activate, Track and ON_DECISION/Decision
https://github.com/optimizely/javascript-sdk/pull/240/files#diff-79c0858a5dc2611f6570afc1265258daR179

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.

initial review

@mfahadahmed
Copy link
Contributor Author

@aliabbasrizvi @jordangarcia @msohailhussain Closing this PR as this change has been split into PR #244 , #245 and #246 now.

@mfahadahmed mfahadahmed closed this Mar 8, 2019
@mfahadahmed mfahadahmed deleted the fahad/on-decision-listener branch May 9, 2019 11:49
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.

5 participants