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 ...@@ -20,7 +20,7 @@ module EE
elasticsearch_project_ids = params.delete(:elasticsearch_project_ids) elasticsearch_project_ids = params.delete(:elasticsearch_project_ids)
if result = super if result = super
find_or_create_index find_or_create_elasticsearch_index
update_elasticsearch_containers(ElasticsearchIndexedNamespace, elasticsearch_namespace_ids) update_elasticsearch_containers(ElasticsearchIndexedNamespace, elasticsearch_namespace_ids)
update_elasticsearch_containers(ElasticsearchIndexedProject, elasticsearch_project_ids) update_elasticsearch_containers(ElasticsearchIndexedProject, elasticsearch_project_ids)
end end
...@@ -61,13 +61,23 @@ module EE ...@@ -61,13 +61,23 @@ module EE
current_user_cap.nil? || current_user_cap > previous_user_cap current_user_cap.nil? || current_user_cap > previous_user_cap
end 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 # The order of checks is important. We should not attempt to create a new index
# unless elasticsearch_indexing is enabled # unless elasticsearch_indexing is enabled
return unless application_setting.elasticsearch_indexing 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 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 ...@@ -38,7 +38,7 @@ RSpec.describe ApplicationSettings::UpdateService do
let(:helper) { Gitlab::Elastic::Helper.new } let(:helper) { Gitlab::Elastic::Helper.new }
before do before do
allow(Gitlab::Elastic::Helper).to receive(:default).and_return(helper) allow(Gitlab::Elastic::Helper).to receive(:new).and_return(helper)
end end
context 'index creation' do context 'index creation' do
...@@ -61,6 +61,15 @@ RSpec.describe ApplicationSettings::UpdateService do ...@@ -61,6 +61,15 @@ RSpec.describe ApplicationSettings::UpdateService do
service.execute service.execute
end end
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
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