From 2dd1d6efd95ea730f2c7c051d1f580d5f884ee9d Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Tue, 3 Dec 2024 20:05:00 -0800 Subject: [PATCH] Move search index name to a central config location. --- app/models/gem_download.rb | 2 +- config/application.rb | 2 +- config/deploy/web.yaml.erb | 2 ++ test/helpers/es_helper.rb | 2 +- test/models/deletion_test.rb | 3 +-- test/models/pusher_test.rb | 6 ++---- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/models/gem_download.rb b/app/models/gem_download.rb index 8462392ec01..237f3e98441 100644 --- a/app/models/gem_download.rb +++ b/app/models/gem_download.rb @@ -135,7 +135,7 @@ def downloads_by_gem(rubygem_ids) end def update_query(id, downloads, version_downloads) - { update: { _index: "rubygems-#{Rails.env}", + { update: { _index: Gemcutter::SEARCH_INDEX_NAME, _id: id, data: { doc: { downloads: downloads, version_downloads: version_downloads } } } } end diff --git a/config/application.rb b/config/application.rb index 3acc35c0dd2..b29ece2ca6e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -98,7 +98,7 @@ def self.config POPULAR_DAYS_LIMIT = 70.days PROTOCOL = config["protocol"] REMEMBER_FOR = 2.weeks - SEARCH_INDEX_NAME = "rubygems-#{Rails.env}".freeze + SEARCH_INDEX_NAME = ENV.fetch("SEARCH_INDEX_NAME", "rubygems-#{Rails.env}".freeze) SEARCH_NUM_REPLICAS = ENV.fetch("SEARCH_NUM_REPLICAS", 1).to_i SEARCH_MAX_PAGES = 100 # Limit max page as ES result window is upper bounded by 10_000 records STATS_MAX_PAGES = 10 diff --git a/config/deploy/web.yaml.erb b/config/deploy/web.yaml.erb index c9e4f42feef..d9110e5ccf9 100644 --- a/config/deploy/web.yaml.erb +++ b/config/deploy/web.yaml.erb @@ -139,6 +139,8 @@ spec: key: elasticsearch_url - name: SEARCH_NUM_REPLICAS value: "<%= environment == 'production' ? 2 : 1 %>" + - name: SEARCH_INDEX_NAME + value: "rubygems-<%= environment %>" - name: MEMCACHED_ENDPOINT valueFrom: secretKeyRef: diff --git a/test/helpers/es_helper.rb b/test/helpers/es_helper.rb index 47552fd0548..396ccb7f67d 100644 --- a/test/helpers/es_helper.rb +++ b/test/helpers/es_helper.rb @@ -18,6 +18,6 @@ def es_version_downloads(id) def get_response(id) Rubygem.searchkick_index.refresh - Searchkick.client.get index: "rubygems-#{Rails.env}", id: id + Searchkick.client.get index: Gemcutter::SEARCH_INDEX_NAME, id: id end end diff --git a/test/models/deletion_test.rb b/test/models/deletion_test.rb index 032f82c923c..81c5363d88f 100644 --- a/test/models/deletion_test.rb +++ b/test/models/deletion_test.rb @@ -160,8 +160,7 @@ class DeletionTest < ActiveSupport::TestCase perform_enqueued_jobs - response = Searchkick.client.get index: "rubygems-#{Rails.env}", - id: @version.rubygem_id + response = Searchkick.client.get index: Gemcutter::SEARCH_INDEX_NAME, id: @version.rubygem_id assert response["_source"]["yanked"] end diff --git a/test/models/pusher_test.rb b/test/models/pusher_test.rb index 14fd53443cd..3e2e409af67 100644 --- a/test/models/pusher_test.rb +++ b/test/models/pusher_test.rb @@ -627,8 +627,7 @@ def two_cert_chain(signing_key:, root_not_before: Time.current, cert_not_before: should "create rubygem index" do @rubygem.update_column("updated_at", Date.new(2016, 07, 04)) perform_enqueued_jobs only: ReindexRubygemJob - response = Searchkick.client.get index: "rubygems-#{Rails.env}", - id: @rubygem.id + response = Searchkick.client.get index: Gemcutter::SEARCH_INDEX_NAME, id: @rubygem.id expected_response = { "name" => "gemsgemsgems", "downloads" => 0, @@ -733,8 +732,7 @@ def two_cert_chain(signing_key:, root_not_before: Time.current, cert_not_before: should "update rubygem index" do perform_enqueued_jobs only: ReindexRubygemJob - response = Searchkick.client.get index: "rubygems-#{Rails.env}", - id: @rubygem.id + response = Searchkick.client.get index: Gemcutter::SEARCH_INDEX_NAME, id: @rubygem.id assert_equal "new summary", response["_source"]["summary"] end