Commit 6ee8e0c1 authored by Terri Chu's avatar Terri Chu

Merge branch 'john-mason-feature-329191' into 'master'

Flash a warning when not using index aliases

See merge request gitlab-org/gitlab!71609
parents 2ab68081 14d035b4
...@@ -9,6 +9,7 @@ module EE ...@@ -9,6 +9,7 @@ module EE
prepended do prepended do
before_action :elasticsearch_reindexing_task, only: [:advanced_search] before_action :elasticsearch_reindexing_task, only: [:advanced_search]
before_action :elasticsearch_index_settings, only: [:advanced_search] before_action :elasticsearch_index_settings, only: [:advanced_search]
before_action :elasticsearch_warn_if_not_using_aliases, only: [:advanced_search]
feature_category :license, [:seat_link_payload] feature_category :license, [:seat_link_payload]
feature_category :source_code_management, [:templates] feature_category :source_code_management, [:templates]
...@@ -22,6 +23,12 @@ module EE ...@@ -22,6 +23,12 @@ module EE
def elasticsearch_index_settings def elasticsearch_index_settings
@elasticsearch_index_settings = Elastic::IndexSetting.order_by_name @elasticsearch_index_settings = Elastic::IndexSetting.order_by_name
end end
def elasticsearch_warn_if_not_using_aliases
@elasticsearch_warn_if_not_using_aliases = ::Gitlab::Elastic::Helper.default.alias_missing?
rescue StandardError => e
log_exception(e)
end
end end
EE_VALID_SETTING_PANELS = %w(advanced_search templates).freeze EE_VALID_SETTING_PANELS = %w(advanced_search templates).freeze
......
...@@ -2,5 +2,22 @@ ...@@ -2,5 +2,22 @@
- page_title _("Advanced Search") - page_title _("Advanced Search")
- @content_class = "limit-container-width" unless fluid_layout - @content_class = "limit-container-width" unless fluid_layout
- help_link_start = "<a class='gl-link' href='#{help_page_path('integration/elasticsearch')}#%{anchor}' target='_blank' rel='noopener noreferrer'>"
- help_zero_downtime_reindexing_link_start = help_link_start.html_safe % { anchor: "zero-downtime-reindexing" }
- help_advanced_search_migrations_link_start = help_link_start.html_safe % { anchor: "advanced-search-migrations" }
- help_recreate_index_link_start = help_link_start.html_safe % { anchor: "last-resort-to-recreate-an-index" }
- if @elasticsearch_warn_if_not_using_aliases
- content_for :page_level_alert do
%div{ class: [container_class, @content_class, 'gl-pt-5!'] }
.gl-alert{ class: ['gl-alert-warning'] }
= sprite_icon('warning', size: 16, css_class: "gl-alert-icon")
.gl-alert-content{ role: 'alert' }
%h4.gl-alert-title
= s_('AdvancedSearch|Reindex required')
.gl-alert-body
= s_('Introduced in GitLab 13.1, before using %{reindexing_link_start}zero-downtime reindexing%{link_end} and %{migrations_link_start}Advanced Search migrations%{link_end}, you need to %{recreate_link_start}recreate your index%{link_end}.').html_safe % { reindexing_link_start: help_zero_downtime_reindexing_link_start, migrations_link_start: help_advanced_search_migrations_link_start, recreate_link_start: help_recreate_index_link_start, link_end: '</a>'.html_safe }
= render_if_exists 'admin/application_settings/elasticsearch_form' = render_if_exists 'admin/application_settings/elasticsearch_form'
...@@ -164,6 +164,10 @@ module Gitlab ...@@ -164,6 +164,10 @@ module Gitlab
client.indices.exists_alias(name: name || target_name) client.indices.exists_alias(name: name || target_name)
end end
def alias_missing?(name: nil)
!alias_exists?(name: name)
end
# Calls Elasticsearch refresh API to ensure data is searchable # Calls Elasticsearch refresh API to ensure data is searchable
# immediately. # immediately.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html # https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html
......
...@@ -321,6 +321,33 @@ RSpec.describe Admin::ApplicationSettingsController do ...@@ -321,6 +321,33 @@ RSpec.describe Admin::ApplicationSettingsController do
@request.env['HTTP_REFERER'] = advanced_search_admin_application_settings_path @request.env['HTTP_REFERER'] = advanced_search_admin_application_settings_path
end end
context 'warning if not using index aliases' do
let(:helper) { instance_double(::Gitlab::Elastic::Helper) }
before do
allow(::Gitlab::Elastic::Helper).to receive(:default).and_return(helper)
end
it 'warns when NOT using index aliases' do
allow(helper).to receive(:alias_missing?).and_return true
get :advanced_search
expect(assigns[:elasticsearch_warn_if_not_using_aliases]).to be_truthy
end
it 'does NOT warn when using index aliases' do
allow(helper).to receive(:alias_missing?).and_return false
get :advanced_search
expect(assigns[:elasticsearch_warn_if_not_using_aliases]).to be_falsy
end
it 'does NOT blow up if elasticsearch is unreachable' do
allow(helper).to receive(:alias_missing?).and_raise(::Elasticsearch::Transport::Transport::ServerError, 'boom')
get :advanced_search
expect(assigns[:elasticsearch_warn_if_not_using_aliases]).to be_falsy
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'advanced search settings' do context 'advanced search settings' do
it 'updates the advanced search settings' do it 'updates the advanced search settings' do
settings = { settings = {
......
...@@ -264,6 +264,12 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do ...@@ -264,6 +264,12 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do
end end
end end
describe '#alias_missing?' do
it 'is the opposite of #alias_exists?' do
expect(helper.alias_missing?).to eq(!helper.alias_exists?)
end
end
describe '#cluster_free_size_bytes' do describe '#cluster_free_size_bytes' do
it 'returns valid cluster size' do it 'returns valid cluster size' do
expect(helper.cluster_free_size_bytes).to be_positive expect(helper.cluster_free_size_bytes).to be_positive
......
...@@ -2914,6 +2914,9 @@ msgstr "" ...@@ -2914,6 +2914,9 @@ msgstr ""
msgid "Advanced export options" msgid "Advanced export options"
msgstr "" msgstr ""
msgid "AdvancedSearch|Reindex required"
msgstr ""
msgid "After a successful password update you will be redirected to login screen." msgid "After a successful password update you will be redirected to login screen."
msgstr "" msgstr ""
...@@ -18647,6 +18650,9 @@ msgstr "" ...@@ -18647,6 +18650,9 @@ msgstr ""
msgid "Interval Pattern" msgid "Interval Pattern"
msgstr "" msgstr ""
msgid "Introduced in GitLab 13.1, before using %{reindexing_link_start}zero-downtime reindexing%{link_end} and %{migrations_link_start}Advanced Search migrations%{link_end}, you need to %{recreate_link_start}recreate your index%{link_end}."
msgstr ""
msgid "Introducing Your DevOps Reports" msgid "Introducing Your DevOps Reports"
msgstr "" msgstr ""
......
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