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:
[license](../user/admin_area/license.md).
1. Configure the [Advanced Search settings](#advanced-search-configuration) for
your Elasticsearch cluster. Do not enable **Elasticsearch indexing** or
**Search with Elasticsearch enabled** yet.
1. Click **Save changes** for the changes to take effect.
1. Before enabling **Elasticsearch indexing** you need to create an index by
running the Rake task:
```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**.
your Elasticsearch cluster. Do not enable **Search with Elasticsearch enabled**
yet.
1. Now enable **Elasticsearch indexing** in **Admin Area > Settings >
General > Advanced Search** and click **Save changes**. This will create
an empty index if one does not already exist.
1. Click **Index all projects**.
1. Click **Check progress** in the confirmation message to see the status of
the background jobs.
......@@ -217,7 +206,7 @@ The following Elasticsearch settings are available:
| 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. |
| `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/`). |
......
......@@ -8,8 +8,6 @@ module EE
override :execute
def execute
return false if prevent_elasticsearch_indexing_update?
# Repository size limit comes as MB from the view
limit = params.delete(:repository_size_limit)
application_setting.repository_size_limit = ::Gitlab::Utils.try_megabytes_to_bytes(limit) if limit
......@@ -18,6 +16,7 @@ module EE
elasticsearch_project_ids = params.delete(:elasticsearch_project_ids)
if result = super
find_or_create_index
update_elasticsearch_containers(ElasticsearchIndexedNamespace, elasticsearch_namespace_ids)
update_elasticsearch_containers(ElasticsearchIndexedProject, elasticsearch_project_ids)
end
......@@ -43,10 +42,13 @@ module EE
private
def prevent_elasticsearch_indexing_update?
!application_setting.elasticsearch_indexing &&
::Gitlab::Utils.to_boolean(params[:elasticsearch_indexing]) &&
!::Gitlab::Elastic::Helper.default.index_exists?
def find_or_create_index
# The order of checks is important. We should not attempt to create a new index
# unless elasticsearch_indexing is enabled
return unless application_setting.elasticsearch_indexing
return if ::Gitlab::Elastic::Helper.default.index_exists?
::Gitlab::Elastic::Helper.default.create_empty_index
end
end
end
......
......@@ -26,7 +26,7 @@
Elasticsearch indexing
- unless Gitlab::CurrentSettings.elasticsearch_indexing?
.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?
.form-text
= 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
end
end
context 'index dependent' do
using RSpec::Parameterized::TableSyntax
where(:index_exists, :indexing_enabled, :input_value, :result) do
false | false | true | false
false | true | true | true
true | false | true | true
true | true | true | true
end
context 'elasticsearch_indexing update' do
context 'index creation' do
let(:opts) { { elasticsearch_indexing: true } }
context 'when index exists' do
it 'skips creating a new index' do
expect(Gitlab::Elastic::Helper.default).to(receive(:index_exists?)).and_return(true)
expect(Gitlab::Elastic::Helper.default).not_to(receive(:create_empty_index))
with_them do
before do
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)
service.execute
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
expect(service.execute).to be(result)
service.execute
end
end
end
end
......
......@@ -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."
msgstr ""
msgid "An empty index will be created if one does not already exist"
msgstr ""
msgid "An error has occurred"
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