Commit d3dadbce authored by Rémy Coutable's avatar Rémy Coutable

Merge branch...

Merge branch '216275-elasticsearch-rake-task-gitlab-elastic-index-won-t-work-as-designed' into 'master'

Make `gitlab:elastic:index` enable `elasticsearch_indexing`

Closes #216275

See merge request gitlab-org/gitlab!35342
parents e69aee26 8d32ead9
...@@ -245,7 +245,7 @@ This will delete your existing indexes. ...@@ -245,7 +245,7 @@ This will delete your existing indexes.
If the database size is less than 500 MiB, and the size of all hosted repos is less than 5 GiB: If the database size is less than 500 MiB, and the size of all hosted repos is less than 5 GiB:
1. [Enable **Elasticsearch indexing** and configure your host and port](#enabling-elasticsearch). 1. [Configure your Elasticsearch host and port](#enabling-elasticsearch).
1. Index your data: 1. Index your data:
```shell ```shell
...@@ -424,7 +424,7 @@ The following are some available Rake tasks: ...@@ -424,7 +424,7 @@ The following are some available Rake tasks:
| Task | Description | | Task | Description |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |:--------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`sudo gitlab-rake gitlab:elastic:index`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Wrapper task for `gitlab:elastic:create_empty_index`, `gitlab:elastic:clear_index_status`, `gitlab:elastic:index_projects`, and `gitlab:elastic:index_snippets`. | | [`sudo gitlab-rake gitlab:elastic:index`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Enables Elasticsearch Indexing and run `gitlab:elastic:create_empty_index`, `gitlab:elastic:clear_index_status`, `gitlab:elastic:index_projects`, and `gitlab:elastic:index_snippets`. |
| [`sudo gitlab-rake gitlab:elastic:index_projects`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Iterates over all projects and queues Sidekiq jobs to index them in the background. | | [`sudo gitlab-rake gitlab:elastic:index_projects`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Iterates over all projects and queues Sidekiq jobs to index them in the background. |
| [`sudo gitlab-rake gitlab:elastic:index_projects_status`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Determines the overall status of the indexing. It is done by counting the total number of indexed projects, dividing by a count of the total number of projects, then multiplying by 100. | | [`sudo gitlab-rake gitlab:elastic:index_projects_status`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Determines the overall status of the indexing. It is done by counting the total number of indexed projects, dividing by a count of the total number of projects, then multiplying by 100. |
| [`sudo gitlab-rake gitlab:elastic:clear_index_status`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Deletes all instances of IndexStatus for all projects. | | [`sudo gitlab-rake gitlab:elastic:clear_index_status`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Deletes all instances of IndexStatus for all projects. |
......
---
title: Automatically enable Elasticsearch indexing with 'gitlab:elastic:index'
merge_request: 35342
author:
type: changed
...@@ -9,6 +9,18 @@ namespace :gitlab do ...@@ -9,6 +9,18 @@ namespace :gitlab do
Rake::Task["gitlab:elastic:recreate_index"].invoke Rake::Task["gitlab:elastic:recreate_index"].invoke
Rake::Task["gitlab:elastic:clear_index_status"].invoke Rake::Task["gitlab:elastic:clear_index_status"].invoke
# enable `elasticsearch_indexing` if it isn't
unless Gitlab::CurrentSettings.elasticsearch_indexing?
ApplicationSettings::UpdateService.new(
Gitlab::CurrentSettings.current_application_settings,
nil,
{ elasticsearch_indexing: true }
).execute
puts "Setting `elasticsearch_indexing` has been enabled."
end
Rake::Task["gitlab:elastic:index_projects"].invoke Rake::Task["gitlab:elastic:index_projects"].invoke
Rake::Task["gitlab:elastic:index_snippets"].invoke Rake::Task["gitlab:elastic:index_snippets"].invoke
end end
......
...@@ -5,6 +5,10 @@ require 'rake_helper' ...@@ -5,6 +5,10 @@ require 'rake_helper'
RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do
before do before do
Rake.application.rake_require 'tasks/gitlab/elastic' Rake.application.rake_require 'tasks/gitlab/elastic'
end
context "with elasticsearch_indexing enabled" do
before do
stub_ee_application_setting(elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_indexing: true)
end end
...@@ -32,9 +36,7 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do ...@@ -32,9 +36,7 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do
end end
it 'queues jobs for each project batch' do it 'queues jobs for each project batch' do
expect(Elastic::ProcessInitialBookkeepingService).to receive(:backfill_projects!).with( expect(Elastic::ProcessInitialBookkeepingService).to receive(:backfill_projects!).with(project1, project2)
project1, project2
)
run_rake_task 'gitlab:elastic:index_projects' run_rake_task 'gitlab:elastic:index_projects'
end end
...@@ -54,9 +56,7 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do ...@@ -54,9 +56,7 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do
end end
it 'does not queue jobs for projects that should not be indexed' do it 'does not queue jobs for projects that should not be indexed' do
expect(Elastic::ProcessInitialBookkeepingService).to receive(:backfill_projects!).with( expect(Elastic::ProcessInitialBookkeepingService).to receive(:backfill_projects!).with(project1, project3)
project1, project3
)
run_rake_task 'gitlab:elastic:index_projects' run_rake_task 'gitlab:elastic:index_projects'
end end
...@@ -79,4 +79,13 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do ...@@ -79,4 +79,13 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do
run_rake_task 'gitlab:elastic:recreate_index' run_rake_task 'gitlab:elastic:recreate_index'
end end
end end
end
context "with elasticsearch_indexing is disabled" do
it 'enables `elasticsearch_indexing`' do
expect { run_rake_task 'gitlab:elastic:index' }.to change {
Gitlab::CurrentSettings.elasticsearch_indexing?
}.from(false).to(true)
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