-
Notifications
You must be signed in to change notification settings - Fork 30
fix(logs): Fixing log messages #201
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
$this->_logger->log( | ||
Logger::DEBUG, | ||
sprintf("User '%s' did not meet the audience conditions to be in rollout rule '%s'.", $userId, $experiment->getKey()) | ||
sprintf("User '%s' does not meet conditions for targeting rule %s.", $userId, $i+1) |
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.
nit. $i + 1
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.
This comment is still not addressed.
src/Optimizely/Utils/Validator.php
Outdated
* | ||
* @return boolean Representing whether user meets audience conditions to be in experiment or not. | ||
*/ | ||
public static function isUserInExperiment($config, $experiment, $userAttributes, $logger) | ||
public static function isUserInExperiment($config, $experiment, $userAttributes, $logger, $isRollout = null, $rolloutRule = null) |
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.
This method name needs to be updated. It should be called doesUserMeetAudienceConditions
.
const AUDIENCE_EVALUATION_RESULT_COMBINED = "Audiences for %s collectively evaluated to %s."; | ||
const EVALUATING_AUDIENCES_COMBINED = "Evaluating audiences for %s: %s."; |
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'd prefer if we break out the log messages just so that we have greater control for later changes.
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.
Almost there.
src/Optimizely/Utils/Validator.php
Outdated
* | ||
* @return boolean Representing whether user meets audience conditions to be in experiment or not. | ||
*/ | ||
public static function isUserInExperiment($config, $experiment, $userAttributes, $logger) | ||
public static function doesUserMeetAudienceConditions($config, $experiment, $userAttributes, $logger, $isRollout = null, $rolloutRule = null) |
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.
Instead of passing isRollout
, you can just pass the loggingClass
.
src/Optimizely/Utils/Validator.php
Outdated
@@ -136,27 +137,37 @@ public static function areEventTagsValid($eventTags) | |||
* @param $experiment Experiment Entity representing the 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.
representing the experiment or rollout rule
src/Optimizely/Utils/Validator.php
Outdated
@@ -136,27 +137,37 @@ public static function areEventTagsValid($eventTags) | |||
* @param $experiment Experiment Entity representing the experiment. | |||
* @param $userAttributes array Attributes of the user. | |||
* @param $logger LoggerInterface. | |||
* @param $isRollout Boolean true if experiment to evaluate is a rollout rule. | |||
* @param $rolloutRule String Rollout rule identifier to log. |
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.
You can just pass in the experiment key or rule index and just log that here.
@aliabbasrizvi Assuming experiment class and experiment key by default to avoid unnecessarily modifying many unit tests. Since, this is an internal method, shouldn't make a difference. Let me know if you would like me to explicitly pass arguments when evaluating 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.
Mostly looks good. Some small changes needed.
$this->_logger->log( | ||
Logger::DEBUG, | ||
sprintf("User '%s' did not meet the audience conditions to be in rollout rule '%s'.", $userId, $experiment->getKey()) | ||
sprintf("User '%s' does not meet conditions for targeting rule %s.", $userId, $i+1) |
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.
This comment is still not addressed.
} | ||
break; | ||
} | ||
// Evaluate Everyone Else Rule / Last Rule now | ||
$experiment = $rolloutRules[sizeof($rolloutRules)-1]; | ||
$rolloutRule = $rolloutRules[sizeof($rolloutRules)-1]; |
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.
Is it conventional to not have spacing around operators?
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.
Not something enforced. Subjective
if ($loggingClass === null) { | ||
$loggingClass = 'Optimizely\Enums\ExperimentAudienceEvaluationLogs'; | ||
} | ||
|
||
if ($loggingKey === null) { | ||
$loggingKey = $experiment->getKey(); | ||
} |
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.
Nice !!
tests/UtilsTests/ValidatorTest.php
Outdated
@@ -188,7 +188,7 @@ public function testAreEventTagsValidInvalidEventTags() | |||
} | |||
|
|||
// test that Audience evaluation proceeds if provided attributes are empty or null. | |||
public function testIsUserInExperimentAudienceUsedInExperimentNoAttributesProvided() | |||
public function testdoesUserMeetAudienceConditionsAudienceUsedInExperimentNoAttributesProvided() |
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.
nit. Does and not does.
tests/UtilsTests/ValidatorTest.php
Outdated
// test that isUserInExperiment returns true when no audience is attached to experiment. | ||
public function testIsUserInExperimentNoAudienceUsedInExperiment() | ||
// test that doesUserMeetAudienceConditions returns true when no audience is attached to experiment. | ||
public function testdoesUserMeetAudienceConditionsNoAudienceUsedInExperiment() |
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 comment as 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.
You probably need to update this in all the tests.
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 more comments around variable logging.
@@ -954,8 +954,8 @@ private function getFeatureVariableValueFromVariation($featureFlagKey, $variable | |||
} else { | |||
$this->_logger->log( | |||
Logger::INFO, | |||
"Feature '{$featureFlagKey}' for variation '{$variation->getKey()}' is not enabled, ". | |||
"returning default value '{$variableValue}'." | |||
"Feature '{$featureFlagKey}' is not enabled for user '{$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.
You need to fix the messaging on line 934, 944, 949 as well. They all talk about variations.
On line 934, change to User '{$userId}'is not in experiment or rollout, returning default value '{$variableValue}'
On line 944, change to Returning variable value '{$variableValue}' for variable key <get variable key here> of feature flag {$featureFlagKey}
On line 949, change to `Variable value is not defined. Returning the default variable value '{$variableValue}'"
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.
LGTM
Summary
Test plan