Support the http_proxy environment variable for elasticsearch
Summary
Per https://gitlab.com/gitlab-org/gitlab-ee/issues/3125#note_37127998
Our Ruby elasticsearch client uses Faraday, which doesn't automatically pick up http_proxy
or https_proxy
envvars.
Steps to reproduce
$ http_proxy=http://127.0.0.1:8888 bin/rails c
Loading development environment (Rails 4.2.8)
[1] pry(main)> c = Gitlab::Elastic::Client.build(ApplicationSetting.current.elasticsearch_config)
[2] pry(main)> c.transport.connections.first.connection.proxy
nil
What is the current bug behavior?
Requests do not go via specified proxy
What is the expected correct behavior?
Requests should go via proxy
Possible fixes
https://gitlab.com/gitlab-org/gitlab-ee/blob/master/lib/gitlab/elastic/client.rb#L12
This method needs to add transport_options: { proxy: ENV['http_proxy'] }
to base_config
if the variable is set, per http://www.rubydoc.info/gems/elasticsearch-transport/Elasticsearch/Transport/Client#initialize-instance_method
I'm not sure about https_proxy
, especially given we can specify a mix of http and https URLs to the elasticsearch client.
This doesn't seem to be the full story though. I did this and made some requests through a non-existent proxy server and got results back, instead of ECONNREFUSED
:
[1] pry(main)> c = ::Elasticsearch::Client.new(url: 'http://localhost:9200', transport_options: { proxy: 'http://localhost:666' })
[2] pry(main)> c.transport.connections.first.connection.proxy
=> #<struct Faraday::ProxyOptions uri=#<URI::HTTP http://localhost:666>, user=nil, password=nil>
[3] pry(main)> c.get(index: 'gitlab-development', id: 1)
=> {"_index"=>"gitlab-development",
"_type"=>"snippet",
# ...
}