Skip to content

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

Merged
merged 13 commits into from
Jul 21, 2020
Merged

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented Jun 24, 2020

Summary

  • This PR modifies log messages to be explicit when it's evaluating an experiment and when it's doing so for a Rollout.

Test plan

  • Added additional unit test to assert audience logs for rollouts.
  • Existing tests should continue to pass.

@oakbani oakbani requested a review from a team as a code owner June 24, 2020 07:14
@oakbani oakbani removed their assignment Jun 24, 2020
@oakbani oakbani requested a review from aliabbasrizvi June 24, 2020 07:15
@coveralls
Copy link

coveralls commented Jun 24, 2020

Coverage Status

Coverage increased (+0.04%) to 98.256% when pulling 107e914 on oakbani/fix-targeted-rollouts-log into 3f53ed9 on master.

$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)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. $i + 1

Copy link
Contributor

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.

*
* @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)
Copy link
Contributor

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.

Comment on lines 23 to 24
const AUDIENCE_EVALUATION_RESULT_COMBINED = "Audiences for %s collectively evaluated to %s.";
const EVALUATING_AUDIENCES_COMBINED = "Evaluating audiences for %s: %s.";
Copy link
Contributor

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.

@oakbani oakbani requested a review from aliabbasrizvi June 30, 2020 14:11
@oakbani oakbani removed their assignment Jun 30, 2020
Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

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

Almost there.

*
* @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)
Copy link
Contributor

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.

@@ -136,27 +137,37 @@ public static function areEventTagsValid($eventTags)
* @param $experiment Experiment Entity representing the experiment.
Copy link
Contributor

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

@@ -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.
Copy link
Contributor

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.

@oakbani
Copy link
Contributor Author

oakbani commented Jul 1, 2020

@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.

@oakbani oakbani removed their assignment Jul 1, 2020
@oakbani oakbani changed the title fix(logs): Fixing log messages for Targeted Rollouts fix(logs): Fixing log messages Jul 8, 2020
Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a 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)
Copy link
Contributor

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];
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not something enforced. Subjective

Comment on lines +145 to +151
if ($loggingClass === null) {
$loggingClass = 'Optimizely\Enums\ExperimentAudienceEvaluationLogs';
}

if ($loggingKey === null) {
$loggingKey = $experiment->getKey();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice !!

@@ -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()
Copy link
Contributor

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.

// 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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above

Copy link
Contributor

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.

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a 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}'. ".
Copy link
Contributor

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}'"

@oakbani oakbani requested a review from aliabbasrizvi July 10, 2020 07:19
@oakbani oakbani removed their assignment Jul 10, 2020
Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

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

LGTM

@aliabbasrizvi aliabbasrizvi merged commit efa480f into master Jul 21, 2020
@aliabbasrizvi aliabbasrizvi deleted the oakbani/fix-targeted-rollouts-log branch July 21, 2020 01:09
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.

4 participants