Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 13:00:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 13:00:54 +0300
commit3cccd102ba543e02725d247893729e5c73b38295 (patch)
treef36a04ec38517f5deaaacb5acc7d949688d1e187 /lib/gitlab/ci/pipeline
parent205943281328046ef7b4528031b90fbda70c75ac (diff)
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'lib/gitlab/ci/pipeline')
-rw-r--r--lib/gitlab/ci/pipeline/chain/limit/rate_limit.rb72
-rw-r--r--lib/gitlab/ci/pipeline/chain/template_usage.rb2
2 files changed, 73 insertions, 1 deletions
diff --git a/lib/gitlab/ci/pipeline/chain/limit/rate_limit.rb b/lib/gitlab/ci/pipeline/chain/limit/rate_limit.rb
new file mode 100644
index 00000000000..cb02f09f819
--- /dev/null
+++ b/lib/gitlab/ci/pipeline/chain/limit/rate_limit.rb
@@ -0,0 +1,72 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Pipeline
+ module Chain
+ module Limit
+ class RateLimit < Chain::Base
+ include Chain::Helpers
+
+ def perform!
+ return unless throttle_enabled?
+
+ # We exclude child-pipelines from the rate limit because they represent
+ # sub-pipelines that would otherwise hit the rate limit due to having the
+ # same scope (project, user, sha).
+ #
+ return if pipeline.parent_pipeline?
+
+ if rate_limit_throttled?
+ create_log_entry
+ error(throttle_message) unless dry_run?
+ end
+ end
+
+ def break?
+ @pipeline.errors.any?
+ end
+
+ private
+
+ def rate_limit_throttled?
+ ::Gitlab::ApplicationRateLimiter.throttled?(
+ :pipelines_create, scope: [project, current_user, command.sha]
+ )
+ end
+
+ def create_log_entry
+ Gitlab::AppJsonLogger.info(
+ class: self.class.name,
+ namespace_id: project.namespace_id,
+ project_id: project.id,
+ commit_sha: command.sha,
+ current_user_id: current_user.id,
+ subscription_plan: project.actual_plan_name,
+ message: 'Activated pipeline creation rate limit'
+ )
+ end
+
+ def throttle_message
+ 'Too many pipelines created in the last minute. Try again later.'
+ end
+
+ def throttle_enabled?
+ ::Feature.enabled?(
+ :ci_throttle_pipelines_creation,
+ project,
+ default_enabled: :yaml)
+ end
+
+ def dry_run?
+ ::Feature.enabled?(
+ :ci_throttle_pipelines_creation_dry_run,
+ project,
+ default_enabled: :yaml)
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/pipeline/chain/template_usage.rb b/lib/gitlab/ci/pipeline/chain/template_usage.rb
index 2fcf1740b5f..f9b3b6cd644 100644
--- a/lib/gitlab/ci/pipeline/chain/template_usage.rb
+++ b/lib/gitlab/ci/pipeline/chain/template_usage.rb
@@ -19,7 +19,7 @@ module Gitlab
def track_event(template)
Gitlab::UsageDataCounters::CiTemplateUniqueCounter
- .track_unique_project_event(project_id: pipeline.project_id, template: template, config_source: pipeline.config_source)
+ .track_unique_project_event(project: pipeline.project, template: template, config_source: pipeline.config_source, user: current_user)
end
def included_templates