Commit 00d8836c authored by Ramya Authappan's avatar Ramya Authappan

Merge branch 'refactor-monitor-specs' into 'master'

Refactor monitor tests to use a shared context

Closes #222278

See merge request gitlab-org/gitlab!40141
parents 6691e962 50acbf44
# frozen_string_literal: true # frozen_string_literal: true
require_relative 'cluster_with_prometheus.rb'
module QA module QA
RSpec.describe 'Monitor' do RSpec.describe 'Monitor', :orchestrated, :kubernetes, :requires_admin do
describe 'with Prometheus in a Gitlab-managed cluster', :orchestrated, :kubernetes, :requires_admin do include_context "cluster with Prometheus installed"
before :all do
@cluster = Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create!
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'monitoring-project'
project.auto_devops_enabled = true
project.template_name = 'express'
end
deploy_project_with_prometheus
end
before do
Flow::Login.sign_in_unless_signed_in
@project.visit!
end
after :all do before do
@cluster.remove! Flow::Login.sign_in_unless_signed_in
end @project.visit!
end
it 'configures custom metrics' do it 'configures custom metrics' do
verify_add_custom_metric verify_add_custom_metric
verify_edit_custom_metric verify_edit_custom_metric
verify_delete_custom_metric verify_delete_custom_metric
end end
it 'duplicates to create dashboard to custom' do it 'duplicates to create dashboard to custom' do
Page::Project::Menu.perform(&:go_to_operations_metrics) Page::Project::Menu.perform(&:go_to_operations_metrics)
Page::Project::Operations::Metrics::Show.perform do |on_dashboard| Page::Project::Operations::Metrics::Show.perform do |on_dashboard|
on_dashboard.duplicate_dashboard on_dashboard.duplicate_dashboard
expect(on_dashboard).to have_metrics expect(on_dashboard).to have_metrics
expect(on_dashboard).to have_edit_dashboard_enabled expect(on_dashboard).to have_edit_dashboard_enabled
end
end end
end
it 'verifies data on filtered deployed environment' do it 'verifies data on filtered deployed environment' do
Page::Project::Menu.perform(&:go_to_operations_metrics) Page::Project::Menu.perform(&:go_to_operations_metrics)
Page::Project::Operations::Metrics::Show.perform do |on_dashboard| Page::Project::Operations::Metrics::Show.perform do |on_dashboard|
on_dashboard.filter_environment on_dashboard.filter_environment
expect(on_dashboard).to have_metrics expect(on_dashboard).to have_metrics
end
end end
end
it 'filters using the quick range' do it 'filters using the quick range' do
Page::Project::Menu.perform(&:go_to_operations_metrics) Page::Project::Menu.perform(&:go_to_operations_metrics)
Page::Project::Operations::Metrics::Show.perform do |on_dashboard| Page::Project::Operations::Metrics::Show.perform do |on_dashboard|
on_dashboard.show_last('30 minutes') on_dashboard.show_last('30 minutes')
expect(on_dashboard).to have_metrics expect(on_dashboard).to have_metrics
on_dashboard.show_last('3 hours') on_dashboard.show_last('3 hours')
expect(on_dashboard).to have_metrics expect(on_dashboard).to have_metrics
on_dashboard.show_last('1 day') on_dashboard.show_last('1 day')
expect(on_dashboard).to have_metrics expect(on_dashboard).to have_metrics
end
end end
end
it 'observes cluster health graph' do it 'observes cluster health graph' do
Page::Project::Menu.perform(&:go_to_operations_kubernetes) Page::Project::Menu.perform(&:go_to_operations_kubernetes)
Page::Project::Operations::Kubernetes::Index.perform do |cluster_list| Page::Project::Operations::Kubernetes::Index.perform do |cluster_list|
cluster_list.click_on_cluster(@cluster) cluster_list.click_on_cluster(@cluster)
end end
Page::Project::Operations::Kubernetes::Show.perform do |cluster_panel| Page::Project::Operations::Kubernetes::Show.perform do |cluster_panel|
cluster_panel.open_health cluster_panel.open_health
cluster_panel.wait_for_cluster_health cluster_panel.wait_for_cluster_health
end
end end
end
it 'uses templating variables for metrics dashboards' do it 'uses templating variables for metrics dashboards' do
templating_dashboard_yml = Pathname templating_dashboard_yml = Pathname
.new(__dir__) .new(__dir__)
.join('../../../../fixtures/metrics_dashboards/templating.yml') .join('../../../../fixtures/metrics_dashboards/templating.yml')
Resource::Repository::ProjectPush.fabricate! do |push| Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @project push.project = @project
push.file_name = '.gitlab/dashboards/templating.yml' push.file_name = '.gitlab/dashboards/templating.yml'
push.file_content = File.read(templating_dashboard_yml) push.file_content = File.read(templating_dashboard_yml)
push.commit_message = 'Add templating in dashboard file' push.commit_message = 'Add templating in dashboard file'
push.new_branch = false push.new_branch = false
end
Page::Project::Menu.perform(&:go_to_operations_metrics)
Page::Project::Operations::Metrics::Show.perform do |dashboard|
dashboard.select_dashboard('templating.yml')
expect(dashboard).to have_template_metric('CPU usage GitLab Runner')
expect(dashboard).to have_template_metric('Memory usage Postgresql')
expect(dashboard).to have_templating_variable('GitLab Runner')
expect(dashboard).to have_templating_variable('Postgresql')
end
end end
private Page::Project::Menu.perform(&:go_to_operations_metrics)
def deploy_project_with_prometheus Page::Project::Operations::Metrics::Show.perform do |dashboard|
%w[ dashboard.select_dashboard('templating.yml')
CODE_QUALITY_DISABLED TEST_DISABLED LICENSE_MANAGEMENT_DISABLED
SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED expect(dashboard).to have_template_metric('CPU usage GitLab Runner')
CONTAINER_SCANNING_DISABLED PERFORMANCE_DISABLED SECRET_DETECTION_DISABLED expect(dashboard).to have_template_metric('Memory usage Postgresql')
].each do |key| expect(dashboard).to have_templating_variable('GitLab Runner')
Resource::CiVariable.fabricate_via_api! do |resource| expect(dashboard).to have_templating_variable('Postgresql')
resource.project = @project
resource.key = key
resource.value = '1'
resource.masked = false
end
end
Flow::Login.sign_in
Resource::KubernetesCluster::ProjectCluster.fabricate! do |cluster_settings|
cluster_settings.project = @project
cluster_settings.cluster = @cluster
cluster_settings.install_runner = true
cluster_settings.install_ingress = true
cluster_settings.install_prometheus = true
end
Resource::Pipeline.fabricate_via_api! do |pipeline|
pipeline.project = @project
end.visit!
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('build')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 600)
job.click_element(:pipeline_path)
end
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('production')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 1200)
job.click_element(:pipeline_path)
end
end end
end
private
def verify_add_custom_metric def verify_add_custom_metric
Page::Project::Menu.perform(&:go_to_integrations_settings) Page::Project::Menu.perform(&:go_to_integrations_settings)
Page::Project::Settings::Integrations.perform(&:click_on_prometheus_integration) Page::Project::Settings::Integrations.perform(&:click_on_prometheus_integration)
Page::Project::Settings::Services::Prometheus.perform do |metrics_panel| Page::Project::Settings::Services::Prometheus.perform do |metrics_panel|
metrics_panel.click_on_new_metric metrics_panel.click_on_new_metric
metrics_panel.add_custom_metric metrics_panel.add_custom_metric
end end
Page::Project::Menu.perform(&:go_to_operations_metrics) Page::Project::Menu.perform(&:go_to_operations_metrics)
Page::Project::Operations::Metrics::Show.perform do |on_dashboard| Page::Project::Operations::Metrics::Show.perform do |on_dashboard|
expect(on_dashboard).to have_custom_metric('HTTP Requests Total') expect(on_dashboard).to have_custom_metric('HTTP Requests Total')
end
end end
end
def verify_edit_custom_metric def verify_edit_custom_metric
Page::Project::Menu.perform(&:go_to_integrations_settings) Page::Project::Menu.perform(&:go_to_integrations_settings)
Page::Project::Settings::Integrations.perform(&:click_on_prometheus_integration) Page::Project::Settings::Integrations.perform(&:click_on_prometheus_integration)
Page::Project::Settings::Services::Prometheus.perform do |metrics_panel| Page::Project::Settings::Services::Prometheus.perform do |metrics_panel|
metrics_panel.click_on_custom_metric('Business / HTTP Requests Total (req/sec)') metrics_panel.click_on_custom_metric('Business / HTTP Requests Total (req/sec)')
metrics_panel.edit_custom_metric metrics_panel.edit_custom_metric
end end
Page::Project::Menu.perform(&:go_to_operations_metrics) Page::Project::Menu.perform(&:go_to_operations_metrics)
Page::Project::Operations::Metrics::Show.perform do |on_dashboard| Page::Project::Operations::Metrics::Show.perform do |on_dashboard|
expect(on_dashboard).to have_custom_metric('Throughput') expect(on_dashboard).to have_custom_metric('Throughput')
end
end end
end
def verify_delete_custom_metric def verify_delete_custom_metric
Page::Project::Menu.perform(&:go_to_integrations_settings) Page::Project::Menu.perform(&:go_to_integrations_settings)
Page::Project::Settings::Integrations.perform(&:click_on_prometheus_integration) Page::Project::Settings::Integrations.perform(&:click_on_prometheus_integration)
Page::Project::Settings::Services::Prometheus.perform do |metrics_panel| Page::Project::Settings::Services::Prometheus.perform do |metrics_panel|
metrics_panel.click_on_custom_metric('Business / Throughput (req/sec)') metrics_panel.click_on_custom_metric('Business / Throughput (req/sec)')
metrics_panel.delete_custom_metric metrics_panel.delete_custom_metric
end end
Page::Project::Menu.perform(&:go_to_operations_metrics) Page::Project::Menu.perform(&:go_to_operations_metrics)
Page::Project::Operations::Metrics::Show.perform do |on_dashboard| Page::Project::Operations::Metrics::Show.perform do |on_dashboard|
expect(on_dashboard).not_to have_custom_metric('Throughput') expect(on_dashboard).not_to have_custom_metric('Throughput')
end
end end
end end
end end
......
# frozen_string_literal: true
module QA
RSpec.configure do |rspec|
# This config option will be enabled by default on RSpec 4,
# but for reasons of backwards compatibility, you have to
# set it on RSpec 3.
#
# It causes the host group and examples to inherit metadata
# from the shared context.
rspec.shared_context_metadata_behavior = :apply_to_host_groups
end
RSpec.shared_context "cluster with Prometheus installed", shared_context: :metadata do
before :all do
@cluster = Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create!
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'monitoring-project'
project.auto_devops_enabled = true
project.template_name = 'express'
end
deploy_project_with_prometheus
end
def deploy_project_with_prometheus
%w[
CODE_QUALITY_DISABLED TEST_DISABLED LICENSE_MANAGEMENT_DISABLED
SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED
CONTAINER_SCANNING_DISABLED PERFORMANCE_DISABLED SECRET_DETECTION_DISABLED
].each do |key|
Resource::CiVariable.fabricate_via_api! do |resource|
resource.project = @project
resource.key = key
resource.value = '1'
resource.masked = false
end
end
Flow::Login.sign_in
Resource::KubernetesCluster::ProjectCluster.fabricate! do |cluster_settings|
cluster_settings.project = @project
cluster_settings.cluster = @cluster
cluster_settings.install_runner = true
cluster_settings.install_ingress = true
cluster_settings.install_prometheus = true
end
Resource::Pipeline.fabricate_via_api! do |pipeline|
pipeline.project = @project
end.visit!
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('build')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 600)
job.click_element(:pipeline_path)
end
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('production')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 1200)
job.click_element(:pipeline_path)
end
end
after :all do
@cluster.remove!
end
end
end
# frozen_string_literal: true # frozen_string_literal: true
require 'pathname' require 'pathname'
require_relative 'cluster_with_prometheus.rb'
module QA module QA
RSpec.describe 'Monitor' do RSpec.describe 'Monitor', :orchestrated, :kubernetes, :requires_admin do
describe 'with Prometheus in a Gitlab-managed cluster', :orchestrated, :kubernetes, :requires_admin do include_context "cluster with Prometheus installed"
before :all do
@cluster = Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create!
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'monitoring-project'
project.auto_devops_enabled = true
project.template_name = 'express'
end
deploy_project_with_prometheus
end
after :all do before do
@cluster.remove! Flow::Login.sign_in_unless_signed_in
end @project.visit!
end
before do
Flow::Login.sign_in_unless_signed_in
@project.visit!
end
it 'allows configuration of alerts', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/233409', type: :flaky } do it 'allows configuration of alerts', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/233409', type: :flaky } do
Page::Project::Menu.perform(&:go_to_operations_metrics) Page::Project::Menu.perform(&:go_to_operations_metrics)
Page::Project::Operations::Metrics::Show.perform do |on_dashboard| Page::Project::Operations::Metrics::Show.perform do |on_dashboard|
verify_metrics(on_dashboard) verify_metrics(on_dashboard)
verify_add_alert(on_dashboard) verify_add_alert(on_dashboard)
verify_edit_alert(on_dashboard) verify_edit_alert(on_dashboard)
verify_persist_alert(on_dashboard) verify_persist_alert(on_dashboard)
verify_delete_alert(on_dashboard) verify_delete_alert(on_dashboard)
end
end end
end
it 'creates an incident template and opens an incident with template applied', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/236203', type: :investigating } do it 'creates an incident template and opens an incident with template applied', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/236203', type: :investigating } do
create_incident_template create_incident_template
Page::Project::Menu.perform(&:go_to_operations_settings) Page::Project::Menu.perform(&:go_to_operations_settings)
Page::Project::Settings::Operations.perform do |settings| Page::Project::Settings::Operations.perform do |settings|
settings.expand_incidents do |incident_settings| settings.expand_incidents do |incident_settings|
incident_settings.enable_issues_for_incidents incident_settings.enable_issues_for_incidents
incident_settings.select_issue_template('incident') incident_settings.select_issue_template('incident')
incident_settings.save_incident_settings incident_settings.save_incident_settings
end
end
create_incident_issue
Page::Project::Issue::Show.perform do |issue|
expect(issue).to have_metrics_unfurled
end end
end end
private create_incident_issue
def deploy_project_with_prometheus
%w[
CODE_QUALITY_DISABLED TEST_DISABLED LICENSE_MANAGEMENT_DISABLED
SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED
CONTAINER_SCANNING_DISABLED PERFORMANCE_DISABLED SECRET_DETECTION_DISABLED
].each do |key|
Resource::CiVariable.fabricate_via_api! do |resource|
resource.project = @project
resource.key = key
resource.value = '1'
resource.masked = false
end
end
Flow::Login.sign_in Page::Project::Issue::Show.perform do |issue|
expect(issue).to have_metrics_unfurled
end
end
Resource::KubernetesCluster::ProjectCluster.fabricate! do |cluster_settings| private
cluster_settings.project = @project
cluster_settings.cluster = @cluster
cluster_settings.install_runner = true
cluster_settings.install_ingress = true
cluster_settings.install_prometheus = true
end
Resource::Pipeline.fabricate_via_api! do |pipeline| def verify_metrics(on_dashboard)
pipeline.project = @project on_dashboard.wait_for_metrics
end.visit!
Page::Project::Pipeline::Show.perform do |pipeline| expect(on_dashboard).to have_metrics
pipeline.click_job('build') expect(on_dashboard).not_to have_alert
end end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 600)
job.click_element(:pipeline_path) def verify_add_alert(on_dashboard)
end on_dashboard.write_first_alert('>', 0)
Page::Project::Pipeline::Show.perform do |pipeline| expect(on_dashboard).to have_alert
pipeline.click_job('production') end
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 1200)
job.click_element(:pipeline_path) def verify_edit_alert(on_dashboard)
end on_dashboard.write_first_alert('<', 0)
end
def verify_metrics(on_dashboard) expect(on_dashboard).to have_alert('<')
on_dashboard.wait_for_metrics end
expect(on_dashboard).to have_metrics def verify_persist_alert(on_dashboard)
expect(on_dashboard).not_to have_alert on_dashboard.refresh
end on_dashboard.wait_for_metrics
on_dashboard.wait_for_alert('<')
def verify_add_alert(on_dashboard) expect(on_dashboard).to have_alert('<')
on_dashboard.write_first_alert('>', 0) end
expect(on_dashboard).to have_alert def verify_delete_alert(on_dashboard)
end on_dashboard.delete_first_alert
def verify_edit_alert(on_dashboard) expect(on_dashboard).not_to have_alert('<')
on_dashboard.write_first_alert('<', 0) end
expect(on_dashboard).to have_alert('<') def create_incident_template
end Page::Project::Menu.perform(&:go_to_operations_metrics)
def verify_persist_alert(on_dashboard) chart_link = Page::Project::Operations::Metrics::Show.perform do |on_dashboard|
on_dashboard.refresh
on_dashboard.wait_for_metrics on_dashboard.wait_for_metrics
on_dashboard.wait_for_alert('<') on_dashboard.copy_link_to_first_chart
expect(on_dashboard).to have_alert('<')
end end
def verify_delete_alert(on_dashboard) incident_template = "Incident Metric: #{chart_link}"
on_dashboard.delete_first_alert push_template_to_repository(incident_template)
end
expect(on_dashboard).not_to have_alert('<')
end
def create_incident_template def push_template_to_repository(template)
Page::Project::Menu.perform(&:go_to_operations_metrics) @project.visit!
chart_link = Page::Project::Operations::Metrics::Show.perform do |on_dashboard| Page::Project::Show.perform(&:create_new_file!)
on_dashboard.wait_for_metrics
on_dashboard.copy_link_to_first_chart
end
incident_template = "Incident Metric: #{chart_link}" Page::File::Form.perform do |form|
push_template_to_repository(incident_template) form.add_name('.gitlab/issue_templates/incident.md')
form.add_content(template)
form.add_commit_message('Add Incident template')
form.commit_changes
end end
end
def push_template_to_repository(template) def create_incident_issue
@project.visit! Page::Project::Menu.perform(&:go_to_operations_incidents)
Page::Project::Show.perform(&:create_new_file!)
Page::File::Form.perform do |form| Page::Project::Operations::Incidents::Index.perform do |incidents_page|
form.add_name('.gitlab/issue_templates/incident.md') incidents_page.create_incident
form.add_content(template)
form.add_commit_message('Add Incident template')
form.commit_changes
end
end end
def create_incident_issue Page::Project::Issue::New.perform do |new_issue|
Page::Project::Menu.perform(&:go_to_operations_incidents) new_issue.fill_title('test incident')
new_issue.create_new_issue
Page::Project::Operations::Incidents::Index.perform do |incidents_page|
incidents_page.create_incident
end
Page::Project::Issue::New.perform do |new_issue|
new_issue.fill_title('test incident')
new_issue.create_new_issue
end
end end
end end
end end
......
# frozen_string_literal: true
#
module QA
RSpec.configure do |rspec|
# This config option will be enabled by default on RSpec 4,
# but for reasons of backwards compatibility, you have to
# set it on RSpec 3.
#
# It causes the host group and examples to inherit metadata
# from the shared context.
rspec.shared_context_metadata_behavior = :apply_to_host_groups
end
RSpec.shared_context "cluster with Prometheus installed", shared_context: :metadata do
before :all do
@cluster = Service::KubernetesCluster.new(provider_class: Service::ClusterProvider::K3s).create!
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'monitoring-project'
project.auto_devops_enabled = true
project.template_name = 'express'
end
deploy_project_with_prometheus
end
def deploy_project_with_prometheus
%w[
CODE_QUALITY_DISABLED TEST_DISABLED LICENSE_MANAGEMENT_DISABLED
SAST_DISABLED DAST_DISABLED DEPENDENCY_SCANNING_DISABLED
CONTAINER_SCANNING_DISABLED PERFORMANCE_DISABLED SECRET_DETECTION_DISABLED
].each do |key|
Resource::CiVariable.fabricate_via_api! do |resource|
resource.project = @project
resource.key = key
resource.value = '1'
resource.masked = false
end
end
Flow::Login.sign_in
Resource::KubernetesCluster::ProjectCluster.fabricate! do |cluster_settings|
cluster_settings.project = @project
cluster_settings.cluster = @cluster
cluster_settings.install_runner = true
cluster_settings.install_ingress = true
cluster_settings.install_prometheus = true
end
Resource::Pipeline.fabricate_via_api! do |pipeline|
pipeline.project = @project
end.visit!
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('build')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 600)
job.click_element(:pipeline_path)
end
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('production')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 1200)
job.click_element(:pipeline_path)
end
end
after :all do
@cluster.remove!
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment