From d50f4f1ca6f352b367a20696f7264bf8a1302ceb Mon Sep 17 00:00:00 2001 From: Terri Chu <tchu@gitlab.com> Date: Mon, 8 Apr 2024 03:59:59 +0000 Subject: [PATCH] Remove search_index_all_projects FF Changelog: other EE: true --- .../development/search_index_all_projects.yml | 8 -- .../advanced_search/elasticsearch.md | 8 +- .../concerns/elastic/projects_search.rb | 2 - .../models/elasticsearch_indexed_project.rb | 5 +- .../elastic/project_transfer_worker.rb | 9 +- .../workers/elastic_commit_indexer_worker.rb | 2 +- .../elastic_namespace_indexer_worker.rb | 3 +- ee/app/workers/elastic_wiki_indexer_worker.rb | 2 +- .../models/concerns/elastic/project_spec.rb | 105 ++++-------------- .../elasticsearch_indexed_project_spec.rb | 93 ++++------------ .../search/rake_task_executor_service_spec.rb | 12 -- .../elastic/project_transfer_worker_spec.rb | 54 +++------ .../elastic_commit_indexer_worker_spec.rb | 68 +++--------- .../elastic_namespace_indexer_worker_spec.rb | 13 --- .../elastic_wiki_indexer_worker_spec.rb | 81 +++----------- 15 files changed, 97 insertions(+), 368 deletions(-) delete mode 100644 config/feature_flags/development/search_index_all_projects.yml diff --git a/config/feature_flags/development/search_index_all_projects.yml b/config/feature_flags/development/search_index_all_projects.yml deleted file mode 100644 index ad81dde6f6e2..000000000000 --- a/config/feature_flags/development/search_index_all_projects.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: search_index_all_projects -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/134456 -rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/432489 -milestone: '16.7' -type: development -group: group::global search -default_enabled: true diff --git a/doc/integration/advanced_search/elasticsearch.md b/doc/integration/advanced_search/elasticsearch.md index 763c2573e0b7..1ffec71b7ea9 100644 --- a/doc/integration/advanced_search/elasticsearch.md +++ b/doc/integration/advanced_search/elasticsearch.md @@ -399,13 +399,7 @@ from the Elasticsearch index as expected. #### All project records are indexed > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/428070) in GitLab 16.7 [with a flag](../../administration/feature_flags.md) named `search_index_all_projects`. Disabled by default. -> - [Enabled on GitLab.com](https://gitlab.com/gitlab-org/gitlab/-/issues/432489) in GitLab 16.9. -> - [Enabled on self-managed](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/145300) in GitLab 16.10. - -FLAG: -On self-managed GitLab, by default this feature is available. -To hide the feature, an administrator can [disable the feature flag](../../administration/feature_flags.md) named `search_index_all_projects`. -On GitLab.com, this feature is available. On GitLab Dedicated, this feature is not available. +> - [Generally available](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/148111) in GitLab 16.11. Feature flag `search_index_all_projects` removed. When you select the **Limit the amount of namespace and project data to index** checkbox: diff --git a/ee/app/models/concerns/elastic/projects_search.rb b/ee/app/models/concerns/elastic/projects_search.rb index e5b85b0964e2..e6db944ae972 100644 --- a/ee/app/models/concerns/elastic/projects_search.rb +++ b/ee/app/models/concerns/elastic/projects_search.rb @@ -22,8 +22,6 @@ def maintaining_indexed_associations? override :maintaining_elasticsearch? def maintaining_elasticsearch? - return super if ::Feature.disabled?(:search_index_all_projects, root_namespace) - ::Gitlab::CurrentSettings.elasticsearch_indexing? end diff --git a/ee/app/models/elasticsearch_indexed_project.rb b/ee/app/models/elasticsearch_indexed_project.rb index 2cd68a926bd8..a7b47d42ec22 100644 --- a/ee/app/models/elasticsearch_indexed_project.rb +++ b/ee/app/models/elasticsearch_indexed_project.rb @@ -25,8 +25,7 @@ def index def delete_from_index return unless Gitlab::CurrentSettings.elasticsearch_indexing? - # do not delete the project document if indexing for all projects is enabled for the project - delete_project = ::Feature.disabled?(:search_index_all_projects, project.root_namespace) - ElasticDeleteProjectWorker.perform_async(project.id, project.es_id, delete_project: delete_project) + # project documents are indexed regardless of limit settings + ElasticDeleteProjectWorker.perform_async(project.id, project.es_id, delete_project: false) end end diff --git a/ee/app/workers/elastic/project_transfer_worker.rb b/ee/app/workers/elastic/project_transfer_worker.rb index ae14032ae55e..147126319a01 100644 --- a/ee/app/workers/elastic/project_transfer_worker.rb +++ b/ee/app/workers/elastic/project_transfer_worker.rb @@ -31,13 +31,10 @@ def perform(project_id, old_namespace_id, new_namespace_id) delete_old_project(project, old_namespace_id) elsif should_invalidate_elasticsearch_indexes_cache && ::Gitlab::CurrentSettings.elasticsearch_indexing? - # If the new namespace isn't indexed, the project should no longer exist in the index - # and will be deleted asynchronously. If all projects are indexed, queue the project for indexing + # If the new namespace isn't indexed, the project's associated records should no longer exist in the index + # and will be deleted asynchronously. Queue the project for indexing # to update the namespace field and remove the old document from the index. - - keep_project_in_index = ::Feature.enabled?(:search_index_all_projects, project.root_namespace) - - ::Elastic::ProcessInitialBookkeepingService.track!(build_document_reference(project)) if keep_project_in_index + ::Elastic::ProcessInitialBookkeepingService.track!(build_document_reference(project)) delete_old_project(project, old_namespace_id) end diff --git a/ee/app/workers/elastic_commit_indexer_worker.rb b/ee/app/workers/elastic_commit_indexer_worker.rb index 157b5e8af21b..19f17abf61a4 100644 --- a/ee/app/workers/elastic_commit_indexer_worker.rb +++ b/ee/app/workers/elastic_commit_indexer_worker.rb @@ -32,7 +32,7 @@ def perform(project_id, wiki = false, options = {}) @project = Project.find_by_id(project_id) unless @project&.use_elasticsearch? es_id = ::Gitlab::Elastic::Helper.build_es_id(es_type: Project.es_type, target_id: project_id) - delete_project = @project.nil? || ::Feature.disabled?(:search_index_all_projects, @project.root_namespace) + delete_project = @project.nil? ElasticDeleteProjectWorker.perform_async(project_id, es_id, delete_project: delete_project) return true end diff --git a/ee/app/workers/elastic_namespace_indexer_worker.rb b/ee/app/workers/elastic_namespace_indexer_worker.rb index df388b72ef70..2b603a7b9458 100644 --- a/ee/app/workers/elastic_namespace_indexer_worker.rb +++ b/ee/app/workers/elastic_namespace_indexer_worker.rb @@ -50,9 +50,8 @@ def index_group_associations(namespace) end def delete_from_index(namespace) - delete_project = ::Feature.disabled?(:search_index_all_projects, namespace.root_ancestor) namespace.all_projects.find_in_batches do |batch| - args = batch.map { |project| [project.id, project.es_id, { delete_project: delete_project }] } + args = batch.map { |project| [project.id, project.es_id, { delete_project: false }] } ElasticDeleteProjectWorker.bulk_perform_async(args) # rubocop:disable Scalability/BulkPerformWithContext end diff --git a/ee/app/workers/elastic_wiki_indexer_worker.rb b/ee/app/workers/elastic_wiki_indexer_worker.rb index 5b19e23b33bb..92ed5ba322dd 100644 --- a/ee/app/workers/elastic_wiki_indexer_worker.rb +++ b/ee/app/workers/elastic_wiki_indexer_worker.rb @@ -88,7 +88,7 @@ def cleanup_container_elastic_documents(container, container_id, container_type) end if container_type == 'Project' - delete_project = container.nil? || ::Feature.disabled?(:search_index_all_projects, container.root_namespace) + delete_project = container.nil? ElasticDeleteProjectWorker.perform_async( container_id, diff --git a/ee/spec/models/concerns/elastic/project_spec.rb b/ee/spec/models/concerns/elastic/project_spec.rb index 1410ff4b3df4..8d4eb5f7f88d 100644 --- a/ee/spec/models/concerns/elastic/project_spec.rb +++ b/ee/spec/models/concerns/elastic/project_spec.rb @@ -20,17 +20,7 @@ describe '#maintaining_elasticsearch?' do subject(:maintaining_elasticsearch) { project.maintaining_elasticsearch? } - context 'when the search_index_all_projects FF is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it { is_expected.to be(false) } - end - - context 'when the search_index_all_projects FF is true' do - it { is_expected.to be(true) } - end + it { is_expected.to be(true) } end describe '#use_elasticsearch?' do @@ -48,17 +38,7 @@ describe '#maintaining_elasticsearch?' do subject(:maintaining_elasticsearch) { project.maintaining_elasticsearch? } - context 'when the search_index_all_projects FF is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it { is_expected.to be(true) } - end - - context 'when the search_index_all_projects FF is true' do - it { is_expected.to be(true) } - end + it { is_expected.to be(true) } end describe '#use_elasticsearch?' do @@ -68,28 +48,12 @@ end describe 'indexing', :sidekiq_inline do - context 'when the search_index_all_projects FF is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it 'only indexes enabled projects' do - create(:project, :empty_repo, path: 'test_two', description: 'awesome project') - ensure_elasticsearch_index! - - expect(described_class.elastic_search('main_project', options: { project_ids: :any }).total_count).to eq(1) - expect(described_class.elastic_search('"test_two"', options: { project_ids: :any }).total_count).to eq(0) - end - end + it 'indexes all projects' do + create(:project, :empty_repo, path: 'test_two', description: 'awesome project') + ensure_elasticsearch_index! - context 'when the search_index_all_projects FF is true' do - it 'indexes all projects' do - create(:project, :empty_repo, path: 'test_two', description: 'awesome project') - ensure_elasticsearch_index! - - expect(described_class.elastic_search('main_project', options: { project_ids: :any }).total_count).to eq(1) - expect(described_class.elastic_search('"test_two"', options: { project_ids: :any }).total_count).to eq(1) - end + expect(described_class.elastic_search('main_project', options: { project_ids: :any }).total_count).to eq(1) + expect(described_class.elastic_search('"test_two"', options: { project_ids: :any }).total_count).to eq(1) end end end @@ -106,48 +70,19 @@ subject(:maintaining_elasticsearch) { project_in_group.maintaining_elasticsearch? } - context 'when the search_index_all_projects FF is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it { is_expected.to be(true) } - end - - context 'when the search_index_all_projects FF is true' do - it { is_expected.to be(true) } - end + it { is_expected.to be(true) } end describe 'indexing' do - context 'when the search_index_all_projects FF is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it 'indexes only projects under the group' do - create(:project, name: 'group_test1', group: create(:group, parent: group)) - create(:project, name: 'group_test2', description: 'awesome project') - create(:project, name: 'group_test3', group: group) - ensure_elasticsearch_index! - - expect(described_class.elastic_search('group_test*', options: { project_ids: :any }).total_count).to eq(2) - expect(described_class.elastic_search('"group_test3"', options: { project_ids: :any }).total_count).to eq(1) - expect(described_class.elastic_search('"group_test2"', options: { project_ids: :any }).total_count).to eq(0) - end - end - - context 'when the search_index_all_projects FF is true' do - it 'indexes all projects' do - create(:project, name: 'group_test1', group: create(:group, parent: group)) - create(:project, name: 'group_test2', description: 'awesome project') - create(:project, name: 'group_test3', group: group) - ensure_elasticsearch_index! - - expect(described_class.elastic_search('group_test*', options: { project_ids: :any }).total_count).to eq(3) - expect(described_class.elastic_search('"group_test3"', options: { project_ids: :any }).total_count).to eq(1) - expect(described_class.elastic_search('"group_test2"', options: { project_ids: :any }).total_count).to eq(1) - end + it 'indexes all projects' do + create(:project, name: 'group_test1', group: create(:group, parent: group)) + create(:project, name: 'group_test2', description: 'awesome project') + create(:project, name: 'group_test3', group: group) + ensure_elasticsearch_index! + + expect(described_class.elastic_search('group_test*', options: { project_ids: :any }).total_count).to eq(3) + expect(described_class.elastic_search('"group_test3"', options: { project_ids: :any }).total_count).to eq(1) + expect(described_class.elastic_search('"group_test2"', options: { project_ids: :any }).total_count).to eq(1) end end @@ -177,7 +112,8 @@ raise ArgumentError, 'Invalid operator' end - expect(described_class.elastic_search('test foo', options: { project_ids: :any }).total_count).to eq(expected_count) + expect(described_class.elastic_search('test foo', + options: { project_ids: :any }).total_count).to eq(expected_count) end end @@ -233,7 +169,8 @@ expect(described_class.elastic_search('"awesome"', options: { project_ids: project_ids }).total_count).to eq(1) expect(described_class.elastic_search('test*', options: { project_ids: project_ids }).total_count).to eq(2) expect(described_class.elastic_search('test*', options: { project_ids: :any }).total_count).to eq(3) - expect(described_class.elastic_search('"someone_elses_project"', options: { project_ids: project_ids }).total_count).to eq(0) + expect(described_class.elastic_search('"someone_elses_project"', + options: { project_ids: project_ids }).total_count).to eq(0) end it 'finds partial matches in project names', :sidekiq_inline do diff --git a/ee/spec/models/elasticsearch_indexed_project_spec.rb b/ee/spec/models/elasticsearch_indexed_project_spec.rb index 32970bea1281..25d7767b2383 100644 --- a/ee/spec/models/elasticsearch_indexed_project_spec.rb +++ b/ee/spec/models/elasticsearch_indexed_project_spec.rb @@ -18,86 +18,37 @@ expect(Elastic::ProcessBookkeepingService).to receive(:track!).with(project) end - context 'when search_index_all_projects is true' do - before do - stub_feature_flags(search_index_all_projects: true) - end - - let(:delete_action) do - expect(ElasticDeleteProjectWorker).to receive(:perform_async) - .with(project.id, project.es_id, delete_project: false) - end - - it_behaves_like 'an elasticsearch indexed container' do - context 'when elasticsearch_indexing is false' do - before do - stub_ee_application_setting(elasticsearch_indexing: false) - end - - describe 'callbacks' do - describe 'on save' do - subject(:elasticsearch_indexed_project) { build(container, container_attributes) } - - it 'triggers index but does not index the data' do - is_expected.to receive(:index) - expect(Elastic::ProcessBookkeepingService).not_to receive(:track!) - - elasticsearch_indexed_project.save! - end - end - - describe 'on destroy' do - subject(:elasticsearch_indexed_project) { create(container, container_attributes) } - - it 'triggers delete_from_index but does not delete data from index' do - is_expected.to receive(:delete_from_index) - expect(ElasticDeleteProjectWorker).not_to receive(:perform_async) - - elasticsearch_indexed_project.destroy! - end - end - end - end - end + let(:delete_action) do + expect(ElasticDeleteProjectWorker).to receive(:perform_async) + .with(project.id, project.es_id, delete_project: false) end - context 'when search_index_all_projects is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - let(:delete_action) do - expect(ElasticDeleteProjectWorker).to receive(:perform_async) - .with(project.id, project.es_id, delete_project: true) - end - - it_behaves_like 'an elasticsearch indexed container' do - context 'when elasticsearch_indexing is false' do - before do - stub_ee_application_setting(elasticsearch_indexing: false) - end + it_behaves_like 'an elasticsearch indexed container' do + context 'when elasticsearch_indexing is false' do + before do + stub_ee_application_setting(elasticsearch_indexing: false) + end - describe 'callbacks' do - describe 'on save' do - subject(:elasticsearch_indexed_project) { build(container, container_attributes) } + describe 'callbacks' do + describe 'on save' do + subject(:elasticsearch_indexed_project) { build(container, container_attributes) } - it 'triggers index but does not index the data' do - is_expected.to receive(:index) - expect(Elastic::ProcessBookkeepingService).not_to receive(:track!) + it 'triggers index but does not index the data' do + is_expected.to receive(:index) + expect(Elastic::ProcessBookkeepingService).not_to receive(:track!) - elasticsearch_indexed_project.save! - end + elasticsearch_indexed_project.save! end + end - describe 'on destroy' do - subject(:elasticsearch_indexed_project) { create(container, container_attributes) } + describe 'on destroy' do + subject(:elasticsearch_indexed_project) { create(container, container_attributes) } - it 'triggers delete_from_index but does not delete data from index' do - is_expected.to receive(:delete_from_index) - expect(ElasticDeleteProjectWorker).not_to receive(:perform_async) + it 'triggers delete_from_index but does not delete data from index' do + is_expected.to receive(:delete_from_index) + expect(ElasticDeleteProjectWorker).not_to receive(:perform_async) - elasticsearch_indexed_project.destroy! - end + elasticsearch_indexed_project.destroy! end end end diff --git a/ee/spec/services/search/rake_task_executor_service_spec.rb b/ee/spec/services/search/rake_task_executor_service_spec.rb index b6c523298621..1cd78a2efc82 100644 --- a/ee/spec/services/search/rake_task_executor_service_spec.rb +++ b/ee/spec/services/search/rake_task_executor_service_spec.rb @@ -316,18 +316,6 @@ stub_ee_application_setting(elasticsearch_limit_indexing: true) end - context 'when the search_index_all_projects feature flag is disabled' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it 'does not queue jobs for projects that should not be indexed' do - expect(Elastic::ProcessInitialBookkeepingService).to receive(:backfill_projects!).with(project1, project3) - - task - end - end - context 'when elasticsearch_indexing is disabled' do before do stub_ee_application_setting(elasticsearch_indexing: false) diff --git a/ee/spec/workers/elastic/project_transfer_worker_spec.rb b/ee/spec/workers/elastic/project_transfer_worker_spec.rb index 7c5608fbe2a9..2d454eb04a44 100644 --- a/ee/spec/workers/elastic/project_transfer_worker_spec.rb +++ b/ee/spec/workers/elastic/project_transfer_worker_spec.rb @@ -71,52 +71,28 @@ create(:elasticsearch_indexed_namespace, namespace: indexed_namespace) end - context 'when search_index_all_projects is true' do - before do - stub_feature_flags(search_index_all_projects: true) - end - - it 'invalidates the cache and removes only the associated data from the index' do - expect(Elastic::ProcessInitialBookkeepingService).to receive(:track!).with(project) - expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:backfill_projects!) - expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(project.id, project.es_id, - namespace_routing_id: project.root_ancestor.id) - expect(::Gitlab::CurrentSettings) - .to receive(:invalidate_elasticsearch_indexes_cache_for_project!) - .with(project.id).and_call_original - - worker.perform(project.id, non_indexed_namespace.id, indexed_namespace.id) - end + it 'invalidates the cache and removes only the associated data from the index' do + expect(Elastic::ProcessInitialBookkeepingService).to receive(:track!).with(project) + expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:backfill_projects!) + expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(project.id, project.es_id, + namespace_routing_id: project.root_ancestor.id) + expect(::Gitlab::CurrentSettings) + .to receive(:invalidate_elasticsearch_indexes_cache_for_project!) + .with(project.id).and_call_original - context 'when the reindex_projects_to_apply_routing migration is not finished' do - before do - set_elasticsearch_migration_to(:reindex_projects_to_apply_routing, including: false) - end - - it 'tracks with a document reference and deletes without namespace_routing_id' do - expect(Elastic::ProcessInitialBookkeepingService).to receive(:track!) - .with(an_instance_of(Gitlab::Elastic::DocumentReference)) - expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:backfill_projects!) - expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(project.id, project.es_id) - expect(::Gitlab::CurrentSettings) - .to receive(:invalidate_elasticsearch_indexes_cache_for_project!) - .with(project.id).and_call_original - - worker.perform(project.id, non_indexed_namespace.id, indexed_namespace.id) - end - end + worker.perform(project.id, non_indexed_namespace.id, indexed_namespace.id) end - context 'when search_index_all_projects is false' do + context 'when the reindex_projects_to_apply_routing migration is not finished' do before do - stub_feature_flags(search_index_all_projects: false) + set_elasticsearch_migration_to(:reindex_projects_to_apply_routing, including: false) end - it 'invalidates the cache and removes the project and associated data from the index' do - expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:track!) + it 'tracks with a document reference and deletes without namespace_routing_id' do + expect(Elastic::ProcessInitialBookkeepingService).to receive(:track!) + .with(an_instance_of(Gitlab::Elastic::DocumentReference)) expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:backfill_projects!) - expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(project.id, project.es_id, - namespace_routing_id: project.root_ancestor.id) + expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(project.id, project.es_id) expect(::Gitlab::CurrentSettings) .to receive(:invalidate_elasticsearch_indexes_cache_for_project!) .with(project.id).and_call_original diff --git a/ee/spec/workers/elastic_commit_indexer_worker_spec.rb b/ee/spec/workers/elastic_commit_indexer_worker_spec.rb index 56200af9b39a..00cb8062de3b 100644 --- a/ee/spec/workers/elastic_commit_indexer_worker_spec.rb +++ b/ee/spec/workers/elastic_commit_indexer_worker_spec.rb @@ -28,66 +28,24 @@ Gitlab::Elastic::Helper.build_es_id(es_type: Project.es_type, target_id: non_existing_record_id) end - context 'when search_index_all_projects is true' do - before do - stub_feature_flags(search_index_all_projects: true) - end - - it 'calls ElasticDeleteProjectWorker on the project to delete all documents and returns true' do - expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(id, es_id, delete_project: true) - expect(Gitlab::Elastic::Indexer).not_to receive(:new) - expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) - expect(worker.perform(id)).to be true - end - end - - context 'when search_index_all_projects is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it 'calls ElasticDeleteProjectWorker on the project to delete all documents and returns true' do - expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(id, es_id, delete_project: true) - expect(Gitlab::Elastic::Indexer).not_to receive(:new) - expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) - expect(worker.perform(id)).to be true - end + it 'calls ElasticDeleteProjectWorker on the project to delete all documents and returns true' do + expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(id, es_id, delete_project: true) + expect(Gitlab::Elastic::Indexer).not_to receive(:new) + expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) + expect(worker.perform(id)).to be true end end context 'when elasticsearch is disabled for Project' do - context 'when search_index_all_projects is true' do - before do - stub_feature_flags(search_index_all_projects: true) - end - - it 'calls ElasticDeleteProjectWorker to keep itself and only delete associated documents and returns true' do - allow_next_found_instance_of(Project) do |project| - expect(project).to receive(:use_elasticsearch?).and_return(false) - end - expect(ElasticDeleteProjectWorker).to receive(:perform_async) - .with(project.id, project.es_id, delete_project: false) - expect(Gitlab::Elastic::Indexer).not_to receive(:new) - expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) - expect(worker.perform(project.id)).to be true - end - end - - context 'when search_index_all_projects is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it 'calls ElasticDeleteProjectWorker on the project to delete all documents and returns true' do - allow_next_found_instance_of(Project) do |project| - expect(project).to receive(:use_elasticsearch?).and_return(false) - end - expect(ElasticDeleteProjectWorker).to receive(:perform_async) - .with(project.id, project.es_id, delete_project: true) - expect(Gitlab::Elastic::Indexer).not_to receive(:new) - expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) - expect(worker.perform(project.id)).to be true + it 'calls ElasticDeleteProjectWorker to keep itself and only delete associated documents and returns true' do + allow_next_found_instance_of(Project) do |project| + expect(project).to receive(:use_elasticsearch?).and_return(false) end + expect(ElasticDeleteProjectWorker).to receive(:perform_async) + .with(project.id, project.es_id, delete_project: false) + expect(Gitlab::Elastic::Indexer).not_to receive(:new) + expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) + expect(worker.perform(project.id)).to be true end end diff --git a/ee/spec/workers/elastic_namespace_indexer_worker_spec.rb b/ee/spec/workers/elastic_namespace_indexer_worker_spec.rb index 71f030c16518..e291c094067b 100644 --- a/ee/spec/workers/elastic_namespace_indexer_worker_spec.rb +++ b/ee/spec/workers/elastic_namespace_indexer_worker_spec.rb @@ -56,19 +56,6 @@ worker.perform(namespace.id, :delete) end - context 'when the search_index_all_projects feature flag is disabled' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it 'deletes all projects belonging to the namespace' do - args = projects.map { |project| [project.id, project.es_id, { delete_project: true }] } - expect(ElasticDeleteProjectWorker).to receive(:bulk_perform_async).with(args) - - worker.perform(namespace.id, :delete) - end - end - it 'does not enqueue Search::ElasticGroupAssociationDeletionWorker' do expect(Search::ElasticGroupAssociationDeletionWorker).not_to receive(:perform_async) diff --git a/ee/spec/workers/elastic_wiki_indexer_worker_spec.rb b/ee/spec/workers/elastic_wiki_indexer_worker_spec.rb index b82b83dba394..567f6efebd3c 100644 --- a/ee/spec/workers/elastic_wiki_indexer_worker_spec.rb +++ b/ee/spec/workers/elastic_wiki_indexer_worker_spec.rb @@ -35,42 +35,17 @@ context 'when container is Project' do context 'when elasticsearch is disabled for Project' do - context 'when search_index_all_projects is true' do - before do - stub_feature_flags(search_index_all_projects: true) + it 'does not remove the project but removes all associated documents from the index' do + allow_next_found_instance_of(Project) do |project| + expect(project).to receive(:use_elasticsearch?).and_return(false) end - it 'does not remove the project but removes all associated documents from the index' do - allow_next_found_instance_of(Project) do |project| - expect(project).to receive(:use_elasticsearch?).and_return(false) - end - - expect(ElasticDeleteProjectWorker).to receive(:perform_async) - .with(project.id, project.es_id, delete_project: false) - expect(Gitlab::Elastic::Indexer).not_to receive(:new) - expect(logger_double).not_to receive(:info) - expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) - expect(worker.perform(project.id, project.class.name)).to be true - end - end - - context 'when search_index_all_projects is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it 'removes the project and all associated documents from the index' do - allow_next_found_instance_of(Project) do |project| - expect(project).to receive(:use_elasticsearch?).and_return(false) - end - - expect(ElasticDeleteProjectWorker).to receive(:perform_async) - .with(project.id, project.es_id, delete_project: true) - expect(Gitlab::Elastic::Indexer).not_to receive(:new) - expect(logger_double).not_to receive(:info) - expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) - expect(worker.perform(project.id, project.class.name)).to be true - end + expect(ElasticDeleteProjectWorker).to receive(:perform_async) + .with(project.id, project.es_id, delete_project: false) + expect(Gitlab::Elastic::Indexer).not_to receive(:new) + expect(logger_double).not_to receive(:info) + expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) + expect(worker.perform(project.id, project.class.name)).to be true end end @@ -153,36 +128,14 @@ Gitlab::Elastic::Helper.build_es_id(es_type: Project.es_type, target_id: non_existing_record_id) end - context 'when search_index_all_projects is false' do - before do - stub_feature_flags(search_index_all_projects: false) - end - - it 'removes the project and all associated documents from the index' do - expect(logger_double).to receive(:warn).with(container_id: id, container_type: Project.name, - message: 'Container record not found') - expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(id, es_id, delete_project: true) - expect(Gitlab::Elastic::Indexer).not_to receive(:new) - expect(logger_double).not_to receive(:info) - expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) - expect(worker.perform(id, Project.name)).to be true - end - end - - context 'when search_index_all_projects is true' do - before do - stub_feature_flags(search_index_all_projects: true) - end - - it 'removes the project and all associated documents from the index' do - expect(logger_double).to receive(:warn).with(container_id: id, container_type: Project.name, - message: 'Container record not found') - expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(id, es_id, delete_project: true) - expect(Gitlab::Elastic::Indexer).not_to receive(:new) - expect(logger_double).not_to receive(:info) - expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) - expect(worker.perform(id, Project.name)).to be true - end + it 'removes the project and all associated documents from the index' do + expect(logger_double).to receive(:warn).with(container_id: id, container_type: Project.name, + message: 'Container record not found') + expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(id, es_id, delete_project: true) + expect(Gitlab::Elastic::Indexer).not_to receive(:new) + expect(logger_double).not_to receive(:info) + expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex) + expect(worker.perform(id, Project.name)).to be true end end -- GitLab