Commit ffa85fad authored by Andrejs Cunskis's avatar Andrejs Cunskis

Merge branch 'egb-add-es-toggle-rake' into 'master'

Add enable and disable elasticsearch rake tasks

See merge request gitlab-org/gitlab!75946
parents 68dfa652 4de07933
...@@ -478,6 +478,8 @@ The following are some available Rake tasks: ...@@ -478,6 +478,8 @@ The following are some available Rake tasks:
| [`sudo gitlab-rake gitlab:elastic:mark_reindex_failed`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Mark the most recent re-index job as failed. | | [`sudo gitlab-rake gitlab:elastic:mark_reindex_failed`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Mark the most recent re-index job as failed. |
| [`sudo gitlab-rake gitlab:elastic:list_pending_migrations`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | List pending migrations. Pending migrations include those that have not yet started, have started but not finished, and those that are halted. | | [`sudo gitlab-rake gitlab:elastic:list_pending_migrations`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | List pending migrations. Pending migrations include those that have not yet started, have started but not finished, and those that are halted. |
| [`sudo gitlab-rake gitlab:elastic:estimate_cluster_size`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Get an estimate of cluster size based on the total repository size. | | [`sudo gitlab-rake gitlab:elastic:estimate_cluster_size`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Get an estimate of cluster size based on the total repository size. |
| [`sudo gitlab-rake gitlab:elastic:enable_search_with_elasticsearch`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Enable advanced search with Elasticsearch. |
| [`sudo gitlab-rake gitlab:elastic:disable_search_with_elasticsearch`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Disables advanced search with Elasticsearch. |
### Environment variables ### Environment variables
......
...@@ -27,6 +27,36 @@ namespace :gitlab do ...@@ -27,6 +27,36 @@ namespace :gitlab do
Rake::Task["gitlab:elastic:index_snippets"].invoke Rake::Task["gitlab:elastic:index_snippets"].invoke
end end
desc 'GitLab | Elasticsearch | Enable Elasticsearch search'
task enable_search_with_elasticsearch: :environment do
if Gitlab::CurrentSettings.elasticsearch_search?
puts "Setting `elasticsearch_search` was already enabled."
else
ApplicationSettings::UpdateService.new(
Gitlab::CurrentSettings.current_application_settings,
nil,
{ elasticsearch_search: true }
).execute
puts "Setting `elasticsearch_search` has been enabled."
end
end
desc 'GitLab | Elasticsearch | Disable Elasticsearch search'
task disable_search_with_elasticsearch: :environment do
if Gitlab::CurrentSettings.elasticsearch_search?
ApplicationSettings::UpdateService.new(
Gitlab::CurrentSettings.current_application_settings,
nil,
{ elasticsearch_search: false }
).execute
puts "Setting `elasticsearch_search` has been disabled."
else
puts "Setting `elasticsearch_search` was already disabled."
end
end
desc "GitLab | Elasticsearch | Index projects in the background" desc "GitLab | Elasticsearch | Index projects in the background"
task index_projects: :environment do task index_projects: :environment do
print "Enqueuing projects…" print "Enqueuing projects…"
......
...@@ -7,6 +7,54 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic, :silence_stdout ...@@ -7,6 +7,54 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic, :silence_stdout
Rake.application.rake_require 'tasks/gitlab/elastic' Rake.application.rake_require 'tasks/gitlab/elastic'
end end
describe 'when enabling and disabling elastic settings' do
let(:settings) { ::Gitlab::CurrentSettings }
before do
settings.update!(elasticsearch_search: es_enabled)
end
describe 'when enabling elasticsearch with setting initially off' do
subject { run_rake_task('gitlab:elastic:enable_search_with_elasticsearch') }
let(:es_enabled) { false }
it 'enables elasticsearch' do
expect { subject }.to change { settings.elasticsearch_search }.from(false).to(true)
end
end
describe 'when enabling elasticsearch with setting initially on' do
subject { run_rake_task('gitlab:elastic:enable_search_with_elasticsearch') }
let(:es_enabled) { true }
it 'does nothing when elasticsearch is already enabled' do
expect { subject }.not_to change { settings.elasticsearch_search }
end
end
describe 'when disabling elasticsearch with setting initially on' do
subject { run_rake_task('gitlab:elastic:disable_search_with_elasticsearch') }
let(:es_enabled) { true }
it 'disables elasticsearch' do
expect { subject }.to change { settings.elasticsearch_search }.from(true).to(false)
end
end
describe 'when disabling elasticsearch with setting initially off' do
subject { run_rake_task('gitlab:elastic:disable_search_with_elasticsearch') }
let(:es_enabled) { false }
it 'does nothing when elasticsearch is already disabled' do
expect { subject }.not_to change { settings.elasticsearch_search }
end
end
end
describe 'create_empty_index' do describe 'create_empty_index' do
subject { run_rake_task('gitlab:elastic:create_empty_index') } subject { run_rake_task('gitlab:elastic:create_empty_index') }
......
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