Skip to content

Commit

Permalink
Merge pull request #3424 from rbayet/feat-switch-for-log-request-deta…
Browse files Browse the repository at this point in the history
…ils-when-error

[Core] Error request body logging tied to new setting
  • Loading branch information
rbayet authored Oct 27, 2024
2 parents 5d920ce + 4eccfa9 commit 528d00e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ interface ClientConfigurationInterface
*/
public function getServerList();

/**
* Indicates whether the body of requests in error should be logged or not.
*
* @return boolean
*/
public function isLoggingErrorRequest();

/**
* Indicates whether the debug node is enabled or not.
*
Expand Down
3 changes: 1 addition & 2 deletions src/module-elasticsuite-core/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ public function search($params)
try {
$response = $this->getEsClient()->search($params);
} catch (\Exception $e) {
// If debug is enabled, no need to log, the ES client would already have done it.
if (false === $this->clientConfiguration->isDebugModeEnabled()) {
if ($this->clientConfiguration->isLoggingErrorRequest()) {
$requestInfo = json_encode($params, JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE);
$this->logger->error(sprintf("Search Request Failure [error] : %s", $e->getMessage()));
$this->logger->error(sprintf("Search Request Failure [request] : %s", $requestInfo));
Expand Down
8 changes: 8 additions & 0 deletions src/module-elasticsuite-core/Client/ClientConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public function getServerList()
return explode(',', $this->getElasticsearchClientConfigParam('servers') ?? '');
}

/**
* {@inheritDoc}
*/
public function isLoggingErrorRequest()
{
return (bool) $this->getElasticsearchClientConfigParam('enable_error_request_logging');
}

/**
* {@inheritdoc}
*/
Expand Down
25 changes: 15 additions & 10 deletions src/module-elasticsuite-core/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,53 +30,58 @@

<group id="es_client" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Elasticsearch Client</label>
<field id="servers" translate="label comment" type="text" sortOrder="51" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="servers" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Elasticsearch Servers List</label>
<comment>List of servers in [host]:[port] format separated by a comma (e.g. : "es-node1.fqdn:9200, es-node2.fqdn:9200")</comment>
</field>
<field id="enable_https_mode" translate="label comment" type="select" sortOrder="52" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="enable_https_mode" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Use HTTPS</label>
<comment>Select yes if you want to connect to your Elasticsearch server over HTTPS.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_certificate_validation" translate="label comment" type="select" sortOrder="52" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="enable_certificate_validation" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Use SSL certificate Validation</label>
<comment>Select no if you are using opensearch.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_http_auth" translate="label comment" type="select" sortOrder="52" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="enable_http_auth" translate="label comment" type="select" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Enable basic HTTP authentication</label>
<comment>Enable this option when your Elasticsearch server use basic HTTP authentication.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_http_auth_encoding" translate="label comment" type="select" sortOrder="52" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="enable_http_auth_encoding" translate="label comment" type="select" sortOrder="50" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Encode HTTP authorization headers</label>
<comment>Enable this option when you want to base64 encode the Authorization headers. (Open Distro requires this)</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="http_auth_user" translate="label comment" type="text" sortOrder="53" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="http_auth_user" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Basic HTTP authentication user</label>
<depends>
<field id="enable_http_auth">1</field>
</depends>
</field>
<field id="http_auth_pwd" translate="label comment" type="text" sortOrder="54" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="http_auth_pwd" translate="label comment" type="text" sortOrder="61" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Basic HTTP authentication password</label>
<depends>
<field id="enable_http_auth">1</field>
</depends>
</field>
<field id="enable_debug_mode" translate="label comment" type="select" sortOrder="55" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="enable_error_request_logging" translate="label comment" type="select" sortOrder="70" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Enable logging of request that produce errors</label>
<comment><![CDATA[This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled.]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_debug_mode" translate="label comment" type="select" sortOrder="75" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Enable Debug Mode</label>
<comment>When enabled the module will produce logs through Magento logging system.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="connection_timeout" translate="label comment" type="text" sortOrder="56" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="connection_timeout" translate="label comment" type="text" sortOrder="80" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Server Connection Timeout</label>
<comment>In seconds.</comment>
<frontend_class>validate-number</frontend_class>
</field>
<field id="max_retries" translate="label comment" type="text" sortOrder="56" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<field id="max_retries" translate="label comment" type="text" sortOrder="90" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Elasticsearch Client Maximum Number of Retries</label>
<comment>Maximum number of times to retry connection when there is a connection failure</comment>
<frontend_class>validate-number</frontend_class>
Expand Down
1 change: 1 addition & 0 deletions src/module-elasticsuite-core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<default>
<smile_elasticsuite_core_base_settings>
<es_client>
<enable_error_request_logging>0</enable_error_request_logging>
<enable_debug_mode>0</enable_debug_mode>
<servers>localhost:9200</servers>
<connection_timeout>1</connection_timeout>
Expand Down
2 changes: 2 additions & 0 deletions src/module-elasticsuite-core/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ General,General
"Basic HTTP authentication password","Basic HTTP authentication password"
"Enable Debug Mode","Enable Debug Mode"
"When enabled the module will produce logs through Magento logging system.","When enabled the module will produce logs through Magento logging system."
"Enable logging of request that produce errors","Enable logging of request that produce errors"
"This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled.","This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled."
"Server Connection Timeout","Server Connection Timeout"
"In seconds.","In seconds."
"Indices Settings","Indices Settings"
Expand Down
2 changes: 2 additions & 0 deletions src/module-elasticsuite-core/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ General,Général
"Basic HTTP authentication password","Mot de passe pour l'authentification HTTP"
"Enable Debug Mode","Activer le mode debug"
"When enabled the module will produce logs through Magento logging system.","Lorsqu'activé, le module va produire des logs via le système de logs Magento standard."
"Enable logging of request that produce errors","Journaliser les requêtes en erreur"
"This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled.","Ceci est une alternative au mode debug pour les environnements de production. Lorsqu'activé, même si le mode debug est désactivé, le corps des requêtes en erreur sera loggé. Si désactivé, seul l'exception/le message d'erreur sera loggé (comportement historique). Un système de rotation des logs sur le fichier var/log/system.log est recommandé si activé."
"Server Connection Timeout","Délai de connexion au serveur"
"In seconds.","En secondes."
"Indices Settings","Paramètres des index"
Expand Down

0 comments on commit 528d00e

Please sign in to comment.