This document provides a development guide for contributors to add application limits to GitLab.
First of all, you have to gather information and decide which are the different limits that will be set for the different GitLab tiers. You also need to coordinate with others to document and communicate those limits.
There is a guide about introducing application limits.
The merge request to configure maximum number of webhooks per project is a good example about configuring application limits.
plan_limits table, you have to create a new column and insert the
limit values. It’s recommended to create separate migration script files.
Add new column to the
plan_limitstable with non-null default value 0, eg:
add_column(:plan_limits, :project_hooks, :integer, default: 0, null: false)Note: Plan limits entries set to
0mean that limits are not enabled.
Insert plan limits values into the database using
create_or_update_plan_limitmigration helper, eg:
create_or_update_plan_limit('project_hooks', 'free', 10) create_or_update_plan_limit('project_hooks', 'bronze', 20) create_or_update_plan_limit('project_hooks', 'silver', 30) create_or_update_plan_limit('project_hooks', 'gold', 100)
Access to the current limit can be done through the project or the namespace, eg:
There is one method
PlanLimits#exceeded? to check if the current limit is
being exceeded. You can use either an
ActiveRecord object or an
Ensures that the count of the records does not exceed the defined limit, eg:
project.actual_limits.exceeded?(:project_hooks, ProjectHook.where(project: project))
Ensures that the number does not exceed the defined limit, eg:
can be used to validate that a model does not exceed the limits. It ensures
that the count of the records for the current model does not exceed the defined
project_hooks) must correspond to the name of the model we are validating (
class ProjectHook include Limitable end