Commit deee2572 authored by Dmitriy Zaporozhets (DZ)'s avatar Dmitriy Zaporozhets (DZ)

Merge branch '327847-fix-migration-has-finished' into 'master'

Advanced Search: Fix inaccessible ES server error

See merge request gitlab-org/gitlab!65731
parents e8df4442 31e6e995
...@@ -37,7 +37,8 @@ module Elastic ...@@ -37,7 +37,8 @@ module Elastic
def load_from_index def load_from_index
client.get(index: index_name, id: version) client.get(index: index_name, id: version)
rescue Elasticsearch::Transport::Transport::Errors::NotFound rescue StandardError => e
logger.error("[Elastic::MigrationRecord]: #{e.class}: #{e.message}")
nil nil
end end
...@@ -64,7 +65,7 @@ module Elastic ...@@ -64,7 +65,7 @@ module Elastic
.search(index: helper.migrations_index_name, body: { query: { term: { completed: completed } }, size: ELASTICSEARCH_SIZE }) .search(index: helper.migrations_index_name, body: { query: { term: { completed: completed } }, size: ELASTICSEARCH_SIZE })
.dig('hits', 'hits') .dig('hits', 'hits')
.map { |v| v['_id'].to_i } .map { |v| v['_id'].to_i }
rescue Elasticsearch::Transport::Transport::Errors::NotFound rescue StandardError
[] []
end end
...@@ -103,5 +104,9 @@ module Elastic ...@@ -103,5 +104,9 @@ module Elastic
def helper def helper
Gitlab::Elastic::Helper.default Gitlab::Elastic::Helper.default
end end
def logger
@logger ||= ::Gitlab::Elasticsearch::Logger.build
end
end end
end end
...@@ -41,6 +41,20 @@ RSpec.describe Elastic::MigrationRecord, :elastic do ...@@ -41,6 +41,20 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
end end
end end
describe '#load_from_index' do
it 'does not raise an exeption when connection refused' do
allow(Gitlab::Elastic::Helper.default).to receive(:get).and_raise(Faraday::ConnectionFailed)
expect(record.load_from_index).to be_nil
end
it 'does not raise an exeption when record does not exist' do
allow(Gitlab::Elastic::Helper.default).to receive(:get).and_raise(Elasticsearch::Transport::Transport::Errors::NotFound)
expect(record.load_from_index).to be_nil
end
end
describe '#halt!' do describe '#halt!' do
it 'sets state for halted and halted_indexing_unpaused' do it 'sets state for halted and halted_indexing_unpaused' do
record.halt! record.halt!
...@@ -87,6 +101,13 @@ RSpec.describe Elastic::MigrationRecord, :elastic do ...@@ -87,6 +101,13 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
expect(described_class.load_versions(completed: true)).to eq([]) expect(described_class.load_versions(completed: true)).to eq([])
expect(described_class.load_versions(completed: false)).to eq([]) expect(described_class.load_versions(completed: false)).to eq([])
end end
it 'returns empty array when exception is raised' do
allow(Gitlab::Elastic::Helper.default.client).to receive(:search).and_raise(Faraday::ConnectionFailed)
expect(described_class.load_versions(completed: true)).to eq([])
expect(described_class.load_versions(completed: false)).to eq([])
end
end end
describe '#running?' do describe '#running?' do
......
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