Commit a778d4f7 authored by Dmitry Gruzd's avatar Dmitry Gruzd Committed by Matthias Käppler

Fix unreachable ES url exception

EE: true
Changelog: fixed
parent 2f9eec2f
...@@ -7,12 +7,19 @@ module Gitlab ...@@ -7,12 +7,19 @@ module Gitlab
module Client module Client
extend Gitlab::Utils::StrongMemoize extend Gitlab::Utils::StrongMemoize
OPEN_TIMEOUT = 5
# Takes a hash as returned by `ApplicationSetting#elasticsearch_config`, # Takes a hash as returned by `ApplicationSetting#elasticsearch_config`,
# and configures itself based on those parameters # and configures itself based on those parameters
def self.build(config) def self.build(config)
base_config = { base_config = {
urls: config[:url], urls: config[:url],
request_timeout: config[:client_request_timeout], transport_options: {
request: {
timeout: config[:client_request_timeout],
open_timeout: OPEN_TIMEOUT
}
},
randomize_hosts: true, randomize_hosts: true,
retry_on_failure: true retry_on_failure: true
}.compact }.compact
......
...@@ -18,7 +18,7 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do ...@@ -18,7 +18,7 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do
end end
after do after do
helper.delete_index(index_name: @index_name) helper.delete_index(index_name: @index_name) if @index_name
end end
describe '.new' do describe '.new' do
......
...@@ -18,14 +18,18 @@ RSpec.describe Gitlab::Elastic::Client do ...@@ -18,14 +18,18 @@ RSpec.describe Gitlab::Elastic::Client do
end end
it 'does not set request timeout in transport' do it 'does not set request timeout in transport' do
expect(client.transport.options).not_to include(:request_timeout) options = client.transport.options.dig(:transport_options, :request)
expect(options).to include(open_timeout: described_class::OPEN_TIMEOUT, timeout: nil)
end end
context 'with client_request_timeout in config' do context 'with client_request_timeout in config' do
let(:params) { { url: 'http://dummy-elastic:9200', client_request_timeout: 30 } } let(:params) { { url: 'http://dummy-elastic:9200', client_request_timeout: 30 } }
it 'does not set request timeout in transport' do it 'sets request timeout in transport' do
expect(client.transport.options).to include(request_timeout: 30) options = client.transport.options.dig(:transport_options, :request)
expect(options).to include(open_timeout: described_class::OPEN_TIMEOUT, timeout: 30)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment