Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a32fc5f3
Commit
a32fc5f3
authored
Apr 12, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only use the experimental elasticsearch indexer if it is present
parent
c13ff72c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
6 deletions
+48
-6
app/views/admin/application_settings/_elasticsearch_form.html.haml
.../admin/application_settings/_elasticsearch_form.html.haml
+5
-2
lib/gitlab/elastic/indexer.rb
lib/gitlab/elastic/indexer.rb
+5
-1
lib/gitlab/utils.rb
lib/gitlab/utils.rb
+17
-0
spec/lib/gitlab/elastic/indexer_spec.rb
spec/lib/gitlab/elastic/indexer_spec.rb
+10
-2
spec/lib/gitlab/utils_spec.rb
spec/lib/gitlab/utils_spec.rb
+11
-1
No files found.
app/views/admin/application_settings/_elasticsearch_form.html.haml
View file @
a32fc5f3
...
@@ -7,12 +7,15 @@
...
@@ -7,12 +7,15 @@
=
f
.
check_box
:elasticsearch_indexing
=
f
.
check_box
:elasticsearch_indexing
Elasticsearch indexing
Elasticsearch indexing
-
missing
=
!
Gitlab
::
Elastic
::
Indexer
.
experimental_indexer_present?
.form-group
.form-group
.col-sm-offset-2.col-sm-10
.col-sm-offset-2.col-sm-10
.checkbox
.checkbox
=
f
.
label
:elasticsearch_experimental_indexer
do
=
f
.
label
:elasticsearch_experimental_indexer
do
=
f
.
check_box
:elasticsearch_experimental_indexer
=
f
.
check_box
:elasticsearch_experimental_indexer
,
disabled:
missing
Use experimental repository indexer
Use
<a
href=
"https://gitlab.com/gitlab-org/gitlab-elasticsearch-indexer"
>
experimental repository indexer
</a>
-
if
missing
(not installed)
.form-group
.form-group
.col-sm-offset-2.col-sm-10
.col-sm-offset-2.col-sm-10
...
...
lib/gitlab/elastic/indexer.rb
View file @
a32fc5f3
...
@@ -10,6 +10,10 @@ module Gitlab
...
@@ -10,6 +10,10 @@ module Gitlab
Error
=
Class
.
new
(
StandardError
)
Error
=
Class
.
new
(
StandardError
)
def
self
.
experimental_indexer_present?
Gitlab
::
Utils
.
which
(
EXPERIMENTAL_INDEXER
).
present?
end
attr_reader
:project
attr_reader
:project
def
initialize
(
project
)
def
initialize
(
project
)
...
@@ -46,7 +50,7 @@ module Gitlab
...
@@ -46,7 +50,7 @@ module Gitlab
end
end
def
path_to_indexer
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
EXPERIMENTAL_INDEXER
else
else
Rails
.
root
.
join
(
'bin'
,
'elastic_repo_indexer'
).
to_s
Rails
.
root
.
join
(
'bin'
,
'elastic_repo_indexer'
).
to_s
...
...
lib/gitlab/utils.rb
View file @
a32fc5f3
...
@@ -27,5 +27,22 @@ module Gitlab
...
@@ -27,5 +27,22 @@ module Gitlab
rescue
ArgumentError
rescue
ArgumentError
size
size
end
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
end
end
spec/lib/gitlab/elastic/indexer_spec.rb
View file @
a32fc5f3
...
@@ -86,12 +86,20 @@ describe Gitlab::Elastic::Indexer do
...
@@ -86,12 +86,20 @@ describe Gitlab::Elastic::Indexer do
end
end
end
end
context
'experimental indexer
present
'
do
context
'experimental indexer
enabled
'
do
before
do
before
do
stub_application_setting
(
elasticsearch_experimental_indexer:
true
)
stub_application_setting
(
elasticsearch_experimental_indexer:
true
)
end
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
)
expect_popen
.
with
([
'gitlab-elasticsearch-indexer'
,
anything
,
anything
],
anything
,
anything
).
and_return
(
popen_success
)
indexer
.
run
indexer
.
run
...
...
spec/lib/gitlab/utils_spec.rb
View file @
a32fc5f3
require
'spec_helper'
describe
Gitlab
::
Utils
,
lib:
true
do
describe
Gitlab
::
Utils
,
lib:
true
do
delegate
:to_boolean
,
to: :described_class
delegate
:to_boolean
,
:which
,
to: :described_class
describe
'.to_boolean'
do
describe
'.to_boolean'
do
it
'accepts booleans'
do
it
'accepts booleans'
do
...
@@ -30,4 +32,12 @@ describe Gitlab::Utils, lib: true do
...
@@ -30,4 +32,12 @@ describe Gitlab::Utils, lib: true do
expect
(
to_boolean
(
nil
)).
to
be_nil
expect
(
to_boolean
(
nil
)).
to
be_nil
end
end
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
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment