debian-mirror-gitlab/spec/factories/alert_management/alerts.rb

154 lines
3.4 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'ffaker'
FactoryBot.define do
factory :alert_management_alert, class: 'AlertManagement::Alert' do
triggered
project
title { FFaker::Lorem.sentence }
started_at { Time.current }
2020-06-23 00:09:42 +05:30
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
2021-10-27 15:23:28 +05:30
trait :with_incident do
2020-07-28 23:09:34 +05:30
after(:create) do |alert|
2021-10-27 15:23:28 +05:30
create(:incident, alert_management_alert: alert, project: alert.project)
2020-07-28 23:09:34 +05:30
end
2020-05-24 23:13:21 +05:30
end
2020-06-23 00:09:42 +05:30
trait :with_assignee do |alert|
after(:create) do |alert|
2020-10-24 23:57:45 +05:30
alert.alert_assignees.create!(assignee: create(:user))
2020-06-23 00:09:42 +05:30
end
end
2020-05-24 23:13:21 +05:30
trait :with_fingerprint do
fingerprint { SecureRandom.hex }
end
trait :with_service do
service { FFaker::Product.product_name }
end
trait :with_monitoring_tool do
monitoring_tool { FFaker::AWS.product_description }
end
trait :with_description do
description { FFaker::Lorem.sentence }
end
trait :with_host do
hosts { [FFaker::Internet.ip_v4_address] }
end
trait :without_ended_at do
ended_at { nil }
end
trait :triggered do
2021-01-03 14:25:43 +05:30
status { AlertManagement::Alert.status_value(:triggered) }
2020-05-24 23:13:21 +05:30
without_ended_at
end
trait :acknowledged do
2021-01-03 14:25:43 +05:30
status { AlertManagement::Alert.status_value(:acknowledged) }
2020-05-24 23:13:21 +05:30
without_ended_at
end
trait :resolved do
2021-01-03 14:25:43 +05:30
status { AlertManagement::Alert.status_value(:resolved) }
2021-04-17 20:07:23 +05:30
ended_at { Time.current }
2020-05-24 23:13:21 +05:30
end
trait :ignored do
2021-01-03 14:25:43 +05:30
status { AlertManagement::Alert.status_value(:ignored) }
2020-05-24 23:13:21 +05:30
without_ended_at
end
2020-07-28 23:09:34 +05:30
trait :critical do
severity { 'critical' }
end
trait :high do
severity { 'high' }
end
trait :medium do
severity { 'medium' }
end
trait :low do
2020-05-24 23:13:21 +05:30
severity { 'low' }
end
2020-07-28 23:09:34 +05:30
trait :info do
severity { 'info' }
end
trait :unknown do
severity { 'unknown' }
end
2021-06-08 01:23:25 +05:30
trait :threat_monitoring do
domain { :threat_monitoring }
end
2020-05-24 23:13:21 +05:30
trait :prometheus do
2021-01-03 14:25:43 +05:30
monitoring_tool { Gitlab::AlertManagement::Payload::MONITORING_TOOLS[:prometheus] }
2020-08-18 19:51:02 +05:30
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-24 23:13:21 +05:30
end
2021-06-08 01:23:25 +05:30
trait :cilium do
monitoring_tool { Gitlab::AlertManagement::Payload::MONITORING_TOOLS[:cilium] }
payload do
{
annotations: {
title: 'This is a cilium alert',
summary: 'Summary of the alert',
description: 'Description of the alert'
},
startsAt: started_at
}.with_indifferent_access
end
end
2020-05-24 23:13:21 +05:30
trait :all_fields do
2021-10-27 15:23:28 +05:30
with_incident
2020-06-23 00:09:42 +05:30
with_assignee
2020-05-24 23:13:21 +05:30
with_fingerprint
with_service
with_monitoring_tool
with_host
with_description
2020-07-28 23:09:34 +05:30
low
2020-05-24 23:13:21 +05:30
end
2021-01-03 14:25:43 +05:30
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-05-24 23:13:21 +05:30
end
end