Commit aac80fde authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '198467-group-hooks-limits' into 'master'

Resolve "Add webhook limits for groups"

See merge request gitlab-org/gitlab!25129
parents 909645a5 8f2f2105
# frozen_string_literal: true
class AddGroupHooksToPlanLimits < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column(:plan_limits, :group_hooks, :integer, default: 0, null: false)
end
end
# frozen_string_literal: true
class InsertGroupHooksPlanLimits < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
return unless Gitlab.com?
create_or_update_plan_limit('group_hooks', 'bronze', 50)
create_or_update_plan_limit('group_hooks', 'silver', 50)
create_or_update_plan_limit('group_hooks', 'gold', 50)
end
def down
return unless Gitlab.com?
create_or_update_plan_limit('group_hooks', 'bronze', 0)
create_or_update_plan_limit('group_hooks', 'silver', 0)
create_or_update_plan_limit('group_hooks', 'gold', 0)
end
end
...@@ -3109,6 +3109,7 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do ...@@ -3109,6 +3109,7 @@ ActiveRecord::Schema.define(version: 2020_02_24_163804) do
t.integer "ci_pipeline_size", default: 0, null: false t.integer "ci_pipeline_size", default: 0, null: false
t.integer "ci_active_jobs", default: 0, null: false t.integer "ci_active_jobs", default: 0, null: false
t.integer "project_hooks", default: 0, null: false t.integer "project_hooks", default: 0, null: false
t.integer "group_hooks", default: 0, null: false
t.index ["plan_id"], name: "index_plan_limits_on_plan_id", unique: true t.index ["plan_id"], name: "index_plan_limits_on_plan_id", unique: true
end end
......
...@@ -35,13 +35,23 @@ Read more in the [CI documentation](../ci/yaml/README.md#processing-git-pushes). ...@@ -35,13 +35,23 @@ Read more in the [CI documentation](../ci/yaml/README.md#processing-git-pushes).
Activity history for projects and individuals' profiles was limited to one year until [GitLab 11.4](https://gitlab.com/gitlab-org/gitlab-foss/issues/52246) when it was extended to two years, and in [GitLab 12.4](https://gitlab.com/gitlab-org/gitlab/issues/33840) to three years. Activity history for projects and individuals' profiles was limited to one year until [GitLab 11.4](https://gitlab.com/gitlab-org/gitlab-foss/issues/52246) when it was extended to two years, and in [GitLab 12.4](https://gitlab.com/gitlab-org/gitlab/issues/33840) to three years.
## Number of project webhooks ## Number of webhooks
A maximum number of webhooks applies to each GitLab.com tier. Limits apply to project and group webhooks.
### Project Webhooks
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20730) in GitLab 12.6. > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20730) in GitLab 12.6.
A maximum number of project webhooks applies to each GitLab.com tier. Check the Check the [Maximum number of project webhooks (per tier)](../user/project/integrations/webhooks.md#maximum-number-of-project-webhooks-per-tier) section in the Webhooks page.
[Maximum number of webhooks (per tier)](../user/project/integrations/webhooks.md#maximum-number-of-webhooks-per-tier)
section in the Webhooks page. ### Group Webhooks
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25129) in GitLab 12.9.
Check the [Maximum number of group webhooks (per tier)](../user/project/integrations/webhooks.md#maximum-number-of-group-webhooks-per-tier) section in the Webhooks page.
### Setting the limit on a self-hosted installation
To set this limit on a self-hosted installation, run the following in the To set this limit on a self-hosted installation, run the following in the
[GitLab Rails console](https://docs.gitlab.com/omnibus/maintenance/#starting-a-rails-console-session): [GitLab Rails console](https://docs.gitlab.com/omnibus/maintenance/#starting-a-rails-console-session):
...@@ -50,7 +60,11 @@ To set this limit on a self-hosted installation, run the following in the ...@@ -50,7 +60,11 @@ To set this limit on a self-hosted installation, run the following in the
# If limits don't exist for the default plan, you can create one with: # If limits don't exist for the default plan, you can create one with:
# Plan.default.create_limits! # Plan.default.create_limits!
# For project webhooks
Plan.default.limits.update!(project_hooks: 100) Plan.default.limits.update!(project_hooks: 100)
# For group webhooks
Plan.default.limits.update!(group_hooks: 100)
``` ```
NOTE: **Note:** Set the limit to `0` to disable it. NOTE: **Note:** Set the limit to `0` to disable it.
......
...@@ -47,7 +47,7 @@ and **per project and per group** for **GitLab Enterprise Edition**. ...@@ -47,7 +47,7 @@ and **per project and per group** for **GitLab Enterprise Edition**.
Navigate to the webhooks page by going to your project's Navigate to the webhooks page by going to your project's
**Settings ➔ Webhooks**. **Settings ➔ Webhooks**.
## Maximum number of webhooks (per tier) ## Maximum number of project webhooks (per tier)
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20730) in GitLab 12.6. > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20730) in GitLab 12.6.
...@@ -61,6 +61,20 @@ tier](https://about.gitlab.com/pricing/), as shown in the following table: ...@@ -61,6 +61,20 @@ tier](https://about.gitlab.com/pricing/), as shown in the following table:
| Silver | 100 | | Silver | 100 |
| Gold | 100 | | Gold | 100 |
## Maximum number of group webhooks (per tier)
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25129) in GitLab 12.9.
A maximum number of group webhooks applies to each [GitLab.com
tier](https://about.gitlab.com/pricing/), as shown in the following table:
| Tier | Number of webhooks per group |
|----------|--------------------------------|
| Free | feature not available |
| Bronze | 50 |
| Silver | 50 |
| Gold | 50 |
## Use-cases ## Use-cases
- You can set up a webhook in GitLab to send a notification to - You can set up a webhook in GitLab to send a notification to
......
...@@ -22,8 +22,20 @@ class GroupHook < ProjectHook ...@@ -22,8 +22,20 @@ class GroupHook < ProjectHook
clear_validators! clear_validators!
validates :url, presence: true, addressable_url: true validates :url, presence: true, addressable_url: true
validate :validate_group_hook_limits_not_exceeded, on: :create
def pluralized_name def pluralized_name
_('Group Hooks') _('Group Hooks')
end end
private
def validate_group_hook_limits_not_exceeded
return unless group
if group.actual_limits.exceeded?(:group_hooks, GroupHook.where(group: group))
errors.add(:base, _("Maximum number of group hooks (%{count}) exceeded") %
{ count: group.actual_limits.group_hooks })
end
end
end end
---
title: Add webhook limits for groups
merge_request: 25129
author:
type: added
...@@ -6,4 +6,36 @@ describe GroupHook do ...@@ -6,4 +6,36 @@ describe GroupHook do
describe "Associations" do describe "Associations" do
it { is_expected.to belong_to :group } it { is_expected.to belong_to :group }
end end
describe 'validations' do
subject(:group_hook) { build(:group_hook, group: group) }
let(:gold_plan) { create(:gold_plan) }
let(:plan_limits) { create(:plan_limits, plan: gold_plan) }
let(:group) { create(:group) }
let!(:subscription) { create(:gitlab_subscription, namespace: group, hosted_plan: gold_plan) }
context 'without plan limits configured' do
it 'can create new group hooks' do
expect { group_hook.save }.to change { described_class.count }
end
end
context 'with plan limits configured' do
before do
plan_limits.update(group_hooks: 1)
end
it 'can create new group hooks' do
expect { group_hook.save }.to change { described_class.count }
end
it 'cannot create new group hooks exceding the plan limits' do
create(:group_hook, group: group)
expect { group_hook.save }.not_to change { described_class.count }
expect(group_hook.errors[:base]).to contain_exactly('Maximum number of group hooks (1) exceeded')
end
end
end
end end
...@@ -11972,6 +11972,9 @@ msgstr "" ...@@ -11972,6 +11972,9 @@ msgstr ""
msgid "Maximum number of comments exceeded" msgid "Maximum number of comments exceeded"
msgstr "" msgstr ""
msgid "Maximum number of group hooks (%{count}) exceeded"
msgstr ""
msgid "Maximum number of mirrors that can be synchronizing at the same time." msgid "Maximum number of mirrors that can be synchronizing at the same time."
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment