-
Notifications
You must be signed in to change notification settings - Fork 973
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
Enable the Client to keep requests #864
Conversation
@egodsk thanks for the PR, I see your point but actually you can read all the HTTP requests and responses made by the client using the Logger feature. You can use the information stored by the logger for monitoring/debugging your application, this is the main reason for logging. |
Hi @ezimuel. Thank you for your reply. I see your thinking with the logger, however the problem I see with only using the logger is that, the information that is printing and the way that it is printed, is determined by the way that it is hardcoded in the library. Ex. when a request is made it will write the following to the logger: I'm aware that the I'm open to suggestion in ways other then introducing an array for keeping the requests, as to how, one would be able to easily retrieve and work on the requests made, but I'm unaware of other ways to do it? If you can suggest another approach, I will happily try and make a new PR with the suggestion :). Regards, |
Few things:
$params = [
// all the normal request details here
];
// toggle verbosity
$params['client']['verbose'] = true;
$response = $client->search($params);
print_r($response); [...,
'transfer_stats' => [
'url' => '...',
'content_type' => 'application/json; charset=UTF-8',
'http_code' => 200,
'header_size' => 144,
'request_size' => 419,
'filetime' => -1,
'ssl_verify_result' => 0,
'redirect_count' => 0,
'total_time' => 60.845132,
'namelookup_time' => 0.0013470000000000001,
'connect_time' => 0.029269,
'pretransfer_time' => 0.16522499999999996,
'size_upload' => 0.0,
'size_download' => 0.0,
'speed_download' => 0.0,
'speed_upload' => 0.0,
'download_content_length' => 1907.0,
'upload_content_length' => 0.0,
'starttransfer_time' => 60.845117999999999,
'redirect_time' => 0.0,
'redirect_url' => '',
'primary_ip' => 'XXXXXXX',
'certinfo' => [],
],
...
]
Just throwing out some other options, not saying we do/don't want some kind of more robust tracking in the client. I'll leave that to @ezimuel :) |
@egodsk I agree with @polyfractal we have already different ways to debug the HTTP request/response for this library. I continue to see the logging the best way to go. The question become if we can facilitate the customization of the logging format, as you pointed out. Right now, the logging is provided using the functions:
These functions have a lot of parameters, maybe we can simplify it using just use Elasticsearch\ClientBuilder;
use Elasticsearch\Connections\Connection;
use Elasticsearch\Connections\ConnectionFactory;
class MyConnection extends Connection
{
public function logRequestSuccess($request, $response, $exception) {
// custom log
}
}
class MyConnectionFactoy extends ConnectionFactory
{
public function create($hostDetails) {
return new MyConnection(
$this->handler,
$hostDetails,
$this->connectionParams,
$this->serializer,
$this->logger,
$this->tracer
);
}
}
$client = ClientBuilder::fromConfig([
'ConnectionFactory' => MyConnectionFactory::class
]); We can definitely work to simplify the customization of the logging messages in the future, maybe using some interface or callable for |
Hi @ezimuel and @polyfractal. Thank you for your feedback. You all make some great points. I'm going to close this pull request and start a little on the work in the direction suggested by @ezimuel , by starting to simply the logRequest and see, if it can be easily later be customized. |
Currently the Client only saves the latest request made using the Client, but if you are interested in seeing all the requests made by the client in its lifetime, there is no real way of getting this data, without enabling the logger, which logs the requests and responses in the way that this library has specified.
With this Pull-Request, you can enable the client to keep an array of requests made using the Client. This will be useful for debugging and testing purposes mainly, or for profiling purposes.
Please let me know what you think about this :)
Feel free to comment, review and edit if needed.
Regards,
Emil G.