-
Notifications
You must be signed in to change notification settings - Fork 83
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
Conversation
ON_DECISION: 'ON_DECISION:type, user_id, attributes, decision_info', | ||
}; | ||
|
||
exports.ON_DECISION_NOTIFICATION_TYPES = { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) : ''; |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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) : ''; |
There was a problem hiding this comment.
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
@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' |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initial review
@aliabbasrizvi @jordangarcia @msohailhussain Closing this PR as this change has been split into PR #244 , #245 and #246 now. |
Summary
isfeatureEnabled
getEnabledFeatures
getFeatureVariableString
getFeatureVariableBoolean
getFeatureVariableInteger
getFeatureVariableDouble
Test plan