Commit 4ebbb004 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch '331513-fix-es-settings' into 'master'

Advanced Search Settings page does not load if the ES url is unreachable

See merge request gitlab-org/gitlab!63764
parents 9ab7cde7 a778d4f7
......@@ -7,12 +7,19 @@ module Gitlab
module Client
extend Gitlab::Utils::StrongMemoize
OPEN_TIMEOUT = 5
# Takes a hash as returned by `ApplicationSetting#elasticsearch_config`,
# and configures itself based on those parameters
def self.build(config)
base_config = {
urls: config[:url],
request_timeout: config[:client_request_timeout],
transport_options: {
request: {
timeout: config[:client_request_timeout],
open_timeout: OPEN_TIMEOUT
}
},
randomize_hosts: true,
retry_on_failure: true
}.compact
......
......@@ -18,7 +18,7 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do
end
after do
helper.delete_index(index_name: @index_name)
helper.delete_index(index_name: @index_name) if @index_name
end
describe '.new' do
......
......@@ -18,14 +18,18 @@ RSpec.describe Gitlab::Elastic::Client do
end
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
context 'with client_request_timeout in config' do
let(:params) { { url: 'http://dummy-elastic:9200', client_request_timeout: 30 } }
it 'does not set request timeout in transport' do
expect(client.transport.options).to include(request_timeout: 30)
it 'sets request timeout in transport' do
options = client.transport.options.dig(:transport_options, :request)
expect(options).to include(open_timeout: described_class::OPEN_TIMEOUT, timeout: 30)
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