2020-04-22 20:09:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'ffaker'
|
|
|
|
|
|
|
|
FactoryBot.define do
|
|
|
|
factory :alert_management_alert, class: 'AlertManagement::Alert' do
|
2020-05-12 08:09:47 -04:00
|
|
|
triggered
|
2020-04-22 20:09:41 -04:00
|
|
|
project
|
|
|
|
title { FFaker::Lorem.sentence }
|
|
|
|
started_at { Time.current }
|
|
|
|
|
2020-05-22 05:08:09 -04:00
|
|
|
trait :with_validation_errors do
|
|
|
|
after(:create) do |alert|
|
|
|
|
too_many_hosts = Array.new(AlertManagement::Alert::HOSTS_MAX_LENGTH + 1) { |_| 'host' }
|
|
|
|
alert.update_columns(hosts: too_many_hosts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-22 20:09:41 -04:00
|
|
|
trait :with_issue do
|
2020-06-29 11:08:56 -04:00
|
|
|
after(:create) do |alert|
|
|
|
|
create(:issue, alert_management_alert: alert, project: alert.project)
|
|
|
|
end
|
2020-04-22 20:09:41 -04:00
|
|
|
end
|
|
|
|
|
2020-05-29 17:08:35 -04:00
|
|
|
trait :with_assignee do |alert|
|
|
|
|
after(:create) do |alert|
|
2020-07-21 08:09:30 -04:00
|
|
|
alert.alert_assignees.create!(assignee: create(:user))
|
2020-05-29 17:08:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-22 20:09:41 -04:00
|
|
|
trait :with_fingerprint do
|
|
|
|
fingerprint { SecureRandom.hex }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_service do
|
2020-04-28 11:09:29 -04:00
|
|
|
service { FFaker::Product.product_name }
|
2020-04-22 20:09:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_monitoring_tool do
|
2020-04-28 11:09:29 -04:00
|
|
|
monitoring_tool { FFaker::AWS.product_description }
|
2020-04-22 20:09:41 -04:00
|
|
|
end
|
|
|
|
|
2020-05-18 05:08:12 -04:00
|
|
|
trait :with_description do
|
|
|
|
description { FFaker::Lorem.sentence }
|
|
|
|
end
|
|
|
|
|
2020-04-22 20:09:41 -04:00
|
|
|
trait :with_host do
|
2020-05-13 17:08:55 -04:00
|
|
|
hosts { [FFaker::Internet.ip_v4_address] }
|
2020-04-28 11:09:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_ended_at do
|
|
|
|
ended_at { Time.current }
|
2020-04-22 20:09:41 -04:00
|
|
|
end
|
|
|
|
|
2020-05-07 11:09:29 -04:00
|
|
|
trait :without_ended_at do
|
|
|
|
ended_at { nil }
|
|
|
|
end
|
|
|
|
|
2020-05-12 08:09:47 -04:00
|
|
|
trait :triggered do
|
2020-10-08 11:08:17 -04:00
|
|
|
status { AlertManagement::Alert.status_value(:triggered) }
|
2020-05-12 08:09:47 -04:00
|
|
|
without_ended_at
|
|
|
|
end
|
|
|
|
|
2020-05-07 11:09:29 -04:00
|
|
|
trait :acknowledged do
|
2020-10-08 11:08:17 -04:00
|
|
|
status { AlertManagement::Alert.status_value(:acknowledged) }
|
2020-05-07 11:09:29 -04:00
|
|
|
without_ended_at
|
|
|
|
end
|
|
|
|
|
2020-04-22 20:09:41 -04:00
|
|
|
trait :resolved do
|
2020-10-08 11:08:17 -04:00
|
|
|
status { AlertManagement::Alert.status_value(:resolved) }
|
2020-05-07 11:09:29 -04:00
|
|
|
with_ended_at
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :ignored do
|
2020-10-08 11:08:17 -04:00
|
|
|
status { AlertManagement::Alert.status_value(:ignored) }
|
2020-05-07 11:09:29 -04:00
|
|
|
without_ended_at
|
2020-04-22 20:09:41 -04:00
|
|
|
end
|
2020-04-28 11:09:29 -04:00
|
|
|
|
2020-07-03 11:09:13 -04:00
|
|
|
trait :critical do
|
|
|
|
severity { 'critical' }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :high do
|
|
|
|
severity { 'high' }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :medium do
|
|
|
|
severity { 'medium' }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :low do
|
2020-05-13 17:08:55 -04:00
|
|
|
severity { 'low' }
|
|
|
|
end
|
|
|
|
|
2020-07-03 11:09:13 -04:00
|
|
|
trait :info do
|
|
|
|
severity { 'info' }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :unknown do
|
|
|
|
severity { 'unknown' }
|
|
|
|
end
|
|
|
|
|
2020-05-15 11:08:04 -04:00
|
|
|
trait :prometheus do
|
2020-09-22 08:09:39 -04:00
|
|
|
monitoring_tool { Gitlab::AlertManagement::Payload::MONITORING_TOOLS[:prometheus] }
|
2020-07-30 02:09:55 -04:00
|
|
|
payload do
|
|
|
|
{
|
|
|
|
annotations: {
|
|
|
|
title: 'This is a prometheus error',
|
|
|
|
summary: 'Summary of the error',
|
|
|
|
description: 'Description of the error'
|
|
|
|
},
|
|
|
|
startsAt: started_at
|
|
|
|
}.with_indifferent_access
|
|
|
|
end
|
2020-05-15 11:08:04 -04:00
|
|
|
end
|
|
|
|
|
2020-04-28 11:09:29 -04:00
|
|
|
trait :all_fields do
|
|
|
|
with_issue
|
2020-05-29 17:08:35 -04:00
|
|
|
with_assignee
|
2020-04-28 11:09:29 -04:00
|
|
|
with_fingerprint
|
|
|
|
with_service
|
|
|
|
with_monitoring_tool
|
|
|
|
with_host
|
2020-05-18 05:08:12 -04:00
|
|
|
with_description
|
2020-07-03 11:09:13 -04:00
|
|
|
low
|
2020-04-28 11:09:29 -04:00
|
|
|
end
|
2020-09-22 08:09:39 -04:00
|
|
|
|
|
|
|
trait :from_payload do
|
|
|
|
after(:build) do |alert|
|
|
|
|
alert_params = ::Gitlab::AlertManagement::Payload.parse(
|
|
|
|
alert.project,
|
|
|
|
alert.payload,
|
|
|
|
monitoring_tool: alert.monitoring_tool
|
|
|
|
).alert_params
|
|
|
|
|
|
|
|
alert.assign_attributes(alert_params)
|
|
|
|
end
|
|
|
|
end
|
2020-04-22 20:09:41 -04:00
|
|
|
end
|
|
|
|
end
|