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
prepended do
before_action :elasticsearch_reindexing_task, 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 :source_code_management, [:templates]
......@@ -22,6 +23,12 @@ module EE
def elasticsearch_index_settings
@elasticsearch_index_settings = Elastic::IndexSetting.order_by_name
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
EE_VALID_SETTING_PANELS = %w(advanced_search templates).freeze
......
......@@ -2,5 +2,22 @@
- page_title _("Advanced Search")
- @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'
......@@ -164,6 +164,10 @@ module Gitlab
client.indices.exists_alias(name: name || target_name)
end
def alias_missing?(name: nil)
!alias_exists?(name: name)
end
# Calls Elasticsearch refresh API to ensure data is searchable
# immediately.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html
......
......@@ -321,6 +321,33 @@ RSpec.describe Admin::ApplicationSettingsController do
@request.env['HTTP_REFERER'] = advanced_search_admin_application_settings_path
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
it 'updates the advanced search settings' do
settings = {
......
......@@ -264,6 +264,12 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do
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
it 'returns valid cluster size' do
expect(helper.cluster_free_size_bytes).to be_positive
......
......@@ -2914,6 +2914,9 @@ msgstr ""
msgid "Advanced export options"
msgstr ""
msgid "AdvancedSearch|Reindex required"
msgstr ""
msgid "After a successful password update you will be redirected to login screen."
msgstr ""
......@@ -18647,6 +18650,9 @@ msgstr ""
msgid "Interval Pattern"
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"
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