Commit c3626715 authored by Mark Florian's avatar Mark Florian

Merge branch '329669-fix-update-elasticsearch-settings-by-api' into 'master'

Fix API elasticsearch settings update

See merge request gitlab-org/gitlab!60740
parents 19c87e94 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
......@@ -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
......
......@@ -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
......
---
title: Fix API elasticsearch settings update
merge_request: 60740
author:
type: fixed
......@@ -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
......
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