Problem/Motivation
My site's environment has a proxy that routes all traffic towards a forward proxy, and further to the internet.
However, when connecting to Elasticsearch, I do not want to route the traffic outside the network, because the Drupal and Elasticsearch servers are hosted on different servers on the same subnet.
Currently, the elasticsearch_connector module is unable to reach the Elasticsearch server to proxy settings.
From the console on the Drupal server, if I run curl --noproxy '*' http://es-search.dev.org.local:9200/, then I can see the cluster information printed to the console. However if i omit the --noproxy option (i.e.: curl http://es-search.dev.org.local:9200/ then curl can't connect.
How can I tell elasticsearch connector to connect to the elasticsearch using no_proxyalues?
Elasticsearch connector should be able to use Drupal's existing HTTP proxy settings to handle this situation.
The elasticsearch/elasticsearch library has a ClientBuilder::setHttpClientOptions() that accepts a \Psr\Http\Client\ClientInterface, i.e.: a PSR-7 HTTP Client.
Drupal core has a service with the machine name http_client, which conforms to the PSR-7 ClientInterface standard, and also knows about any proxies that are configured in settings.php for Drupal to use.
Proposed resolution
Pass Drupal's http_client to elasticsearch/elasticsearch's ClientBuilder::setHttpClientOptions, so it connects through that.
Remaining tasks
Merge request for 8.0.x- merge request !96 created by @hexaki in #13Maintainer review and testing- done by @mparker17 by #21Merge request for 9.0.x- merge request !204 created by @murrow in #22Community review and testing- skipped by @mparker17 in #24Commit to 9.0.x- merged by @mparker17 in #26Commit to 8.0.x- merged by @mparker17 in #28Release 9.0.x- released in 9.0.0-alpha3 by @mparker17Release 8.0.x- released in 8.0.0-alpha7 by @mparker17
User interface changes
None.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
Added support for connecting to Elasticsearch through the proxy globally configured for Drupal in settings.php.
Issue fork elasticsearch_connector-3321300
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
murrow commentedIn the current build (8.0.0-alpha2), I see no implementation that uses Drupal's HTTP proxy settings. This version of Elasticsearch Connector uses
elasticsearch/elasticsearch8, which should support proxies through the ClientBuilder'ssetHttpClientOptions()method, as described here: https://www.elastic.co/guide/en/elasticsearch/client/php-api/8.15/http-client.html.Is it correct to say that proxy support is missing from this module?
Comment #3
murrow commentedChanging the version number
Comment #4
sokru commented@murrow, you're correct there's currently no support for proxy connection.
Comment #5
murrow commentedComment #6
murrow commented@sokru, I have updated the issue summary with a proposed solution. The dependency injection part will disturb the code a bit, but I don't think the other tasks will have much impact. What are your thoughts?
Comment #7
murrow commentedFurther update to the summary problem section
Comment #8
murrow commentedAdding test task
Comment #14
hexaki commentedI pushed a solution using ClientBuilder::setHttpClient.
I also made it possible for Connector extending the StandardConnector to alter the Client without having to redefine it completely.
Comment #15
hexaki commentedComment #17
mparker17Sorry for the noise; I haven't had a chance to review the change yet.
I rebased onto the latest
8.0.x, so the phpstan pipeline wouldn't warn us about a deprecationComment #18
mparker17@murrow, @hexaki, thank you both very much for your contributions!
I've had a chance to look at the code in the merge request, and I have some feedback.
Before I give my feedback, note that I am assuming that, because you moved the Issue Status to "Needs review", you have finished implementing the full solution that you want. If that's not the case (i.e.: you still have work to do), please move it back to "Needs work" until you're done! Thank you! (it's hard for me to tell because I don't have the context that you do — I've never needed to connect to Elasticsearch through a proxy!)
Without further ado, here is my feedback...
(note that I may have misunderstood the Issue Title, and my expectation may be wrong!)
setHttpClientOptions()in the merge request, but I don't see anything like that.(note that I may have misunderstood the issue summary and my expectation may be wrong)
Needs issue summary updatetag, please remove when you're done updating the issue summary.Needs teststag, please remove it when you've added some tests.Since I have some questions for you, I'm changing the status to
Postponed (maintainer needs more info). When you've answered the questions, please move the issue back toNeeds reviewif you're done, orNeeds workif you have more work to do!Some other notes...
I fixed a spelling mistake in a docblock in the code.
I've updated the Issue Summary a bit based on my understanding of the problem and your solution. Please review it, and fix it if I've made a mistake.
I removed the
proxyandproxy variablesissue tags, as those are non-standard. See this list of standard tags.I changed this to a "Feature request" to reflect that you're asking for a feature that doesn't currently exist in the module. See also @sokru's comment in #4.
Comment #19
hexaki commentedHello, thanks @mparker17 for your feedback.
1. My understanding was that the proxy is usually an environment configuration and Drupal already has the means to configure it via the settings.php. So I didn't see the need for the proxy to be redefined in the server configuration.
I'm not used to contrib modules, and I have access to the entire site configuration (config and settings), so it seemed the easiest solution.
Do you rather like a full config solution ?
2. My propsed solution is : Use Drupal's "HttpClient" as in the \Elastic\Elasticsearch\ClientBuilder. This way the proxy is defined by
$settings['http_client_config']['proxy']3. Next step is validating this solution and writing tests.
4. I could use help writing a test for this solution (any guideline is fine).
Comment #20
sweetchuckMR96 at commit c0ce23116b39467d4c2bb857d7a75a5d3037c0ef works for me.
settings.php
Comment #21
mparker17I rebased onto 8.0.x. I added the ability to use Drupal core's
http_clientservice (which knows about the proxy) from the newerElasticCloudEndpointConnectorandElasticCloudIdConnectorconnectors.I was on the fence about adding a
getClientBuilder()method to the Standard connector (or presumably, all connector plugins), but I ultimately decided that, to keep it simple, I wouldn't add it (which adds a bit of duplication). I think it's worth exploring if it would be worth adding a connector base class, but I daresay that's out-of-scope for this issue.This merge request also changes nearly the same part of the code as #3529647: Fix logging in BasicAuthConnector, meaning there's a chance those two changes will conflict... so I set the HTTP Client before the Hosts: hopefully Git can still figure out how to auto-merge them. If not, it should be relatively simple to resolve a merge conflict if that happens anyway.
I'm not sure how we can test this so I'm removing the "Needs tests" tag. Happily, it seems like pipeline 801875 passed, so that tells me we didn't break anything, although our current CI environment doesn't have a proxy configured.
I would appreciate it if @sabsbecool, @murrow, @hexaki, @sweetchuck, and/or @sokru could test out the updated changes and let me know if it still works.
Comment #23
mparker17Created merge request !204 for the 9.0.x branch; updated this issue's version, and added the "Needs backport" tag so I don't forget to merge the 8.0.x MR.
Comment #24
mparker17I haven't heard back from anyone in 6 days, but I want to make this issue part of the next release, so I'm going to merge this one now.
Comment #25
mparker17Had to rebase and fix a merge conflict; then made a follow-up change to make merges easier in the future.
D10 an D11 tests pass, so I'm going to merge.
Comment #27
mparker17Merged to 9.0.x; merging to 8.0.x next.
Comment #29
mparker17Merged to 8.0.x. I will update this when I make a the next release.
Comment #31
mparker17The changes in this issue were released in elasticsearch_connector-9.0.0-alpha3, and elasticsearch_connector-8.0.0-alpha7