Commit 1cec26c7 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch...

Merge branch '299991-opening-admin-settings-page-results-in-the-error-500-if-localhost-cannot-be-accessed-on' into 'master'

Handle unreachable ES host in settings check

See merge request gitlab-org/gitlab!52586
parents 2430d6ae b982d4b1
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
- recreate_index_url = help_page_url('integration/elasticsearch.md') - recreate_index_url = help_page_url('integration/elasticsearch.md')
- recreate_index_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: recreate_index_url } - recreate_index_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: recreate_index_url }
- recreate_index_text = _("Changes won't take place until the index is %{link_start}recreated%{link_end}.").html_safe % { link_start: recreate_index_link_start, link_end: '</a>'.html_safe } - recreate_index_text = _("Changes won't take place until the index is %{link_start}recreated%{link_end}.").html_safe % { link_start: recreate_index_link_start, link_end: '</a>'.html_safe }
- elasticsearch_available = Gitlab::Elastic::Helper.default.client.ping - elasticsearch_available = Gitlab::Elastic::Helper.default.ping?
%section.settings.expanded.as-elasticsearch.no-animate#js-elasticsearch-settings{ data: { qa_selector: 'elasticsearch_tab' } } %section.settings.expanded.as-elasticsearch.no-animate#js-elasticsearch-settings{ data: { qa_selector: 'elasticsearch_tab' } }
.settings-header .settings-header
......
---
title: Handle network unreachable for ES settings check
merge_request: 52586
author:
type: fixed
...@@ -294,6 +294,13 @@ module Gitlab ...@@ -294,6 +294,13 @@ module Gitlab
end end
end end
# handles unreachable hosts and any other exceptions that may be raised
def ping?
client.ping
rescue
false
end
private private
def additional_index_options def additional_index_options
......
...@@ -359,4 +359,15 @@ RSpec.describe Gitlab::Elastic::Helper do ...@@ -359,4 +359,15 @@ RSpec.describe Gitlab::Elastic::Helper do
end end
end end
end end
describe '#ping?' do
subject { helper.ping? }
it 'does not raise any exception' do
allow(Gitlab::Elastic::Helper.default.client).to receive(:ping).and_raise(StandardError)
expect(subject).to be_falsey
expect { subject }.not_to raise_exception
end
end
end end
...@@ -218,5 +218,18 @@ RSpec.describe 'admin/application_settings/_elasticsearch_form' do ...@@ -218,5 +218,18 @@ RSpec.describe 'admin/application_settings/_elasticsearch_form' do
expect(rendered).to include('Retry migration') expect(rendered).to include('Retry migration')
end end
end end
context 'when elasticsearch is unreachable' do
before do
allow(Gitlab::Elastic::Helper.default).to receive(:ping?).and_return(false)
end
it 'does not show the retry migration card' do
render
expect(rendered).not_to include('There is a halted Elasticsearch migration')
expect(rendered).not_to include('Retry migration')
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