diff options
Diffstat (limited to 'lib/gitlab/alert_management')
-rw-r--r-- | lib/gitlab/alert_management/alert_params.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/alert_management/fingerprint.rb | 27 |
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/gitlab/alert_management/alert_params.rb b/lib/gitlab/alert_management/alert_params.rb index 982479784a9..789a4fe246a 100644 --- a/lib/gitlab/alert_management/alert_params.rb +++ b/lib/gitlab/alert_management/alert_params.rb @@ -20,7 +20,8 @@ module Gitlab hosts: Array(annotations[:hosts]), payload: payload, started_at: parsed_payload['startsAt'], - severity: annotations[:severity] + severity: annotations[:severity], + fingerprint: annotations[:fingerprint] } end diff --git a/lib/gitlab/alert_management/fingerprint.rb b/lib/gitlab/alert_management/fingerprint.rb new file mode 100644 index 00000000000..6ab47c88ca1 --- /dev/null +++ b/lib/gitlab/alert_management/fingerprint.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Gitlab + module AlertManagement + class Fingerprint + def self.generate(data) + new.generate(data) + end + + def generate(data) + return unless data.present? + + if data.is_a?(Array) + data = flatten_array(data) + end + + Digest::SHA1.hexdigest(data.to_s) + end + + private + + def flatten_array(array) + array.flatten.map!(&:to_s).join + end + end + end +end |