Commit 4db36aa3 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '338-install-elasticsearch-indexer' into 'master'

Add setting for gitlab-elasticsearch-indexer path

See merge request gitlab-org/gitlab-ee!14728
parents 3c6af384 efcd83de
...@@ -217,6 +217,7 @@ Gitlab.ee do ...@@ -217,6 +217,7 @@ Gitlab.ee do
Settings['elasticsearch'] ||= Settingslogic.new({}) Settings['elasticsearch'] ||= Settingslogic.new({})
Settings.elasticsearch['enabled'] = false if Settings.elasticsearch['enabled'].nil? Settings.elasticsearch['enabled'] = false if Settings.elasticsearch['enabled'].nil?
Settings.elasticsearch['url'] = ENV['ELASTIC_URL'] || "http://localhost:9200" Settings.elasticsearch['url'] = ENV['ELASTIC_URL'] || "http://localhost:9200"
Settings.elasticsearch['indexer_path'] ||= Gitlab::Utils.which('gitlab-elasticsearch-indexer')
end end
# #
......
...@@ -8,13 +8,12 @@ module Gitlab ...@@ -8,13 +8,12 @@ module Gitlab
class Indexer class Indexer
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
EXPERIMENTAL_INDEXER = 'gitlab-elasticsearch-indexer'.freeze
Error = Class.new(StandardError) Error = Class.new(StandardError)
class << self class << self
def experimental_indexer_present? def experimental_indexer_present?
Gitlab::Utils.which(EXPERIMENTAL_INDEXER).present? path = Gitlab.config.elasticsearch.indexer_path
path.present? && File.executable?(path)
end end
def experimental_indexer_version def experimental_indexer_version
...@@ -73,7 +72,7 @@ module Gitlab ...@@ -73,7 +72,7 @@ module Gitlab
def path_to_indexer def path_to_indexer
if use_experimental_indexer? if use_experimental_indexer?
EXPERIMENTAL_INDEXER Gitlab.config.elasticsearch.indexer_path
else else
Rails.root.join('bin', 'elastic_repo_indexer').to_s Rails.root.join('bin', 'elastic_repo_indexer').to_s
end end
......
...@@ -49,7 +49,7 @@ describe Gitlab::Elastic::Indexer do ...@@ -49,7 +49,7 @@ describe Gitlab::Elastic::Indexer do
expect_popen.with( expect_popen.with(
[ [
'gitlab-elasticsearch-indexer', 'tmp/tests/gitlab-elasticsearch-indexer/bin/gitlab-elasticsearch-indexer',
'--blob-type=wiki_blob', '--blob-type=wiki_blob',
'--skip-commits', '--skip-commits',
project.id.to_s, project.id.to_s,
...@@ -149,6 +149,26 @@ describe Gitlab::Elastic::Indexer do ...@@ -149,6 +149,26 @@ describe Gitlab::Elastic::Indexer do
stub_ee_application_setting(elasticsearch_experimental_indexer: true) stub_ee_application_setting(elasticsearch_experimental_indexer: true)
end end
describe '.experimental_indexer_present?' do
it 'returns true for an executable path' do
stub_elasticsearch_setting(indexer_path: 'tmp/tests/gitlab-elasticsearch-indexer/bin/gitlab-elasticsearch-indexer')
expect(described_class.experimental_indexer_present?).to eq(true)
end
it 'returns false for a non-executable path' do
stub_elasticsearch_setting(indexer_path: '/foo/bar')
expect(described_class.experimental_indexer_present?).to eq(false)
end
it 'returns false for a blank path' do
stub_elasticsearch_setting(indexer_path: '')
expect(described_class.experimental_indexer_present?).to eq(false)
end
end
it 'uses the normal indexer when not present' do it 'uses the normal indexer when not present' do
expect(described_class).to receive(:experimental_indexer_present?).and_return(false) expect(described_class).to receive(:experimental_indexer_present?).and_return(false)
expect_popen.with([Rails.root.join('bin/elastic_repo_indexer').to_s, anything, anything], anything, anything).and_return(popen_success) expect_popen.with([Rails.root.join('bin/elastic_repo_indexer').to_s, anything, anything], anything, anything).and_return(popen_success)
...@@ -158,7 +178,13 @@ describe Gitlab::Elastic::Indexer do ...@@ -158,7 +178,13 @@ describe Gitlab::Elastic::Indexer do
it 'uses the experimental indexer when present' do it 'uses the experimental indexer when present' do
expect(described_class).to receive(:experimental_indexer_present?).and_return(true) expect(described_class).to receive(:experimental_indexer_present?).and_return(true)
expect_popen.with(['gitlab-elasticsearch-indexer', anything, anything], anything, anything).and_return(popen_success) expect_popen.with(
[
'tmp/tests/gitlab-elasticsearch-indexer/bin/gitlab-elasticsearch-indexer',
anything, anything
],
anything, anything
).and_return(popen_success)
indexer.run indexer.run
end end
...@@ -174,7 +200,7 @@ describe Gitlab::Elastic::Indexer do ...@@ -174,7 +200,7 @@ describe Gitlab::Elastic::Indexer do
expect_popen.with( expect_popen.with(
[ [
'gitlab-elasticsearch-indexer', 'tmp/tests/gitlab-elasticsearch-indexer/bin/gitlab-elasticsearch-indexer',
project.id.to_s, project.id.to_s,
"#{project.repository.disk_path}.git" "#{project.repository.disk_path}.git"
], ],
......
...@@ -33,5 +33,9 @@ module EE ...@@ -33,5 +33,9 @@ module EE
def stub_smartcard_setting(messages) def stub_smartcard_setting(messages)
allow(::Gitlab.config.smartcard).to receive_messages(to_settings(messages)) allow(::Gitlab.config.smartcard).to receive_messages(to_settings(messages))
end end
def stub_elasticsearch_setting(messages)
allow(::Gitlab.config.elasticsearch).to receive_messages(to_settings(messages))
end
end end
end end
...@@ -18,8 +18,7 @@ module EE ...@@ -18,8 +18,7 @@ module EE
task: "gitlab:indexer:install[#{indexer_args}]" task: "gitlab:indexer:install[#{indexer_args}]"
) )
ENV['PATH'] = # rubocop:disable RSpec/EnvAssignment Settings.elasticsearch['indexer_path'] = indexer_bin_path
[indexer_bin_path, ENV['PATH']].join(File::PATH_SEPARATOR)
end end
def indexer_path def indexer_path
...@@ -27,7 +26,7 @@ module EE ...@@ -27,7 +26,7 @@ module EE
end end
def indexer_bin_path def indexer_bin_path
@indexer_bin_path ||= File.join(indexer_path, 'bin') @indexer_bin_path ||= File.join(indexer_path, 'bin', 'gitlab-elasticsearch-indexer')
end end
def indexer_version def indexer_version
......
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