-
Notifications
You must be signed in to change notification settings - Fork 971
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
Get final request url? #45
Comments
Sorta. The debug and trace logs will provide that information, but it may not be the easiest to work with in unit testing environments. For example, I'm using it in this test to determine if HTTP Basic Auth headers were being properly sent (since the client doesn't expose the raw headers being sent over the wire): That test is using a virtual filesystem to collect the logs, but now that I'm thinking about it, a Monolog handler that emits to stdout or similar may be a better option. Will have to think about that... Another possibility is adding a |
Thanks for the quick reply. |
So I'm on the road at the moment, but I'll investigate the options once I get home, and chat with the other client devs to see if there is a way we can standardize it across the clients. Will keep you posted. |
Hi, do you already have some news on this? |
At a high level, this commit allows the user to obtain info (URI, method, status, etc) of the last request. To accomplish this, a number of things had to change: - Transport visibility had to be increased to public - Transport needs to know which connection was last used - Connections need to save and return last request info Resolves #45
Mocking would be possible, with caveats. There is no way to inject a different Something like: public class MockConnection implements Elasticsearch\Connections\ConnectionInterface
{
public function __construct($hostDetails, $connectionParams, LoggerInterface $log, LoggerInterface $trace){}
public function getTransportSchema(){}
public function isAlive(){}
public function markAlive(){}
public function markDead(){}
public function getLastRequestInfo(){}
public function performRequest($method, $uri, $params = null, $body = null){}
}
$params['connectionClass'] = '\MyProject\MockConnection';
$client = new Elasticsearch\Client($params); The caveat is that each Connection class does a certain amount of processing internal to the class (e.g. pre-pending the connection schema, adding URI parameters, setting curl options, etc). So mocking out a connection class is a good way to unit-test the data that your app is providing to the library...but not a great way to integration test the whole system. Instead of implementing a complete mock connection, you could extend one of the existing connection classes and just call I went ahead and implemented the "getLastRequest" functionality, since it has several useful side effects (exposing transport, etc). The data is buried pretty deep inside the library (all the way down at the connection level), so it requires a fairly long/obnoxious API to surface the data. But for stuff like debugging/unit testing, I think that is ok. This won't be used often in "normal" code. $client = new Elasticsearch\Client();
$client->index(['index' => 'test', 'type' => 'test', 'id' => 1, 'body' => ['field' => 'value']]);
$last = $client->transport->getLastConnection()->getLastRequestInfo();
print_r($last);
|
Wow, super cool, works like a charm! |
fuck |
We are currently using cviebrock/laravel-elasticsearch. Because it presents a facade to the Elasticsearch client, it wasn't immediately obvious how @polyfractal's example should be translated to work within that environment. This thread shows up high in Google, so I'd like to share our solution:
Equivalent one-liner for debugging:
Hopefully this'll save some folks the |
Is this still a thing? |
Hi,
is there a way to retrieve the final url that is generated and used to query ES?
I think this can be very useful for unit testing and debugging.
Thanks
The text was updated successfully, but these errors were encountered: