Skip to content
Snippets Groups Projects
Verified Commit d50f4f1c authored by Terri Chu's avatar Terri Chu :nail_care: Committed by GitLab
Browse files

Remove search_index_all_projects FF

Changelog: other
EE: true
parent 16c41970
No related branches found
No related tags found
1 merge request!148111Remove search_index_all_projects FF
Showing
with 97 additions and 368 deletions
---
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
...@@ -399,13 +399,7 @@ from the Elasticsearch index as expected. ...@@ -399,13 +399,7 @@ from the Elasticsearch index as expected.
#### All project records are indexed #### 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. > - [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. > - [Generally available](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/148111) in GitLab 16.11. Feature flag `search_index_all_projects` removed.
> - [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.
When you select the **Limit the amount of namespace and project data to index** checkbox: When you select the **Limit the amount of namespace and project data to index** checkbox:
......
...@@ -22,8 +22,6 @@ def maintaining_indexed_associations? ...@@ -22,8 +22,6 @@ def maintaining_indexed_associations?
override :maintaining_elasticsearch? override :maintaining_elasticsearch?
def maintaining_elasticsearch? def maintaining_elasticsearch?
return super if ::Feature.disabled?(:search_index_all_projects, root_namespace)
::Gitlab::CurrentSettings.elasticsearch_indexing? ::Gitlab::CurrentSettings.elasticsearch_indexing?
end end
......
...@@ -25,8 +25,7 @@ def index ...@@ -25,8 +25,7 @@ def index
def delete_from_index def delete_from_index
return unless Gitlab::CurrentSettings.elasticsearch_indexing? return unless Gitlab::CurrentSettings.elasticsearch_indexing?
# do not delete the project document if indexing for all projects is enabled for the project # project documents are indexed regardless of limit settings
delete_project = ::Feature.disabled?(:search_index_all_projects, project.root_namespace) ElasticDeleteProjectWorker.perform_async(project.id, project.es_id, delete_project: false)
ElasticDeleteProjectWorker.perform_async(project.id, project.es_id, delete_project: delete_project)
end end
end end
...@@ -31,13 +31,10 @@ def perform(project_id, old_namespace_id, new_namespace_id) ...@@ -31,13 +31,10 @@ def perform(project_id, old_namespace_id, new_namespace_id)
delete_old_project(project, old_namespace_id) delete_old_project(project, old_namespace_id)
elsif should_invalidate_elasticsearch_indexes_cache && ::Gitlab::CurrentSettings.elasticsearch_indexing? 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 # If the new namespace isn't indexed, the project's associated records should no longer exist in the index
# and will be deleted asynchronously. If all projects are indexed, queue the project for indexing # and will be deleted asynchronously. Queue the project for indexing
# to update the namespace field and remove the old document from the index. # to update the namespace field and remove the old document from the index.
::Elastic::ProcessInitialBookkeepingService.track!(build_document_reference(project))
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
delete_old_project(project, old_namespace_id) delete_old_project(project, old_namespace_id)
end end
......
...@@ -32,7 +32,7 @@ def perform(project_id, wiki = false, options = {}) ...@@ -32,7 +32,7 @@ def perform(project_id, wiki = false, options = {})
@project = Project.find_by_id(project_id) @project = Project.find_by_id(project_id)
unless @project&.use_elasticsearch? unless @project&.use_elasticsearch?
es_id = ::Gitlab::Elastic::Helper.build_es_id(es_type: Project.es_type, target_id: project_id) 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) ElasticDeleteProjectWorker.perform_async(project_id, es_id, delete_project: delete_project)
return true return true
end end
......
...@@ -50,9 +50,8 @@ def index_group_associations(namespace) ...@@ -50,9 +50,8 @@ def index_group_associations(namespace)
end end
def delete_from_index(namespace) def delete_from_index(namespace)
delete_project = ::Feature.disabled?(:search_index_all_projects, namespace.root_ancestor)
namespace.all_projects.find_in_batches do |batch| 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 ElasticDeleteProjectWorker.bulk_perform_async(args) # rubocop:disable Scalability/BulkPerformWithContext
end end
......
...@@ -88,7 +88,7 @@ def cleanup_container_elastic_documents(container, container_id, container_type) ...@@ -88,7 +88,7 @@ def cleanup_container_elastic_documents(container, container_id, container_type)
end end
if container_type == 'Project' if container_type == 'Project'
delete_project = container.nil? || ::Feature.disabled?(:search_index_all_projects, container.root_namespace) delete_project = container.nil?
ElasticDeleteProjectWorker.perform_async( ElasticDeleteProjectWorker.perform_async(
container_id, container_id,
......
...@@ -20,17 +20,7 @@ ...@@ -20,17 +20,7 @@
describe '#maintaining_elasticsearch?' do describe '#maintaining_elasticsearch?' do
subject(:maintaining_elasticsearch) { project.maintaining_elasticsearch? } subject(:maintaining_elasticsearch) { project.maintaining_elasticsearch? }
context 'when the search_index_all_projects FF is false' do it { is_expected.to be(true) }
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
end end
describe '#use_elasticsearch?' do describe '#use_elasticsearch?' do
...@@ -48,17 +38,7 @@ ...@@ -48,17 +38,7 @@
describe '#maintaining_elasticsearch?' do describe '#maintaining_elasticsearch?' do
subject(:maintaining_elasticsearch) { project.maintaining_elasticsearch? } subject(:maintaining_elasticsearch) { project.maintaining_elasticsearch? }
context 'when the search_index_all_projects FF is false' do it { is_expected.to be(true) }
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
end end
describe '#use_elasticsearch?' do describe '#use_elasticsearch?' do
...@@ -68,28 +48,12 @@ ...@@ -68,28 +48,12 @@
end end
describe 'indexing', :sidekiq_inline do describe 'indexing', :sidekiq_inline do
context 'when the search_index_all_projects FF is false' do it 'indexes all projects' do
before do create(:project, :empty_repo, path: 'test_two', description: 'awesome project')
stub_feature_flags(search_index_all_projects: false) ensure_elasticsearch_index!
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
context 'when the search_index_all_projects FF is true' do expect(described_class.elastic_search('main_project', options: { project_ids: :any }).total_count).to eq(1)
it 'indexes all projects' do expect(described_class.elastic_search('"test_two"', options: { project_ids: :any }).total_count).to eq(1)
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
end end
end end
end end
...@@ -106,48 +70,19 @@ ...@@ -106,48 +70,19 @@
subject(:maintaining_elasticsearch) { project_in_group.maintaining_elasticsearch? } subject(:maintaining_elasticsearch) { project_in_group.maintaining_elasticsearch? }
context 'when the search_index_all_projects FF is false' do it { is_expected.to be(true) }
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
end end
describe 'indexing' do describe 'indexing' do
context 'when the search_index_all_projects FF is false' do it 'indexes all projects' do
before do create(:project, name: 'group_test1', group: create(:group, parent: group))
stub_feature_flags(search_index_all_projects: false) create(:project, name: 'group_test2', description: 'awesome project')
end create(:project, name: 'group_test3', group: group)
ensure_elasticsearch_index!
it 'indexes only projects under the group' do
create(:project, name: 'group_test1', group: create(:group, parent: group)) expect(described_class.elastic_search('group_test*', options: { project_ids: :any }).total_count).to eq(3)
create(:project, name: 'group_test2', description: 'awesome project') expect(described_class.elastic_search('"group_test3"', options: { project_ids: :any }).total_count).to eq(1)
create(:project, name: 'group_test3', group: group) expect(described_class.elastic_search('"group_test2"', options: { project_ids: :any }).total_count).to eq(1)
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
end end
end end
...@@ -177,7 +112,8 @@ ...@@ -177,7 +112,8 @@
raise ArgumentError, 'Invalid operator' raise ArgumentError, 'Invalid operator'
end 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
end end
...@@ -233,7 +169,8 @@ ...@@ -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('"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: 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('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 end
it 'finds partial matches in project names', :sidekiq_inline do it 'finds partial matches in project names', :sidekiq_inline do
......
...@@ -18,86 +18,37 @@ ...@@ -18,86 +18,37 @@
expect(Elastic::ProcessBookkeepingService).to receive(:track!).with(project) expect(Elastic::ProcessBookkeepingService).to receive(:track!).with(project)
end end
context 'when search_index_all_projects is true' do let(:delete_action) do
before do expect(ElasticDeleteProjectWorker).to receive(:perform_async)
stub_feature_flags(search_index_all_projects: true) .with(project.id, project.es_id, delete_project: false)
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
end end
context 'when search_index_all_projects is false' do it_behaves_like 'an elasticsearch indexed container' do
before do context 'when elasticsearch_indexing is false' do
stub_feature_flags(search_index_all_projects: false) before do
end stub_ee_application_setting(elasticsearch_indexing: 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
describe 'callbacks' do describe 'callbacks' do
describe 'on save' do describe 'on save' do
subject(:elasticsearch_indexed_project) { build(container, container_attributes) } subject(:elasticsearch_indexed_project) { build(container, container_attributes) }
it 'triggers index but does not index the data' do it 'triggers index but does not index the data' do
is_expected.to receive(:index) is_expected.to receive(:index)
expect(Elastic::ProcessBookkeepingService).not_to receive(:track!) expect(Elastic::ProcessBookkeepingService).not_to receive(:track!)
elasticsearch_indexed_project.save! elasticsearch_indexed_project.save!
end
end end
end
describe 'on destroy' do describe 'on destroy' do
subject(:elasticsearch_indexed_project) { create(container, container_attributes) } subject(:elasticsearch_indexed_project) { create(container, container_attributes) }
it 'triggers delete_from_index but does not delete data from index' do it 'triggers delete_from_index but does not delete data from index' do
is_expected.to receive(:delete_from_index) is_expected.to receive(:delete_from_index)
expect(ElasticDeleteProjectWorker).not_to receive(:perform_async) expect(ElasticDeleteProjectWorker).not_to receive(:perform_async)
elasticsearch_indexed_project.destroy! elasticsearch_indexed_project.destroy!
end
end end
end end
end end
......
...@@ -316,18 +316,6 @@ ...@@ -316,18 +316,6 @@
stub_ee_application_setting(elasticsearch_limit_indexing: true) stub_ee_application_setting(elasticsearch_limit_indexing: true)
end 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 context 'when elasticsearch_indexing is disabled' do
before do before do
stub_ee_application_setting(elasticsearch_indexing: false) stub_ee_application_setting(elasticsearch_indexing: false)
......
...@@ -71,52 +71,28 @@ ...@@ -71,52 +71,28 @@
create(:elasticsearch_indexed_namespace, namespace: indexed_namespace) create(:elasticsearch_indexed_namespace, namespace: indexed_namespace)
end end
context 'when search_index_all_projects is true' do it 'invalidates the cache and removes only the associated data from the index' do
before do expect(Elastic::ProcessInitialBookkeepingService).to receive(:track!).with(project)
stub_feature_flags(search_index_all_projects: true) expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:backfill_projects!)
end expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(project.id, project.es_id,
namespace_routing_id: project.root_ancestor.id)
it 'invalidates the cache and removes only the associated data from the index' do expect(::Gitlab::CurrentSettings)
expect(Elastic::ProcessInitialBookkeepingService).to receive(:track!).with(project) .to receive(:invalidate_elasticsearch_indexes_cache_for_project!)
expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:backfill_projects!) .with(project.id).and_call_original
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
context 'when the reindex_projects_to_apply_routing migration is not finished' do worker.perform(project.id, non_indexed_namespace.id, indexed_namespace.id)
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
end 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 before do
stub_feature_flags(search_index_all_projects: false) set_elasticsearch_migration_to(:reindex_projects_to_apply_routing, including: false)
end end
it 'invalidates the cache and removes the project and associated data from the index' do it 'tracks with a document reference and deletes without namespace_routing_id' do
expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:track!) expect(Elastic::ProcessInitialBookkeepingService).to receive(:track!)
.with(an_instance_of(Gitlab::Elastic::DocumentReference))
expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:backfill_projects!) expect(Elastic::ProcessInitialBookkeepingService).not_to receive(:backfill_projects!)
expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(project.id, project.es_id, expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(project.id, project.es_id)
namespace_routing_id: project.root_ancestor.id)
expect(::Gitlab::CurrentSettings) expect(::Gitlab::CurrentSettings)
.to receive(:invalidate_elasticsearch_indexes_cache_for_project!) .to receive(:invalidate_elasticsearch_indexes_cache_for_project!)
.with(project.id).and_call_original .with(project.id).and_call_original
......
...@@ -28,66 +28,24 @@ ...@@ -28,66 +28,24 @@
Gitlab::Elastic::Helper.build_es_id(es_type: Project.es_type, target_id: non_existing_record_id) Gitlab::Elastic::Helper.build_es_id(es_type: Project.es_type, target_id: non_existing_record_id)
end end
context 'when search_index_all_projects is true' do it 'calls ElasticDeleteProjectWorker on the project to delete all documents and returns true' do
before do expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(id, es_id, delete_project: true)
stub_feature_flags(search_index_all_projects: true) expect(Gitlab::Elastic::Indexer).not_to receive(:new)
end expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex)
expect(worker.perform(id)).to be true
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
end end
end end
context 'when elasticsearch is disabled for Project' do context 'when elasticsearch is disabled for Project' do
context 'when search_index_all_projects is true' do it 'calls ElasticDeleteProjectWorker to keep itself and only delete associated documents and returns true' do
before do allow_next_found_instance_of(Project) do |project|
stub_feature_flags(search_index_all_projects: true) expect(project).to receive(:use_elasticsearch?).and_return(false)
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
end 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
end end
......
...@@ -56,19 +56,6 @@ ...@@ -56,19 +56,6 @@
worker.perform(namespace.id, :delete) worker.perform(namespace.id, :delete)
end 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 it 'does not enqueue Search::ElasticGroupAssociationDeletionWorker' do
expect(Search::ElasticGroupAssociationDeletionWorker).not_to receive(:perform_async) expect(Search::ElasticGroupAssociationDeletionWorker).not_to receive(:perform_async)
......
...@@ -35,42 +35,17 @@ ...@@ -35,42 +35,17 @@
context 'when container is Project' do context 'when container is Project' do
context 'when elasticsearch is disabled for Project' do context 'when elasticsearch is disabled for Project' do
context 'when search_index_all_projects is true' do it 'does not remove the project but removes all associated documents from the index' do
before do allow_next_found_instance_of(Project) do |project|
stub_feature_flags(search_index_all_projects: true) expect(project).to receive(:use_elasticsearch?).and_return(false)
end end
it 'does not remove the project but removes all associated documents from the index' do expect(ElasticDeleteProjectWorker).to receive(:perform_async)
allow_next_found_instance_of(Project) do |project| .with(project.id, project.es_id, delete_project: false)
expect(project).to receive(:use_elasticsearch?).and_return(false) expect(Gitlab::Elastic::Indexer).not_to receive(:new)
end expect(logger_double).not_to receive(:info)
expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex)
expect(ElasticDeleteProjectWorker).to receive(:perform_async) expect(worker.perform(project.id, project.class.name)).to be true
.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
end end
end end
...@@ -153,36 +128,14 @@ ...@@ -153,36 +128,14 @@
Gitlab::Elastic::Helper.build_es_id(es_type: Project.es_type, target_id: non_existing_record_id) Gitlab::Elastic::Helper.build_es_id(es_type: Project.es_type, target_id: non_existing_record_id)
end end
context 'when search_index_all_projects is false' do it 'removes the project and all associated documents from the index' do
before do expect(logger_double).to receive(:warn).with(container_id: id, container_type: Project.name,
stub_feature_flags(search_index_all_projects: false) message: 'Container record not found')
end expect(ElasticDeleteProjectWorker).to receive(:perform_async).with(id, es_id, delete_project: true)
expect(Gitlab::Elastic::Indexer).not_to receive(:new)
it 'removes the project and all associated documents from the index' do expect(logger_double).not_to receive(:info)
expect(logger_double).to receive(:warn).with(container_id: id, container_type: Project.name, expect(Gitlab::Metrics::GlobalSearchIndexingSlis).not_to receive(:record_apdex)
message: 'Container record not found') expect(worker.perform(id, Project.name)).to be true
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
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment