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
ea252b0c
Commit
ea252b0c
authored
Apr 30, 2021
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix API elasticsearch settings update
parent
257c13c4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
13 deletions
+64
-13
ee/app/models/elastic/index_setting.rb
ee/app/models/elastic/index_setting.rb
+13
-0
ee/app/services/ee/application_settings/update_service.rb
ee/app/services/ee/application_settings/update_service.rb
+19
-9
ee/app/views/admin/application_settings/_elasticsearch_form.html.haml
.../admin/application_settings/_elasticsearch_form.html.haml
+2
-4
ee/changelogs/unreleased/329669-fix-update-elasticsearch-settings-by-api.yml
...eased/329669-fix-update-elasticsearch-settings-by-api.yml
+5
-0
ee/spec/services/application_settings/update_service_spec.rb
ee/spec/services/application_settings/update_service_spec.rb
+25
-0
No files found.
ee/app/models/elastic/index_setting.rb
View file @
ea252b0c
...
...
@@ -26,6 +26,19 @@ module Elastic
def
number_of_shards
default
.
number_of_shards
end
def
every_alias
aliases
.
each
do
|
alias_name
|
yield
self
[
alias_name
]
end
end
private
def
aliases
helper
=
Gitlab
::
Elastic
::
Helper
.
default
[
helper
.
target_name
]
+
helper
.
standalone_indices_proxies
.
map
(
&
:index_name
)
end
end
end
end
ee/app/services/ee/application_settings/update_service.rb
View file @
ea252b0c
...
...
@@ -51,6 +51,7 @@ module EE
def
update_elasticsearch_index_settings
(
number_of_replicas
:,
number_of_shards
:)
return
if
number_of_replicas
.
nil?
&&
number_of_shards
.
nil?
if
number_of_shards
&
.
respond_to?
(
:to_h
)
number_of_shards
.
to_h
.
each
do
|
index_name
,
shards
|
replicas
=
number_of_replicas
[
index_name
]
...
...
@@ -61,6 +62,15 @@ module EE
number_of_shards:
shards
.
to_i
)
end
else
# This method still receives non-hash values from API
Elastic
::
IndexSetting
.
every_alias
do
|
setting
|
setting
.
update!
(
number_of_replicas:
number_of_replicas
||
setting
.
number_of_replicas
,
number_of_shards:
number_of_shards
||
setting
.
number_of_shards
)
end
end
end
private
...
...
ee/app/views/admin/application_settings/_elasticsearch_form.html.haml
View file @
ea252b0c
...
...
@@ -80,11 +80,9 @@
%th
=
_
(
'Number of shards'
)
%th
=
_
(
'Number of replicas'
)
%tbody
-
aliases
=
[
elastic_helper
.
target_name
]
+
elastic_helper
.
standalone_indices_proxies
.
map
(
&
:index_name
)
-
aliases
.
each
do
|
alias_name
|
-
Elastic
::
IndexSetting
.
every_alias
do
|
setting
|
%tr
-
setting
=
Elastic
::
IndexSetting
[
alias_name
]
%td
=
alias_name
%td
=
setting
.
alias_name
%td
=
f
.
number_field
:elasticsearch_shards
,
name:
"application_setting[elasticsearch_shards][
#{
setting
.
alias_name
}
]"
,
value:
setting
.
number_of_shards
,
class:
'form-control gl-form-input'
,
id:
"application_setting_elasticsearch_shards[
#{
setting
.
alias_name
}
]"
%td
...
...
ee/changelogs/unreleased/329669-fix-update-elasticsearch-settings-by-api.yml
0 → 100644
View file @
ea252b0c
---
title
:
Fix API elasticsearch settings update
merge_request
:
60740
author
:
type
:
fixed
ee/spec/services/application_settings/update_service_spec.rb
View file @
ea252b0c
...
...
@@ -170,6 +170,31 @@ RSpec.describe ApplicationSettings::UpdateService do
end
end
end
context
'setting number_of_shards and number_of_replicas'
do
let
(
:alias_name
)
{
'alias-name'
}
it
'accepts hash values'
do
opts
=
{
elasticsearch_shards:
{
alias_name
=>
10
},
elasticsearch_replicas:
{
alias_name
=>
2
}
}
described_class
.
new
(
setting
,
user
,
opts
).
execute
setting
=
Elastic
::
IndexSetting
[
alias_name
]
expect
(
setting
.
number_of_shards
).
to
eq
(
10
)
expect
(
setting
.
number_of_replicas
).
to
eq
(
2
)
end
it
'accepts legacy (integer) values'
do
opts
=
{
elasticsearch_shards:
32
,
elasticsearch_replicas:
3
}
described_class
.
new
(
setting
,
user
,
opts
).
execute
Elastic
::
IndexSetting
.
every_alias
do
|
setting
|
expect
(
setting
.
number_of_shards
).
to
eq
(
32
)
expect
(
setting
.
number_of_replicas
).
to
eq
(
3
)
end
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