lmenezes / cerebro

MIT License
5.52k stars 716 forks source link

Possible to configure a proxy for the connections cerebro makes? #481

Closed HerbCSO closed 3 years ago

HerbCSO commented 3 years ago

I'm running cerebro ad-hoc on my laptop when I need it. (MacOS Catalina 10.15.7, cerebro version 0.9.2) My company has now introduced the need to use local SOCKS5 proxy server to make the connection (it's complicated! ;] ). I've got http_proxy, https_proxy, HTTP_PROXY, and HTTPS_PROXY environment variables set to http://127.0.0.1:8118 in the terminal window where I'm starting cerebro from. When I connect to http://localhost:9000 (this bit works, I get the cerebro page prompting me for the server URL) and enter the server address, it fails to make a connection with this error:

[error] p.a.h.DefaultHttpErrorHandler -

! @7hi1eak6k - Internal server error, for (POST) [/connect] ->

play.api.UnexpectedException: Unexpected exception[UnknownHostException: <es_server_name_redacted>: nodename nor servname provided, or not known]
        at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:331)
        at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:253)
        at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:424)
        at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:420)
        at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:417)
Caused by: java.net.UnknownHostException: <es_server_name_redacted>: nodename nor servname provided, or not known
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
        at java.net.InetAddress.getAllByName0(InetAddress.java:1277)
        at java.net.InetAddress.getAllByName(InetAddress.java:1193)

A direct connection from my browser to the URL I gave cerebro works and returns the usual JSON info about the ES cluster, so I know I have the correct URL and the server is working. In the browser I have the proxy setup as well.

I've tried starting it with bin/cerebro -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=8118, but that still results in the same error.

Since the error appears to come from InetAddress.getAllByName, I also tried using the IP address in case it was just a DNS issue, but then the error is this:

[error] p.a.h.DefaultHttpErrorHandler -

! @7hi1j0e5p - Internal server error, for (POST) [/connect] ->

play.api.UnexpectedException: Unexpected exception[TimeoutException: Request timeout to <IP_redacted>:9200 after 120000 ms]
        at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:331)
        at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:253)
        at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:424)
        at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:420)
        at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:417)
Caused by: java.util.concurrent.TimeoutException: Request timeout to <IP_redacted>:9200 after 120000 ms
        at play.shaded.ahc.org.asynchttpclient.netty.timeout.TimeoutTimerTask.expire(TimeoutTimerTask.java:43)
        at play.shaded.ahc.org.asynchttpclient.netty.timeout.RequestTimeoutTimerTask.run(RequestTimeoutTimerTask.java:50)
        at play.shaded.ahc.io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:680)
        at play.shaded.ahc.io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:755)
        at play.shaded.ahc.io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:483)

I've tried playing with some of the other things on https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html but so far haven't been able to make it work. I'm probably missing something obvious, but I have no idea what... :/

Any chance you might have some ideas on what else I could try?

0ccupi3R commented 3 years ago

Hi @HerbCSO

I am not sure if you are still facing the same issue. I just faced the same and in my case, it has been resolved by updating my DNS entries /etc/resolv.conf.

HerbCSO commented 3 years ago

Ah, yes, actually I managed to make it work by modifying the cerebro script and adding these lines after the initial addJava call:

addJava "-Dhttp.proxyHost=127.0.0.1"
addJava "-Dhttp.proxyPort=8118"
addJava "-Dhttps.proxyHost=127.0.0.1"
addJava "-Dhttps.proxyPort=8118"

So basically instead of using socksProxyHost I needed to use http.proxyHost and http.proxyPort instead.