Commit e76b49d2 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch...

Merge branch '329273-gitlab-should-only-block-unpausing-elasticsearch-indexing-if-there-is-migration-running-that' into 'master'

Only block pausing indexing if running migration requires it

See merge request gitlab-org/gitlab!65281
parents 3feae782 879558dc
...@@ -68,6 +68,10 @@ module Elastic ...@@ -68,6 +68,10 @@ module Elastic
[] []
end end
def running?
started? && !halted? && !completed?
end
private private
def timestamps(completed:) def timestamps(completed:)
......
...@@ -49,16 +49,17 @@ ...@@ -49,16 +49,17 @@
.gl-card-body .gl-card-body
.form-group .form-group
.form-check .form-check
- pending_migrations = elasticsearch_available && Elastic::DataMigrationService.pending_migrations? && Gitlab::CurrentSettings.elasticsearch_pause_indexing? - first_pending_migration = Elastic::DataMigrationService.pending_migrations.first if elasticsearch_available
- disable_checkbox = !Gitlab::CurrentSettings.elasticsearch_indexing? || pending_migrations || @last_elasticsearch_reindexing_task&.in_progress? - pending_migration_running_and_pauses_indexing = first_pending_migration&.running? && first_pending_migration&.pause_indexing?
- disable_checkbox = !Gitlab::CurrentSettings.elasticsearch_indexing? || pending_migration_running_and_pauses_indexing || @last_elasticsearch_reindexing_task&.in_progress?
= f.check_box :elasticsearch_pause_indexing, class: 'form-check-input', data: { qa_selector: 'pause_checkbox' }, disabled: disable_checkbox = f.check_box :elasticsearch_pause_indexing, class: 'form-check-input', data: { qa_selector: 'pause_checkbox' }, disabled: disable_checkbox
= f.label :elasticsearch_pause_indexing, class: 'form-check-label' do = f.label :elasticsearch_pause_indexing, class: 'form-check-label' do
= _('Pause Elasticsearch indexing') = _('Pause Elasticsearch indexing')
.form-text.gl-text-gray-600.gl-mt-0 .form-text.gl-text-gray-600.gl-mt-0
= _('Changes are still tracked. Useful for cluster/index migrations.') = _('Changes are still tracked. Useful for cluster/index migrations.')
- if pending_migrations - if pending_migration_running_and_pauses_indexing
.form-text.text-warning .form-text.text-warning
= _('There are pending advanced search migrations. Indexing must remain paused until the migrations are completed.') = _('There are pending advanced search migrations which require indexing to be paused. Indexing must remain paused until the migrations are completed.')
.form-group .form-group
.form-check .form-check
......
...@@ -88,4 +88,28 @@ RSpec.describe Elastic::MigrationRecord, :elastic do ...@@ -88,4 +88,28 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
expect(described_class.load_versions(completed: false)).to eq([]) expect(described_class.load_versions(completed: false)).to eq([])
end end
end end
describe '#running?' do
using RSpec::Parameterized::TableSyntax
before do
allow(record).to receive(:halted?).and_return(halted)
allow(record).to receive(:started?).and_return(started)
allow(record).to receive(:completed?).and_return(completed)
end
where(:started, :halted, :completed, :expected) do
false | false | false | false
true | false | false | true
true | true | false | false
true | true | true | false
true | false | true | false
end
with_them do
it 'returns the expected result' do
expect(record.running?).to eq(expected)
end
end
end
end end
...@@ -44,13 +44,34 @@ RSpec.describe 'admin/application_settings/_elasticsearch_form' do ...@@ -44,13 +44,34 @@ RSpec.describe 'admin/application_settings/_elasticsearch_form' do
end end
context 'pending migrations' do context 'pending migrations' do
using RSpec::Parameterized::TableSyntax
let(:pending_migrations) { true } let(:pending_migrations) { true }
let(:pause_indexing) { true } let(:migration) { Elastic::DataMigrationService.migrations.first }
it 'renders a disabled pause checkbox' do before do
allow(Elastic::DataMigrationService).to receive(:pending_migrations).and_return([migration])
allow(migration).to receive(:running?).and_return(running)
allow(migration).to receive(:pause_indexing?).and_return(pause_indexing)
end
where(:running, :pause_indexing, :disabled) do
false | false | false
false | true | false
true | false | false
true | true | true
end
with_them do
it 'renders pause checkbox with disabled set appropriately' do
render render
if disabled
expect(rendered).to have_css('input[id=application_setting_elasticsearch_pause_indexing][disabled="disabled"]') expect(rendered).to have_css('input[id=application_setting_elasticsearch_pause_indexing][disabled="disabled"]')
else
expect(rendered).not_to have_css('input[id=application_setting_elasticsearch_pause_indexing][disabled="disabled"]')
end
end
end end
end end
end end
......
...@@ -32817,7 +32817,7 @@ msgstr "" ...@@ -32817,7 +32817,7 @@ msgstr ""
msgid "There are no variables yet." msgid "There are no variables yet."
msgstr "" msgstr ""
msgid "There are pending advanced search migrations. Indexing must remain paused until the migrations are completed." msgid "There are pending advanced search migrations which require indexing to be paused. Indexing must remain paused until the migrations are completed."
msgstr "" msgstr ""
msgid "There are running deployments on the environment. Please retry later." msgid "There are running deployments on the environment. Please retry later."
......
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