Commit a467ac15 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'always-use-utc-for-indices' into 'master'

Advanced Search: Always use UTC for index names

See merge request gitlab-org/gitlab!78402
parents eeceb35f c8676585
...@@ -61,6 +61,10 @@ module Gitlab ...@@ -61,6 +61,10 @@ module Gitlab
"#{target_name}-migrations" "#{target_name}-migrations"
end end
def index_name_with_timestamp(alias_name)
"#{alias_name}-#{Time.now.utc.strftime('%Y%m%d-%H%M')}"
end
def create_migrations_index def create_migrations_index
settings = { number_of_shards: 1 } settings = { number_of_shards: 1 }
mappings = { mappings = {
...@@ -114,7 +118,7 @@ module Gitlab ...@@ -114,7 +118,7 @@ module Gitlab
proxies = standalone_indices_proxies(target_classes: target_classes) proxies = standalone_indices_proxies(target_classes: target_classes)
proxies.each_with_object({}) do |proxy, indices| proxies.each_with_object({}) do |proxy, indices|
alias_name = proxy.index_name alias_name = proxy.index_name
new_index_name = "#{alias_name}-#{Time.now.strftime("%Y%m%d-%H%M")}" new_index_name = index_name_with_timestamp(alias_name)
create_index(new_index_name, alias_name, with_alias, proxy.settings.to_hash, proxy.mappings.to_hash, options) create_index(new_index_name, alias_name, with_alias, proxy.settings.to_hash, proxy.mappings.to_hash, options)
indices[new_index_name] = alias_name indices[new_index_name] = alias_name
......
...@@ -63,6 +63,14 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do ...@@ -63,6 +63,14 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do
end end
end end
describe '#index_name_with_timestamp', time_travel_to: '2022-01-02 10:30:45 -0700' do
subject { helper.index_name_with_timestamp('gitlab-production') }
it 'returns correct index name' do
is_expected.to eq('gitlab-production-20220102-1730')
end
end
describe '#create_migrations_index' do describe '#create_migrations_index' do
after do after do
helper.delete_migrations_index helper.delete_migrations_index
......
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