diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /app/models/hooks | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'app/models/hooks')
-rw-r--r-- | app/models/hooks/project_hook.rb | 1 | ||||
-rw-r--r-- | app/models/hooks/service_hook.rb | 1 | ||||
-rw-r--r-- | app/models/hooks/system_hook.rb | 1 | ||||
-rw-r--r-- | app/models/hooks/web_hook.rb | 57 |
4 files changed, 2 insertions, 58 deletions
diff --git a/app/models/hooks/project_hook.rb b/app/models/hooks/project_hook.rb index 8e9a74a68d0..695041f0247 100644 --- a/app/models/hooks/project_hook.rb +++ b/app/models/hooks/project_hook.rb @@ -2,7 +2,6 @@ class ProjectHook < WebHook include TriggerableHooks - include WebHooks::AutoDisabling include Presentable include Limitable extend ::Gitlab::Utils::Override diff --git a/app/models/hooks/service_hook.rb b/app/models/hooks/service_hook.rb index 6af70c249a0..453b986ca4d 100644 --- a/app/models/hooks/service_hook.rb +++ b/app/models/hooks/service_hook.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class ServiceHook < WebHook - include WebHooks::Unstoppable include Presentable extend ::Gitlab::Utils::Override diff --git a/app/models/hooks/system_hook.rb b/app/models/hooks/system_hook.rb index eaffe83cab3..3c7f0ef9ffc 100644 --- a/app/models/hooks/system_hook.rb +++ b/app/models/hooks/system_hook.rb @@ -2,7 +2,6 @@ class SystemHook < WebHook include TriggerableHooks - include WebHooks::Unstoppable triggerable_hooks [ :repository_update_hooks, diff --git a/app/models/hooks/web_hook.rb b/app/models/hooks/web_hook.rb index 7202a530feb..5ccbc926a71 100644 --- a/app/models/hooks/web_hook.rb +++ b/app/models/hooks/web_hook.rb @@ -2,15 +2,10 @@ class WebHook < ApplicationRecord include Sortable + include WebHooks::AutoDisabling InterpolationError = Class.new(StandardError) - MAX_FAILURES = 100 - FAILURE_THRESHOLD = 3 # three strikes - EXCEEDED_FAILURE_THRESHOLD = FAILURE_THRESHOLD + 1 - INITIAL_BACKOFF = 1.minute - MAX_BACKOFF = 1.day - BACKOFF_GROWTH_FACTOR = 2.0 SECRET_MASK = '************' attr_encrypted :token, @@ -78,46 +73,6 @@ class WebHook < ApplicationRecord 'user/project/integrations/webhooks' end - def next_backoff - return MAX_BACKOFF if backoff_count >= 8 # optimization to prevent expensive exponentiation and possible overflows - - (INITIAL_BACKOFF * (BACKOFF_GROWTH_FACTOR**backoff_count)) - .clamp(INITIAL_BACKOFF, MAX_BACKOFF) - .seconds - end - - def disable! - update_attribute(:recent_failures, EXCEEDED_FAILURE_THRESHOLD) - end - - def enable! - return if recent_failures == 0 && disabled_until.nil? && backoff_count == 0 - - assign_attributes(recent_failures: 0, disabled_until: nil, backoff_count: 0) - save(validate: false) - end - - # Don't actually back-off until FAILURE_THRESHOLD failures have been seen - # we mark the grace-period using the recent_failures counter - def backoff! - attrs = { recent_failures: next_failure_count } - - if recent_failures >= FAILURE_THRESHOLD - attrs[:backoff_count] = next_backoff_count - attrs[:disabled_until] = next_backoff.from_now - end - - assign_attributes(attrs) - save(validate: false) if changed? - end - - def failed! - return unless recent_failures < MAX_FAILURES - - assign_attributes(disabled_until: nil, backoff_count: 0, recent_failures: next_failure_count) - save(validate: false) - end - # @return [Boolean] Whether or not the WebHook is currently throttled. def rate_limited? rate_limiter.rate_limited? @@ -178,7 +133,7 @@ class WebHook < ApplicationRecord def reset_url_variables interpolated_url_was = interpolated_url(decrypt_url_was, url_variables_were) - return if url_variables_were.empty? || interpolated_url_was == interpolated_url + return if url_variables_were.blank? || interpolated_url_was == interpolated_url self.url_variables = {} if url_changed? && url_variables_were.to_a.intersection(url_variables.to_a).any? end @@ -191,14 +146,6 @@ class WebHook < ApplicationRecord self.class.decrypt_url_variables(encrypted_url_variables_was, iv: encrypted_url_variables_iv_was) end - def next_failure_count - recent_failures.succ.clamp(1, MAX_FAILURES) - end - - def next_backoff_count - backoff_count.succ.clamp(1, MAX_FAILURES) - end - def initialize_url_variables self.url_variables = {} if encrypted_url_variables.nil? end |