You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Delete a post, triggering immediate deletion request to ES (this does not go through the ES bulk request queue) - triggers false positive error PHP Warning: Error in ElasticSearch request: (0) in /usr/src/app/vendor/altis/cloud/inc/namespace.php on line 379 with no debug data. In this case should probably trigger a warning that the request is non blocking, thus response cannot be inspected for errors
Send a large request which triggers split_large_ep_request, this will bypass request logging due to direct use of wp_remote_request. Logging requests on a lower level should solve this: see example below
add_action( 'http_api_debug', __NAMESPACE__ . '\\enhanced_es_debug', 10, 5 );
/**
* Do an error log of failed ES requests
* Lower level than inbuilt altis one, as it is able to catch any request made to ES via wp_remote_{x}
*
* @param array|WP_Error $response
* @param string $context
* @param string $class
* @param array $parsed_args
* @param string $url
* @return void
*/
function enhanced_es_debug( $response, $context, $class, $parsed_args, $url ) {
if ( $context !== 'response' ) {
return;
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
$host = parse_url( $url, PHP_URL_HOST );
if ( ELASTICSEARCH_HOST !== $host ) {
return;
}
$request_response_body = wp_remote_retrieve_body( $response );
$request_response_code = (int) wp_remote_retrieve_response_code( $response );
$is_valid_res = ( $request_response_code >= 200 && $request_response_code <= 299 );
$type = $parsed_args['method'] ?? 'GET?';
// Backup check for errors, sometimes the response is ok but the query
// response JSON contains errors.
$has_errors = strpos( $request_response_body, '"errors":true' ) !== false;
if ( is_wp_error( $response ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
trigger_error( sprintf( 'RBMH Error in ElasticPress request: WP_Error %s %s (%s) %s', $type, $response->get_error_message(), $response->get_error_code(), $url ), E_USER_WARNING );
} elseif ( ! $is_valid_res || $has_errors ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
trigger_error( sprintf( 'RBMH Error in ElasticPress request: %s %s (%s) %s', $type, $request_response_body, $request_response_code, $url ), E_USER_WARNING );
}
}
The text was updated successfully, but these errors were encountered:
Hi Micheal
The error log you are seeing there is a false positive, the request being
sent is a DELETE call which isn't waiting on a response from the
elasticsearch server, and because it doesn't wait for a response, the error
logging code in altis assumes that no response means something went wrong
If you're debugging an issue, it's probably unrelated to this error log
If you want to stop this error from appearing in your logs, ideally the
issue gets patched in altis, otherwise I think you could unhook
(remove_action) the existing altis logging function and replace it with the
one I added here. Let me know if you need help with that
Steps to reproduce:
Delete a post, triggering immediate deletion request to ES (this does not go through the ES bulk request queue) - triggers false positive error
PHP Warning: Error in ElasticSearch request: (0) in /usr/src/app/vendor/altis/cloud/inc/namespace.php on line 379
with no debug data. In this case should probably trigger a warning that the request is non blocking, thus response cannot be inspected for errorsSend a large request which triggers split_large_ep_request, this will bypass request logging due to direct use of wp_remote_request. Logging requests on a lower level should solve this: see example below
The text was updated successfully, but these errors were encountered: