Commit 97aa4542 authored by Douwe Maan's avatar Douwe Maan

Merge branch '2149-check-gitlab-elasticsearch-indexer-in-path' into 'master'

Resolve "Disable the experimental GitLab elasticsearch indexer checkbox if it's not in $PATH"

Closes #2149

See merge request !1643
parents 051cfe45 a32fc5f3
%fieldset
%legend Elasticsearch
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_indexing do
= f.check_box :elasticsearch_indexing
Elasticsearch indexing
- missing = !Gitlab::Elastic::Indexer.experimental_indexer_present?
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_experimental_indexer do
= f.check_box :elasticsearch_experimental_indexer, disabled: missing
Use <a href="https://gitlab.com/gitlab-org/gitlab-elasticsearch-indexer">experimental repository indexer</a>
- if missing
(not installed)
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_search do
= f.check_box :elasticsearch_search
Search with Elasticsearch enabled
.form-group
= f.label :elasticsearch_url, 'URL', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_url, value: @application_setting.elasticsearch_url.join(', '), class: 'form-control', placeholder: 'http://localhost:9200'
.help-block
The url to use for connecting to Elasticsearch. Use a comma-separated list to support clustering (e.g., "http://localhost:9200, http://localhost:9201").
%fieldset
%legend Elasticsearch AWS IAM credentials
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_aws do
= f.check_box :elasticsearch_aws
Using AWS hosted Elasticsearch with IAM credentials
.form-group
= f.label :elasticsearch_aws_region, 'AWS region', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_aws_region, value: @application_setting.elasticsearch_aws_region, class: 'form-control'
.help-block
Region that elasticsearch is configured
.form-group
= f.label :elasticsearch_aws_access_key, 'AWS Access Key', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_aws_access_key, value: @application_setting.elasticsearch_aws_access_key, class: 'form-control'
.help-block
AWS Access Key. Only required if not using role instance credentials
.form-group
= f.label :elasticsearch_aws_secret_access_key, 'AWS Secret Access Key', class: 'control-label col-sm-2'
.col-sm-10
= f.password_field :elasticsearch_aws_secret_access_key, value: @application_setting.elasticsearch_aws_secret_access_key, class: 'form-control'
.help-block
AWS Secret Access Key. Only required if not using role instance credentials
......@@ -460,64 +460,7 @@
.help-block
If you got a lot of false alarms from repository checks you can choose to clear all repository check information from the database.
%fieldset
%legend Elasticsearch
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_indexing do
= f.check_box :elasticsearch_indexing
Elasticsearch indexing
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_experimental_indexer do
= f.check_box :elasticsearch_experimental_indexer
Use experimental repository indexer
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_search do
= f.check_box :elasticsearch_search
Search with Elasticsearch enabled
.form-group
= f.label :elasticsearch_url, 'URL', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_url, value: @application_setting.elasticsearch_url.join(', '), class: 'form-control', placeholder: 'http://localhost:9200'
.help-block
The url to use for connecting to Elasticsearch. Use a comma-separated list to support clustering (e.g., "http://localhost:9200, http://localhost:9201").
%fieldset
%legend Elasticsearch AWS IAM credentials
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :elasticsearch_aws do
= f.check_box :elasticsearch_aws
Using AWS hosted Elasticsearch with IAM credentials
.form-group
= f.label :elasticsearch_aws_region, 'AWS region', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_aws_region, value: @application_setting.elasticsearch_aws_region, class: 'form-control'
.help-block
Region that elasticsearch is configured
.form-group
= f.label :elasticsearch_aws_access_key, 'AWS Access Key', class: 'control-label col-sm-2'
.col-sm-10
= f.text_field :elasticsearch_aws_access_key, value: @application_setting.elasticsearch_aws_access_key, class: 'form-control'
.help-block
AWS Access Key. Only required if not using role instance credentials
.form-group
= f.label :elasticsearch_aws_secret_access_key, 'AWS Secret Access Key', class: 'control-label col-sm-2'
.col-sm-10
= f.password_field :elasticsearch_aws_secret_access_key, value: @application_setting.elasticsearch_aws_secret_access_key, class: 'form-control'
.help-block
AWS Secret Access Key. Only required if not using role instance credentials
= render partial: 'elasticsearch_form', locals: { f: f }
%fieldset
%legend Koding
......
......@@ -10,6 +10,10 @@ module Gitlab
Error = Class.new(StandardError)
def self.experimental_indexer_present?
Gitlab::Utils.which(EXPERIMENTAL_INDEXER).present?
end
attr_reader :project
def initialize(project)
......@@ -46,7 +50,7 @@ module Gitlab
end
def path_to_indexer
if current_application_settings.elasticsearch_experimental_indexer?
if current_application_settings.elasticsearch_experimental_indexer? && self.class.experimental_indexer_present?
EXPERIMENTAL_INDEXER
else
Rails.root.join('bin', 'elastic_repo_indexer').to_s
......
......@@ -27,5 +27,22 @@ module Gitlab
rescue ArgumentError
size
end
# See: http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def which(cmd, env = ENV)
exts = env['PATHEXT'] ? env['PATHEXT'].split(';') : ['']
env['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
nil
end
end
end
......@@ -86,12 +86,20 @@ describe Gitlab::Elastic::Indexer do
end
end
context 'experimental indexer present' do
context 'experimental indexer enabled' do
before do
stub_application_setting(elasticsearch_experimental_indexer: true)
end
it 'uses the experimental indexer' do
it 'uses the normal indexer when not present' do
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)
indexer.run
end
it 'uses the experimental indexer when present' do
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)
indexer.run
......
require 'spec_helper'
describe Gitlab::Utils, lib: true do
delegate :to_boolean, to: :described_class
delegate :to_boolean, :which, to: :described_class
describe '.to_boolean' do
it 'accepts booleans' do
......@@ -30,4 +32,12 @@ describe Gitlab::Utils, lib: true do
expect(to_boolean(nil)).to be_nil
end
end
describe '.which' do
it 'finds the full path to an executable binary' do
expect(File).to receive(:executable?).with('/bin/sh').and_return(true)
expect(which('sh', 'PATH' => '/bin')).to eq('/bin/sh')
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