diff options
Diffstat (limited to 'qa/qa/specs/features/browser_ui/8_monitor')
4 files changed, 221 insertions, 9 deletions
diff --git a/qa/qa/specs/features/browser_ui/8_monitor/alert_management/alert_settings_create_new_alerts_spec.rb b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/alert_settings_create_new_alerts_spec.rb index 2b7dd8fb673..b44020ddfce 100644 --- a/qa/qa/specs/features/browser_ui/8_monitor/alert_management/alert_settings_create_new_alerts_spec.rb +++ b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/alert_settings_create_new_alerts_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module QA - RSpec.describe 'Monitor', product_group: :respond do + RSpec.describe 'Monitor', :smoke, product_group: :respond do describe 'Alert settings' do shared_examples 'sends test alert' do it 'creates new alert' do @@ -24,6 +24,7 @@ module QA before do Flow::Login.sign_in project.visit! + Flow::AlertSettings.go_to_monitor_settings end context( @@ -35,7 +36,8 @@ module QA end before do - Flow::AlertSettings.setup_http_endpoint(payload: payload) + Flow::AlertSettings.setup_http_endpoint_integration + Flow::AlertSettings.send_test_alert(payload: payload) end it_behaves_like 'sends test alert' @@ -73,7 +75,8 @@ module QA end before do - Flow::AlertSettings.setup_prometheus(payload: payload) + Flow::AlertSettings.setup_prometheus_integration + Flow::AlertSettings.send_test_alert(payload: payload) end it_behaves_like 'sends test alert' diff --git a/qa/qa/specs/features/browser_ui/8_monitor/alert_management/automatically_creates_incident_for_alert_spec.rb b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/automatically_creates_incident_for_alert_spec.rb new file mode 100644 index 00000000000..565f56b90ec --- /dev/null +++ b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/automatically_creates_incident_for_alert_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +module QA + RSpec.describe 'Monitor', product_group: :respond do + describe 'Alert' do + shared_examples 'new alert' do + it 'automatically creates new incident' do + Page::Project::Menu.perform(&:go_to_monitor_incidents) + Page::Project::Monitor::Incidents::Index.perform do |index| + expect(index).to have_incident + end + end + end + + let(:project) do + Resource::Project.fabricate_via_api! do |project| + project.name = 'project-for-alerts' + project.description = 'Project for alerts' + end + end + + before do + Flow::Login.sign_in + project.visit! + Flow::AlertSettings.go_to_monitor_settings + Flow::AlertSettings.enable_create_incident + end + + context( + 'when using HTTP endpoint integration', + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/388469' + ) do + before do + Flow::AlertSettings.setup_http_endpoint_integration + Flow::AlertSettings.send_test_alert + end + + it_behaves_like 'new alert' + end + + context( + 'when using Prometheus integration', + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/390123' + ) do + before do + Flow::AlertSettings.setup_prometheus_integration + Flow::AlertSettings.send_test_alert(integration_type: 'prometheus') + end + + it_behaves_like 'new alert' + end + end + end +end diff --git a/qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb index 9d4aff59e48..96db10c1683 100644 --- a/qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb +++ b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module QA - RSpec.describe 'Monitor', product_group: :respond do + RSpec.describe 'Monitor', :smoke, product_group: :respond do describe 'Alert settings' do shared_examples 'sends test alert using authorization key' do |type| it 'creates new alert', :aggregate_failures do @@ -22,7 +22,8 @@ module QA Page::Project::Menu.perform(&:go_to_monitor_alerts) Page::Project::Monitor::Alerts::Index.perform do |index| - expect(index).to have_alert_with_title(alert_title) + expect { index.has_alert_with_title?(alert_title) } + .to eventually_be_truthy.within(max_duration: 60, reload_page: index) end end end @@ -36,9 +37,14 @@ module QA let(:alert_title) { Faker::Lorem.word } + let(:credentials) do + Flow::AlertSettings.integration_credentials + end + before do Flow::Login.sign_in project.visit! + Flow::AlertSettings.go_to_monitor_settings end context( @@ -49,8 +55,8 @@ module QA { title: alert_title, description: alert_title } end - let(:credentials) do - Flow::AlertSettings.setup_http_endpoint(send: false) + before do + Flow::AlertSettings.setup_http_endpoint_integration end it_behaves_like 'sends test alert using authorization key', 'http' @@ -87,8 +93,8 @@ module QA } end - let(:credentials) do - Flow::AlertSettings.setup_prometheus(send: false) + before do + Flow::AlertSettings.setup_prometheus_integration end it_behaves_like 'sends test alert using authorization key' diff --git a/qa/qa/specs/features/browser_ui/8_monitor/alert_management/email_notification_for_alert_spec.rb b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/email_notification_for_alert_spec.rb new file mode 100644 index 00000000000..70874e46f27 --- /dev/null +++ b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/email_notification_for_alert_spec.rb @@ -0,0 +1,149 @@ +# frozen_string_literal: true + +module QA + RSpec.describe 'Monitor', :orchestrated, :smtp, :requires_admin, product_group: :respond do + describe 'Alert' do + shared_examples 'notification on new alert', :aggregate_failures do + it 'sends email to user' do + expect { email_subjects }.to eventually_include(alert_email_subject).within(max_duration: 60) + expect(recipient_email_addresses).to include(user.email) + end + end + + let!(:admin_api_client) { Runtime::API::Client.as_admin } + + let!(:user) do + Resource::User.fabricate_via_api! do |user| + user.api_client = admin_api_client + user.hard_delete_on_api_removal = true + end + end + + let(:project) do + Resource::Project.fabricate_via_api! do |project| + project.name = 'project-for-alerts' + project.description = 'Project for alerts' + end + end + + let(:alert_title) { Faker::Lorem.word } + let(:mail_hog_api) { Vendor::MailHog::API.new } + let(:alert_email_subject) { "#{project.name} | Alert: #{alert_title}" } + let(:http_payload) { { title: alert_title, description: alert_title } } + + let(:prometheus_payload) do + { + version: '4', + groupKey: nil, + status: 'firing', + receiver: '', + groupLabels: {}, + commonLabels: {}, + commonAnnotations: {}, + externalURL: '', + alerts: [ + { + startsAt: Time.now, + generatorURL: Faker::Internet.url, + endsAt: nil, + status: 'firing', + labels: { gitlab_environment_name: Faker::Lorem.word }, + annotations: + { + title: alert_title, + gitlab_y_label: 'status' + } + } + ] + } + end + + before do + Flow::Login.sign_in + project.visit! + Flow::AlertSettings.go_to_monitor_settings + Flow::AlertSettings.enable_email_notification + end + + context 'when user is a maintainer' do + before do + project.add_member(user, Resource::Members::AccessLevel::MAINTAINER) + end + + context( + 'when using HTTP endpoint integration', + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/389993' + ) do + before do + send_http_alert + end + + it_behaves_like 'notification on new alert' + end + + context( + 'when using Prometheus integration', + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/389994' + ) do + before do + send_prometheus_alert + end + + it_behaves_like 'notification on new alert' + end + end + + context 'when user is an owner' do + before do + project.add_member(user, Resource::Members::AccessLevel::OWNER) + end + + context( + 'when using HTTP endpoint integration', + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/390145' + ) do + before do + send_http_alert + end + + it_behaves_like 'notification on new alert' + end + + context( + 'when using Prometheus integration', + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/390144' + ) do + before do + send_prometheus_alert + end + + it_behaves_like 'notification on new alert' + end + end + + private + + def send_http_alert + Flow::AlertSettings.setup_http_endpoint_integration + Flow::AlertSettings.send_test_alert(payload: http_payload) + end + + def send_prometheus_alert + Flow::AlertSettings.setup_prometheus_integration + Flow::AlertSettings.send_test_alert(payload: prometheus_payload) + end + + def mail_hog_messages + mail_hog_api.fetch_messages + end + + def email_subjects + mail_hog_messages.map(&:subject) + end + + def recipient_email_addresses + mail_hog_messages.map(&:to) + end + end + end +end |