diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 15:09:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 15:09:47 +0300 |
commit | 8f9beefac3774b30e911fb00a68f4c7a5244cf27 (patch) | |
tree | 919c3a043f8c10bc3f78f3f6e029acfb6b972556 /app/models/self_managed_prometheus_alert_event.rb | |
parent | e4bf776a8829e5186a0f63603c0be627b891d80e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/self_managed_prometheus_alert_event.rb')
-rw-r--r-- | app/models/self_managed_prometheus_alert_event.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/models/self_managed_prometheus_alert_event.rb b/app/models/self_managed_prometheus_alert_event.rb new file mode 100644 index 00000000000..d2d4a5c37d4 --- /dev/null +++ b/app/models/self_managed_prometheus_alert_event.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class SelfManagedPrometheusAlertEvent < ApplicationRecord + include AlertEventLifecycle + + belongs_to :project, validate: true, inverse_of: :self_managed_prometheus_alert_events + belongs_to :environment, validate: true, inverse_of: :self_managed_prometheus_alert_events + has_and_belongs_to_many :related_issues, class_name: 'Issue', join_table: :issues_self_managed_prometheus_alert_events # rubocop:disable Rails/HasAndBelongsToMany + + validates :started_at, presence: true + validates :payload_key, uniqueness: { scope: :project_id } + + def self.find_or_initialize_by_payload_key(project, payload_key) + find_or_initialize_by(project: project, payload_key: payload_key) do |event| + yield event if block_given? + end + end + + def self.payload_key_for(started_at, alert_name, query_expression) + plain = [started_at, alert_name, query_expression].join('/') + + Digest::SHA1.hexdigest(plain) + end +end |