Skip to content

Refactor how expired namespaces are removed from index

Terri Chu requested to merge 439769-fix-expired-subscriptions into master

What does this MR do and why?

Related to #439769 (closed)

This MR adjusts what qualifies as an "expired" namespace for removal from advanced search. The previous logic was missing removing trials that are null and as a result there are a good number of namespaces that need to be removed from the index.

Due to the large number (see internal comment, I've added a limit of 1000 namespaces that can be removed in one run. The cronworker runs once per day and I think it's ok to remove things slowly (they have been in the index this long so a slow removal will be safer)

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

N/A this is changes to a cron job

How to set up and validate locally

  1. create 2 ElasticsearchIndexedNamespace records with default plan subscriptions
     plan = Plan.default
     Group.last(2).each do |g| 
       GitlabSubscription.create(namespace_id: g.id, hosted_plan_id: plan.id)
       ElasticsearchIndexedNamespace.create(namespace_id: g.id)
     end
  2. create 2 ElasticsearchIndexedNamespace records with bronze plan subscriptions
     plan = Plan.find_by_name('bronze')
     groups = Group.first(2)
     # one with no expiration
     GitlabSubscription.create(namespace_id: groups.first.id, hosted_plan_id: plan.id)
     ElasticsearchIndexedNamespace.create(namespace_id: groups.first.id)
     # one with an expired subscription expiration
     GitlabSubscription.create(namespace_id: groups.second.id, hosted_plan_id: plan.id, start_date: 1.months.ago, end_date: 2.months.ago)
     ElasticsearchIndexedNamespace.create(namespace_id: groups.second.id)
  3. verify that there are 4 records in ElasticsearchIndexedNamespace table
    ElasticsearchIndexedNamespace.count
  4. run the destroy command
    ElasticsearchIndexedNamespace.destroy_namespaces_with_expired_subscriptions!
  5. verify that there is 1 record in ElasticsearchIndexedNamespace table
    ElasticsearchIndexedNamespace.count
Edited by Terri Chu

Merge request reports