Skip to content

Start storing change date for max_seats_used

Josianne Hyson requested to merge jh-store_max_seats_changed_at into master

What does this MR do and why?

This is foundational work for issues [SaaS] Alert to group Owners when group is appr... (#348481 - closed) and [SaaS] Seat overage email schedules excessive n... (#358080 - closed).

We want to be able to efficiently determine what date a subscription had its max_seats_used value updated so that we can determine whether or not we need to inform the user of our overage policy. We've chosen to store this value so that we don't have to calculate the date the last billable user was added to a group every time a group owner loads a page in the group.

This MR will be followed up by !83492 (merged)

Migrations

AddMaxSeatsUsedChangedAtToGitlabSubscriptions

rails db:migrate:up:main VERSION=20220413235818
== 20220413235818 AddMaxSeatsUsedChangedAtToGitlabSubscriptions: migrating ====
-- add_column(:gitlab_subscriptions, :max_seats_used_changed_at, :datetime_with_timezone)
   -> 0.0066s
== 20220413235818 AddMaxSeatsUsedChangedAtToGitlabSubscriptions: migrated (0.0066s)
rails db:migrate:down:main VERSION=20220413235818
== 20220413235818 AddMaxSeatsUsedChangedAtToGitlabSubscriptions: reverting ====
-- remove_column(:gitlab_subscriptions, :max_seats_used_changed_at, :datetime_with_timezone)
   -> 0.0045s
== 20220413235818 AddMaxSeatsUsedChangedAtToGitlabSubscriptions: reverted (0.0114s)

How to set up and validate locally

  1. Ensure the instance thinks it's SaaS by starting the GDK with the flag
    GITLAB_SIMULATE_SAAS=1 gdk restart
  2. Create a group and purchase a GitLab subscription for the group under the Billing tab
  3. Observe that max_seats_used_changed_at is nil in the rails console
  4. Run the worker to update the max seats used statistics
    GITLAB_SIMULATE_SAAS=1 rails c
    ApplicationSetting.first.update!(check_namespace_plan: true)
    UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker.new.perform
  5. Observe that max_seats_used_changed_at is the current date in the console
  6. Add users to the group and re-run the worker
  7. The max_seats_used_changed_at has been updated
  8. Remove users from the group and re-run the worker
  9. The max_seats_used_changed_at has not been updated

MR acceptance checklist

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

Edited by Josianne Hyson

Merge request reports