-
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
Changes from all commits
e32e2b8
2b32343
ef92697
1332498
2617b03
5481ce4
45e7ed8
16b4f6d
6b9a7a6
8a0264f
ea3fa48
f4b577e
107e914
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* Copyright 2020, Optimizely | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Optimizely\Enums; | ||
|
||
class ExperimentAudienceEvaluationLogs extends CommonAudienceEvaluationLogs | ||
{ | ||
const AUDIENCE_EVALUATION_RESULT_COMBINED = "Audiences for experiment \"%s\" collectively evaluated to %s."; | ||
const EVALUATING_AUDIENCES_COMBINED = "Evaluating audiences for experiment \"%s\": %s."; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* Copyright 2020, Optimizely | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Optimizely\Enums; | ||
|
||
class RolloutAudienceEvaluationLogs extends CommonAudienceEvaluationLogs | ||
{ | ||
const AUDIENCE_EVALUATION_RESULT_COMBINED = "Audiences for rule %s collectively evaluated to %s."; | ||
const EVALUATING_AUDIENCES_COMBINED = "Evaluating audiences for rule %s: %s."; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -931,7 +931,7 @@ private function getFeatureVariableValueFromVariation($featureFlagKey, $variable | |
if ($variation === null) { | ||
$this->_logger->log( | ||
Logger::INFO, | ||
"User '{$userId}'is not in any variation, ". | ||
"User '{$userId}' is not in experiment or rollout, ". | ||
"returning default value '{$variableValue}'." | ||
); | ||
} else { | ||
|
@@ -941,21 +941,20 @@ private function getFeatureVariableValueFromVariation($featureFlagKey, $variable | |
$variableValue = $variableUsage->getValue(); | ||
$this->_logger->log( | ||
Logger::INFO, | ||
"Returning variable value '{$variableValue}' for variation '{$variation->getKey()}' ". | ||
"of feature flag '{$featureFlagKey}'" | ||
"Returning variable value '{$variableValue}' for variable key '{$variableKey}' ". | ||
"of feature flag '{$featureFlagKey}'." | ||
); | ||
} else { | ||
$this->_logger->log( | ||
Logger::INFO, | ||
"Variable '{$variableKey}' is not used in variation '{$variation->getKey()}', ". | ||
"returning default value '{$variableValue}'." | ||
"Variable value is not defined. Returning the default variable value '{$variableValue}'." | ||
); | ||
} | ||
} 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 commentThe 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 |
||
"Returning the default variable value '{$variableValue}'." | ||
); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
use Monolog\Logger; | ||
use Optimizely\Config\ProjectConfigInterface; | ||
use Optimizely\Entity\Experiment; | ||
use Optimizely\Enums\AudienceEvaluationLogs; | ||
use Optimizely\Logger\LoggerInterface; | ||
use Optimizely\Utils\ConditionTreeEvaluator; | ||
use Optimizely\Utils\CustomAttributeConditionEvaluator; | ||
|
@@ -133,30 +132,40 @@ public static function areEventTagsValid($eventTags) | |
|
||
/** | ||
* @param $config ProjectConfigInterface Configuration for the project. | ||
* @param $experiment Experiment Entity representing the experiment. | ||
* @param $experiment Experiment Entity representing the experiment or rollout rule. | ||
* @param $userAttributes array Attributes of the user. | ||
* @param $logger LoggerInterface. | ||
* @param $loggingClass String Class holding log strings with placeholders. | ||
* @param $loggingKey String Identifier of an experiment/rollout rule. | ||
* | ||
* @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, $loggingClass = null, $loggingKey = null) | ||
{ | ||
if ($loggingClass === null) { | ||
$loggingClass = 'Optimizely\Enums\ExperimentAudienceEvaluationLogs'; | ||
} | ||
|
||
if ($loggingKey === null) { | ||
$loggingKey = $experiment->getKey(); | ||
} | ||
Comment on lines
+145
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice !! |
||
|
||
$audienceConditions = $experiment->getAudienceConditions(); | ||
if ($audienceConditions === null) { | ||
$audienceConditions = $experiment->getAudienceIds(); | ||
} | ||
|
||
$logger->log(Logger::DEBUG, sprintf( | ||
AudienceEvaluationLogs::EVALUATING_AUDIENCES_COMBINED, | ||
$experiment->getKey(), | ||
$loggingClass::EVALUATING_AUDIENCES_COMBINED, | ||
$loggingKey, | ||
json_encode($audienceConditions) | ||
)); | ||
|
||
// Return true if experiment is not targeted to any audience. | ||
if (empty($audienceConditions)) { | ||
$logger->log(Logger::INFO, sprintf( | ||
AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT_COMBINED, | ||
$experiment->getKey(), | ||
$loggingClass::AUDIENCE_EVALUATION_RESULT_COMBINED, | ||
$loggingKey, | ||
'TRUE' | ||
)); | ||
return true; | ||
|
@@ -171,14 +180,14 @@ public static function isUserInExperiment($config, $experiment, $userAttributes, | |
return $customAttrCondEval->evaluate($leafCondition); | ||
}; | ||
|
||
$evaluateAudience = function ($audienceId) use ($config, $evaluateCustomAttr, $logger) { | ||
$evaluateAudience = function ($audienceId) use ($config, $evaluateCustomAttr, $logger, $loggingClass) { | ||
$audience = $config->getAudience($audienceId); | ||
if ($audience === null) { | ||
return null; | ||
} | ||
|
||
$logger->log(Logger::DEBUG, sprintf( | ||
AudienceEvaluationLogs::EVALUATING_AUDIENCE, | ||
$loggingClass::EVALUATING_AUDIENCE, | ||
$audienceId, | ||
json_encode($audience->getConditionsList()) | ||
)); | ||
|
@@ -188,7 +197,7 @@ public static function isUserInExperiment($config, $experiment, $userAttributes, | |
$resultStr = $result === null ? 'UNKNOWN' : strtoupper(var_export($result, true)); | ||
|
||
$logger->log(Logger::DEBUG, sprintf( | ||
AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT, | ||
$loggingClass::AUDIENCE_EVALUATION_RESULT, | ||
$audienceId, | ||
$resultStr | ||
)); | ||
|
@@ -201,8 +210,8 @@ public static function isUserInExperiment($config, $experiment, $userAttributes, | |
$evalResult = $evalResult || false; | ||
|
||
$logger->log(Logger::INFO, sprintf( | ||
AudienceEvaluationLogs::AUDIENCE_EVALUATION_RESULT_COMBINED, | ||
$experiment->getKey(), | ||
$loggingClass::AUDIENCE_EVALUATION_RESULT_COMBINED, | ||
$loggingKey, | ||
strtoupper(var_export($evalResult, true)) | ||
)); | ||
|
||
|
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.