Streamline billable users calculations
Summary
In #328611 (comment 557307274) we identified that the reference for Billable Users in various pages in self-managed use difference methods for calculation.
In this issue, we should explore deprecating one of these methods and utilize the same across both pages.
Billable Users on License/Subscription Page
Information below from #328611 (comment 557306151)
License#daily_billable_users_count
- This is all active human users. Guest users are excluded if the instance has an Ultimate license. Users who have no memberships at all also count as guests.
- Yes, this is a stored value.
- The worker to calculate and store this value runs daily at 23:50.
- It is stored in the
analytics_usage_trends_measurements
table. Each time the worker runs, a new row is inserted in the table with a value of11
in theidentifier
column, and the total number of billable users in thecount
column. When the function runs, it takes the most recent row from the table. It will fall back to calculating the value on the fly if there are no rows in the table.
- This is the
Billable Users
pictured in the License overview of the Admin Area > Dashboard. See the screenshot below. Used in the view here -
Maximum Users
(License#historical_max
) depends on this value.Maximum Users
is the highest this value has ever been during the current license period.Users Over License
, which is displayed directly below Billable Users, depends onMaximum Users
, and so transitively depends on this value.
Details
- How is this value derived?
This is all active human users. (This queries the users
table looking for active
in the state
column and NULL
in the user_type
column.)
ghost
users are excluded via the active
scope definition on the User
model which ultimately excludes ghost
users.
It also includes all Service Users. (It selects all users where the user_type
column on the users
table has the value 4
). I need to look into this further. I don't know what service users are for, but I think it may be a feature we've never done much with. On gitlab.com
, we have one service user, "GitLab Bot". It may be that self-managed instances don't actually have this type of service user in practice.
If the instance has an Ultimate license, then this value does not include any users who have a highest role of Guest. For example, a user with several Guest memberships and only Guest memberships would not be included in this count for an Ultimate license. If even one of the several memberships were upgraded to Reporter or higher, then this user would count towards the total. Downgrading that membership back to Guest would remove the user from the total again. This is calculated on the fly and does not rely on the user_highest_roles
table or any of the associated code.
- Where is this value presented in the UI?
Used in ee/app/views/admin/licenses/_breakdown.html.haml
.
Billable Users on Seat Usage Page
Information below from #328611 (comment 636800512)
- This has the same definition as
Billable Users
. However,Billable Users
is obtained viaLicense#daily_billable_users_count
. Here, the displayed value in the Billable users row is obtained byUsersStatistics#billable
. Here it is in the view. And where we get the instance in the controller.- This is basically a stored value. The
Users::CreateStatisticsWorker
runs every day at 02:15. Every time the worker runs, it creates a new row in theusers_statistics
table. This row contains a number of values for the last counts of users by highest role. So the total number of guests, reporters, developers, maintainers, owners, bots, blocked users, and users who are not a member of any group or project. The values displayed on this page are either these stored values or easily calculated from them (Billable users, Active users, and Total users). - At page load, this value is calculated from the stored values.
- This data is stored in the
user_statistics
table.
- This is basically a stored value. The
- There is no change for a trial license.