Skip to content

Fix housekeeper search migrations for specs

Terri Chu requested to merge tchu-fix-housekeeper-for-search-migrations into master

What does this MR do and why?

The spec replacement code did not work for the ee/spec/elastic/migrate/20230615101400_create_epic_index_spec.rb spec (copying it in because it will be made obsolete soon)

# frozen_string_literal: true

require 'spec_helper'
require File.expand_path('ee/elastic/migrate/20230615101400_create_epic_index.rb')

RSpec.describe CreateEpicIndex, feature_category: :global_search do
  it_behaves_like 'migration creates a new index', 20230615101400, Epic
end

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Before output
Running keep Keeps::MarkOldAdvancedSearchMigrationsAsObsolete
bundler: failed to load command: gitlab-housekeeper (/Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/bin/gitlab-housekeeper)
/Users/terrichu/projects/gitlab-development-kit/gitlab/keeps/mark_old_advanced_search_migrations_as_obsolete.rb:166:in `add_obsolete_to_migration_spec': undefined method `loc' for nil:NilClass (NoMethodError)

      rewriter.replace(describe_block.loc.expression, content)
                                     ^^^^
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/keeps/mark_old_advanced_search_migrations_as_obsolete.rb:134:in `create_mark_obsolete_change'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/keeps/mark_old_advanced_search_migrations_as_obsolete.rb:39:in `block in each_change'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/keeps/mark_old_advanced_search_migrations_as_obsolete.rb:38:in `each'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/keeps/mark_old_advanced_search_migrations_as_obsolete.rb:38:in `each_change'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/gems/gitlab-housekeeper/lib/gitlab/housekeeper/runner.rb:42:in `block (2 levels) in run'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/gems/gitlab-housekeeper/lib/gitlab/housekeeper/runner.rb:39:in `each'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/gems/gitlab-housekeeper/lib/gitlab/housekeeper/runner.rb:39:in `block in run'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/gems/gitlab-housekeeper/lib/gitlab/housekeeper/git.rb:98:in `with_return_to_current_branch'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/gems/gitlab-housekeeper/lib/gitlab/housekeeper/git.rb:22:in `with_clean_state'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/gems/gitlab-housekeeper/lib/gitlab/housekeeper/runner.rb:38:in `run'
	from /Users/terrichu/projects/gitlab-development-kit/gitlab/gems/gitlab-housekeeper/bin/gitlab-housekeeper:52:in `<top (required)>'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/bin/gitlab-housekeeper:25:in `load'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/bin/gitlab-housekeeper:25:in `<top (required)>'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/cli/exec.rb:58:in `load'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/cli/exec.rb:23:in `run'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/cli.rb:455:in `exec'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/cli.rb:35:in `dispatch'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/cli.rb:29:in `start'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/exe/bundle:28:in `block in <top (required)>'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.11/exe/bundle:20:in `<top (required)>'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/bin/bundle:25:in `load'
	from /Users/terrichu/.asdf/installs/ruby/3.2.3/bin/bundle:25:in `<main>'
After output
Running keep Keeps::MarkOldAdvancedSearchMigrationsAsObsolete
Merge request URL: (known after create), on branch mark-old-advanced-search-migrations-as-obsolete-mark_obsolete-20230615101400--create-epic-index. CI skipped.
=> MarkOldAdvancedSearchMigrationsAsObsolete: mark_obsolete: 20230615101400: CreateEpicIndex
=> Title:
Mark 20230615101400 as obsolete

=> Description:
This migration marks the 20230615101400 CreateEpicIndex Advanced search migration as obsolete.

This MR will still need changes to remove [references to the migration](https://gitlab.com/search?project_id=278964&scope=blobs&search=create_epic_index&regex=false)
in the code. At the moment, the `gitlab-housekeeper` is not always capable of removing all references so
you must check the diff and pipeline failures to confirm if there are any issues.
It is the responsibility of the assignee (picked from ~"group::global search") to push those changes to this branch.

You can read more about the process for marking Advanced search migrations as obsolete in
https://docs.gitlab.com/ee/development/search/advanced_search_migration_styleguide.html#deleting-advanced-search-migrations-in-a-major-version-upgrade.

As part of our process we want to ensure all Advanced search migrations have had at least one
[required stop](https://docs.gitlab.com/ee/development/database/required_stops.html)
to process the migration. Therefore we can mark any Advanced search migrations added before the
last required stop as obsolete.


=> Attributes:
Labels: maintenance::refactor, group::global search, automation:gitlab-housekeeper-authored
Assignees: maddievn
Reviewers:

=> Diff:
diff --git a/ee/elastic/docs/20230615101400_create_epic_index.yml b/ee/elastic/docs/20230615101400_create_epic_index.yml
index 1b400d141f8f..ee1a6f18e2c1 100644
--- a/ee/elastic/docs/20230615101400_create_epic_index.yml
+++ b/ee/elastic/docs/20230615101400_create_epic_index.yml
@@ -5,6 +5,6 @@ description: Create a standalone index for Epics
 group: group::global search
 milestone: '16.2'
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/121635
-obsolete: false
+obsolete: true
 marked_obsolete_by_url:
-marked_obsolete_in_milestone:
+marked_obsolete_in_milestone: '17.2'
diff --git a/ee/elastic/migrate/20230615101400_create_epic_index.rb b/ee/elastic/migrate/20230615101400_create_epic_index.rb
index 9dd9d3cadf3b..cccf169f0c4a 100644
--- a/ee/elastic/migrate/20230615101400_create_epic_index.rb
+++ b/ee/elastic/migrate/20230615101400_create_epic_index.rb
@@ -13,3 +13,5 @@ def target_class
     Epic
   end
 end
+
+CreateEpicIndex.prepend ::Elastic::MigrationObsolete
diff --git a/ee/spec/elastic/migrate/20230615101400_create_epic_index_spec.rb b/ee/spec/elastic/migrate/20230615101400_create_epic_index_spec.rb
index 07d5af0d6729..4259b9267da1 100644
--- a/ee/spec/elastic/migrate/20230615101400_create_epic_index_spec.rb
+++ b/ee/spec/elastic/migrate/20230615101400_create_epic_index_spec.rb
@@ -4,5 +4,5 @@
 require File.expand_path('ee/elastic/migrate/20230615101400_create_epic_index.rb')

 RSpec.describe CreateEpicIndex, feature_category: :global_search do
-  it_behaves_like 'migration creates a new index', 20230615101400, Epic
+  it_behaves_like 'a deprecated Advanced Search migration', 20230615101400
 end


Dry run complete. Housekeeper would have created 1 MR on an actual run.

How to set up and validate locally

bundle exec gitlab-housekeeper --target-branch=master -k Keeps::MarkOldAdvancedSearchMigrationsAsObsolete -m 1 --dry-run
Edited by Terri Chu

Merge request reports