Skip to content

Clear license caches before license reset in seat link sync

What does this MR do and why?

Part of https://gitlab.com/gitlab-org/gitlab/-/issues/411863+

Prior to this change, when triggering seat link syncs while also removing a license and activating an activation code in quick succession, the Sidekiq jobs could lead to duplicated license creations license. This is because the license cache isn't up to date when the Sidekiq job is executed.

To resolve this issue, the seat link sync now clears the current license cache to use the actual current license before executing the logic to reset the license (either update the current one or create a new one) as part of the sync.

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 after
Screenshot_2024-04-18_at_2.55.38_PM Screenshot_2024-04-18_at_3.17.18_PM

How to set up and validate locally

In the master branch:

  1. GitLab: Restart GDK/GitLab to ensure all services are working properly (Sidekiq is sometimes stuck for me).
  2. Zuora: Create a new SM Premium/Ultimate subscription in Zuora.
  3. ZSim/CustomersDot: Wait for the callout to process.
  4. GitLab: Activate the subscription in your GitLab instance.
  5. Zuora: Cancel the subscription in Zuora.
  6. Zuora: Create another SM Premium/Ultimate subscription (with less seats than the one in step 2 for easier distinction) in Zuora.
  7. _ZSim/CustomersDot:_Wait for the callouts to process.
  8. GitLab: Trigger a seat link sync on /admin/subscription with the activated subscription from step 4. This should result in the cancellation to be synced.
  9. CustomersDot: Keep the activation code for the subscription created in step 6 ready for the next step.
  10. GitLab: This to be done in a short timeframe (probably less than a minute): Trigger another seat link sync and remove the current license (= cancellation license), trigger another sync, use the activation code from step 9 and trigger another sync afterwards.
  11. GitLab: You should now have a duplicated (cancellation) license for the cancelled subscription from step 5 in your subscription/license overview.
  12. GitLab: You can also use the following code in your rails console to have more insight into the existing licenses:
    License.order(id: :asc).each {|l| pp l.restrictions.reject {|k,v| [:id, :subscription_id, :subscription_name].exclude?(k) }.merge(id: l.id, lid: l.license.restrictions[:id], cancellation: l.license.generated_from_cancellation, created_at: l.created_at.to_s) }; nil
  13. GitLab: Remove the licenses.
  14. Repeat the steps 1-12 with this MR's branch. You can reuse the same subscription as created in step 6 for step 2.
  15. GitLab: Verify no license was duplicated.
Edited by Corinna Gogolok

Merge request reports