Commit 3b5c6249 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '296032_ignore_es_connection_exception' into 'master'

Ignore connection error when changing the Elasticsearch Server URL

See merge request gitlab-org/gitlab!52645
parents 92d0ef6c 101d747d
......@@ -20,7 +20,7 @@ module EE
elasticsearch_project_ids = params.delete(:elasticsearch_project_ids)
if result = super
find_or_create_index
find_or_create_elasticsearch_index
update_elasticsearch_containers(ElasticsearchIndexedNamespace, elasticsearch_namespace_ids)
update_elasticsearch_containers(ElasticsearchIndexedProject, elasticsearch_project_ids)
end
......@@ -61,13 +61,23 @@ module EE
current_user_cap.nil? || current_user_cap > previous_user_cap
end
def find_or_create_index
def find_or_create_elasticsearch_index
# The order of checks is important. We should not attempt to create a new index
# unless elasticsearch_indexing is enabled
return unless application_setting.elasticsearch_indexing
return if ::Gitlab::Elastic::Helper.default.index_exists?
return if elasticsearch_helper.index_exists?
::Gitlab::Elastic::Helper.default.create_empty_index
elasticsearch_helper.create_empty_index
rescue Faraday::Error => e
log_error(e)
end
def elasticsearch_helper
@elasticsearch_helper ||= ::Gitlab::Elastic::Helper.new(client: elasticsearch_client)
end
def elasticsearch_client
::Gitlab::Elastic::Client.build(application_setting.elasticsearch_config)
end
end
end
......
---
title: Ignore connection error when changing the Elasticsearch Server URL
merge_request: 52645
author:
type: fixed
......@@ -38,7 +38,7 @@ RSpec.describe ApplicationSettings::UpdateService do
let(:helper) { Gitlab::Elastic::Helper.new }
before do
allow(Gitlab::Elastic::Helper).to receive(:default).and_return(helper)
allow(Gitlab::Elastic::Helper).to receive(:new).and_return(helper)
end
context 'index creation' do
......@@ -61,6 +61,15 @@ RSpec.describe ApplicationSettings::UpdateService do
service.execute
end
end
context 'when ES service is not reachable' do
it 'does not throw exception' do
expect(helper).to receive(:index_exists?).and_raise(Faraday::ConnectionFailed, nil)
expect(helper).not_to receive(:create_empty_index)
expect { service.execute }.not_to raise_error
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