Skip to content

Ensure feature-category attr is set for new BatchedMigrationJobs

Why this MR?

'feature_category' class attr is exposed in BatchedMigrationJob and pushed to the ApplicationContext as part of the previous MRs (part-1 and part-2), this MR ensures that the feature_category is defined in all new BatchedMigrationJob subclasses.

What does it do?

  • New cop is created to ensure valid 'feature_category' is defined.
  • config/feature_categories.yml is referred to get valid feature-categories
  • And updates related documentations to capture the new expectation on the 'feature-category'.

Results from local executions

Without feature_category attribute

➜  gitlab git:(381897-check-feature-category-set-on-batched-migrations) bundle exec rubocop lib/gitlab/background_migration/sanitize_confidential_todos.rb 
Inspecting 1 file
C

Offenses:

lib/gitlab/background_migration/sanitize_confidential_todos.rb:12:5: C: BackgroundMigration/FeatureCategory: 'feature_category' should be defined to better assign the ownership for batched migration jobs. For more details refer: https://docs.gitlab.com/ee/development/feature_categorization/#batched-background-migrations
    class SanitizeConfidentialTodos < BatchedMigrationJob ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected
With invalid feature_category attribute
➜  gitlab git:(381897-check-feature-category-set-on-batched-migrations) ✗ bundle exec rubocop lib/gitlab/background_migration/sanitize_confidential_todos.rb
Inspecting 1 file
C

Offenses:

lib/gitlab/background_migration/sanitize_confidential_todos.rb:16:7: C: BackgroundMigration/FeatureCategory: 'feature_category' is invalid. List of valid ones can be found in config/feature_categories.yml
      feature_category :random
      ^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected
With valid feature_category attribute
➜  gitlab git:(381897-check-feature-category-set-on-batched-migrations) ✗ bundle exec rubocop lib/gitlab/background_migration/sanitize_confidential_todos.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

How to set up and validate locally

For local testing sake, we can use an existing SanitizeConfidentialTodos migration job.

  1. bundle exec rubocop lib/gitlab/background_migration/sanitize_confidential_todos.rb
  2. We should be able to see a rubocop offense, stating missing feature_category attribute.
  3. Add feature_category :invalid_category after the line which sets 'operation_name'.
  4. Re running step (1) should complain about 'invalid feature_category'.
  5. Add feature_category :build_artifacts after the line which sets 'operation_name'.
  6. Re running step (1) should not show any offense.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Closes #381897 (closed)

Edited by Prabakaran Murugesan

Merge request reports