Maximum historical users should be based on a license's start date, not 1 year
Problem to solve
In https://gitlab.com/gitlab-org/gitlab-ee/issues/550, we discussed a number of issues that were causing instances to reject licenses that should be accepted by the instance. Most frequently, this occurred due to an instance reducing the number of seats during a renewal. Take, for example, the following scenario:
- An EE customer renews a license for 50 seats. Halfway through the year, they add 20 additional members in addition to the 50 members using the instance. The instance's maximum user count, therefore, is set to 70.
- Next year, the customer decides to renew a few weeks before their license expires. However, they decide to reduce their use to 30 seats instead of renew at 70. They remove 40 members and attempt to apply the new license.
Unfortunately, this license may be rejected. This is the current implementation of the method that calculates it:
def max_historical_user_count HistoricalData.during(1.year.ago..Date.today).maximum(:active_user_count) || 0 end
max_historical_user_count is hardcoded to look back 1 year, any renewal before a license's expiration has serious potential to be incorrect.
We should use the range date dictated by the license key instead, something like:
def max_historical_user_count HistoricalData.during(License.current.starts_at..License.current.expires_at).maximum(:active_user_count) || 0 end
Edit: @tipyn: Jeremy and I walked through this visually to help us understand the problem better (currently only viewable by GitLabbers as neither of us is the owner and can't change the sharing permissions).