Commit 353c8b72 authored by Sean McGivern's avatar Sean McGivern

Merge branch...

Merge branch '239270-remove-the-need-to-run-rake-tasks-to-create-index-when-enabling-elasticsearch-integration' into 'master'

Automate index creation when enabling Elasticsearch integration

See merge request gitlab-org/gitlab!43912
parents 4d4d0192 c10167dd
...@@ -178,22 +178,11 @@ To enable Advanced Search, you need to have admin access to GitLab: ...@@ -178,22 +178,11 @@ To enable Advanced Search, you need to have admin access to GitLab:
[license](../user/admin_area/license.md). [license](../user/admin_area/license.md).
1. Configure the [Advanced Search settings](#advanced-search-configuration) for 1. Configure the [Advanced Search settings](#advanced-search-configuration) for
your Elasticsearch cluster. Do not enable **Elasticsearch indexing** or your Elasticsearch cluster. Do not enable **Search with Elasticsearch enabled**
**Search with Elasticsearch enabled** yet. yet.
1. Click **Save changes** for the changes to take effect. 1. Now enable **Elasticsearch indexing** in **Admin Area > Settings >
1. Before enabling **Elasticsearch indexing** you need to create an index by General > Advanced Search** and click **Save changes**. This will create
running the Rake task: an empty index if one does not already exist.
```shell
# Omnibus installations
sudo gitlab-rake gitlab:elastic:create_empty_index
# Installations from source
bundle exec rake gitlab:elastic:create_empty_index RAILS_ENV=production
```
1. Now enable `Elasticsearch indexing` in **Admin Area > Settings >
General > Advanced Search** and click **Save changes**.
1. Click **Index all projects**. 1. Click **Index all projects**.
1. Click **Check progress** in the confirmation message to see the status of 1. Click **Check progress** in the confirmation message to see the status of
the background jobs. the background jobs.
...@@ -217,7 +206,7 @@ The following Elasticsearch settings are available: ...@@ -217,7 +206,7 @@ The following Elasticsearch settings are available:
| Parameter | Description | | Parameter | Description |
|-------------------------------------------------------|-------------| |-------------------------------------------------------|-------------|
| `Elasticsearch indexing` | Enables or disables Elasticsearch indexing. You may want to enable indexing but disable search in order to give the index time to be fully completed, for example. Also, keep in mind that this option doesn't have any impact on existing data, this only enables/disables the background indexer which tracks data changes and ensures new data is indexed. | | `Elasticsearch indexing` | Enables or disables Elasticsearch indexing and creates an empty index if one does not already exist. You may want to enable indexing but disable search in order to give the index time to be fully completed, for example. Also, keep in mind that this option doesn't have any impact on existing data, this only enables/disables the background indexer which tracks data changes and ensures new data is indexed. |
| `Pause Elasticsearch indexing` | Enables or disables temporary indexing pause. This is useful for cluster migration/reindexing. All changes are still tracked, but they are not committed to the Elasticsearch index until unpaused. | | `Pause Elasticsearch indexing` | Enables or disables temporary indexing pause. This is useful for cluster migration/reindexing. All changes are still tracked, but they are not committed to the Elasticsearch index until unpaused. |
| `Search with Elasticsearch enabled` | Enables or disables using Elasticsearch in search. | | `Search with Elasticsearch enabled` | Enables or disables using Elasticsearch in search. |
| `URL` | The URL to use for connecting to Elasticsearch. Use a comma-separated list to support clustering (e.g., `http://host1, https://host2:9200`). If your Elasticsearch instance is password protected, pass the `username:password` in the URL (e.g., `http://<username>:<password>@<elastic_host>:9200/`). | | `URL` | The URL to use for connecting to Elasticsearch. Use a comma-separated list to support clustering (e.g., `http://host1, https://host2:9200`). If your Elasticsearch instance is password protected, pass the `username:password` in the URL (e.g., `http://<username>:<password>@<elastic_host>:9200/`). |
......
...@@ -8,8 +8,6 @@ module EE ...@@ -8,8 +8,6 @@ module EE
override :execute override :execute
def execute def execute
return false if prevent_elasticsearch_indexing_update?
# Repository size limit comes as MB from the view # Repository size limit comes as MB from the view
limit = params.delete(:repository_size_limit) limit = params.delete(:repository_size_limit)
application_setting.repository_size_limit = ::Gitlab::Utils.try_megabytes_to_bytes(limit) if limit application_setting.repository_size_limit = ::Gitlab::Utils.try_megabytes_to_bytes(limit) if limit
...@@ -18,6 +16,7 @@ module EE ...@@ -18,6 +16,7 @@ module EE
elasticsearch_project_ids = params.delete(:elasticsearch_project_ids) elasticsearch_project_ids = params.delete(:elasticsearch_project_ids)
if result = super if result = super
find_or_create_index
update_elasticsearch_containers(ElasticsearchIndexedNamespace, elasticsearch_namespace_ids) update_elasticsearch_containers(ElasticsearchIndexedNamespace, elasticsearch_namespace_ids)
update_elasticsearch_containers(ElasticsearchIndexedProject, elasticsearch_project_ids) update_elasticsearch_containers(ElasticsearchIndexedProject, elasticsearch_project_ids)
end end
...@@ -43,10 +42,13 @@ module EE ...@@ -43,10 +42,13 @@ module EE
private private
def prevent_elasticsearch_indexing_update? def find_or_create_index
!application_setting.elasticsearch_indexing && # The order of checks is important. We should not attempt to create a new index
::Gitlab::Utils.to_boolean(params[:elasticsearch_indexing]) && # unless elasticsearch_indexing is enabled
!::Gitlab::Elastic::Helper.default.index_exists? return unless application_setting.elasticsearch_indexing
return if ::Gitlab::Elastic::Helper.default.index_exists?
::Gitlab::Elastic::Helper.default.create_empty_index
end end
end end
end end
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
Elasticsearch indexing Elasticsearch indexing
- unless Gitlab::CurrentSettings.elasticsearch_indexing? - unless Gitlab::CurrentSettings.elasticsearch_indexing?
.form-text.text-muted .form-text.text-muted
= _('Please create an index before enabling indexing') = _('An empty index will be created if one does not already exist')
- if Gitlab::CurrentSettings.elasticsearch_indexing? - if Gitlab::CurrentSettings.elasticsearch_indexing?
.form-text .form-text
= link_to _('Index all projects'), admin_elasticsearch_enqueue_index_path, = link_to _('Index all projects'), admin_elasticsearch_enqueue_index_path,
......
---
title: Find or create index when Elasticsearch indexing enabled
merge_request: 43912
author:
type: changed
...@@ -34,26 +34,26 @@ RSpec.describe ApplicationSettings::UpdateService do ...@@ -34,26 +34,26 @@ RSpec.describe ApplicationSettings::UpdateService do
end end
end end
context 'index dependent' do context 'elasticsearch_indexing update' do
using RSpec::Parameterized::TableSyntax context 'index creation' do
let(:opts) { { elasticsearch_indexing: true } }
where(:index_exists, :indexing_enabled, :input_value, :result) do context 'when index exists' do
false | false | true | false it 'skips creating a new index' do
false | true | true | true expect(Gitlab::Elastic::Helper.default).to(receive(:index_exists?)).and_return(true)
true | false | true | true expect(Gitlab::Elastic::Helper.default).not_to(receive(:create_empty_index))
true | true | true | true
end
with_them do service.execute
before do end
allow(Gitlab::Elastic::Helper.default).to(receive(:index_exists?)).and_return(index_exists)
allow(service.application_setting).to(receive(:elasticsearch_indexing)).and_return(indexing_enabled)
end end
let(:opts) { { elasticsearch_indexing: input_value } } context 'when index does not exist' do
it 'creates a new index' do
expect(Gitlab::Elastic::Helper.default).to(receive(:index_exists?)).and_return(false)
expect(Gitlab::Elastic::Helper.default).to(receive(:create_empty_index))
it 'returns correct result' do service.execute
expect(service.execute).to be(result) end
end end
end end
end end
......
...@@ -2683,6 +2683,9 @@ msgstr "" ...@@ -2683,6 +2683,9 @@ msgstr ""
msgid "An empty GitLab User field will add the FogBugz user's full name (e.g. \"By John Smith\") in the description of all issues and comments. It will also associate and/or assign these issues and comments with the project creator." msgid "An empty GitLab User field will add the FogBugz user's full name (e.g. \"By John Smith\") in the description of all issues and comments. It will also associate and/or assign these issues and comments with the project creator."
msgstr "" msgstr ""
msgid "An empty index will be created if one does not already exist"
msgstr ""
msgid "An error has occurred" msgid "An error has occurred"
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