2020-07-13 15:09:08 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Cluster Health board', :js, :kubeclient, :use_clean_rails_memory_store_caching, :sidekiq_inline do
|
|
|
|
include KubernetesHelpers
|
|
|
|
include PrometheusHelpers
|
|
|
|
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
|
|
|
let_it_be(:clusterable) { create(:project) }
|
|
|
|
let_it_be(:cluster) { create(:cluster, :provided_by_gcp, :project, projects: [clusterable]) }
|
|
|
|
let_it_be(:cluster_path) { project_cluster_path(clusterable, cluster) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
clusterable.add_maintainer(current_user)
|
|
|
|
|
|
|
|
sign_in(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows cluster board section within the page' do
|
|
|
|
visit cluster_path
|
|
|
|
|
|
|
|
expect(page).to have_text('Health')
|
|
|
|
|
|
|
|
click_link 'Health'
|
|
|
|
|
|
|
|
expect(page).to have_css('.cluster-health-graphs')
|
|
|
|
end
|
|
|
|
|
2021-06-10 21:10:02 +00:00
|
|
|
context 'no prometheus available' do
|
|
|
|
it 'shows enable Prometheus message' do
|
2020-07-13 15:09:08 +00:00
|
|
|
visit cluster_path
|
|
|
|
|
|
|
|
click_link 'Health'
|
|
|
|
|
2021-04-12 06:09:17 +00:00
|
|
|
expect(page).to have_text('you must first enable Prometheus in the Integrations tab')
|
2020-07-13 15:09:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-03 12:10:18 +00:00
|
|
|
context 'when there is cluster with enabled prometheus' do
|
2020-07-13 15:09:08 +00:00
|
|
|
before do
|
2021-06-03 12:10:18 +00:00
|
|
|
create(:clusters_integrations_prometheus, enabled: true, cluster: cluster)
|
2020-07-13 15:09:08 +00:00
|
|
|
stub_kubeclient_discover(cluster.platform.api_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'waiting for data' do
|
|
|
|
before do
|
|
|
|
stub_empty_response
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows container and waiting for data message' do
|
|
|
|
visit cluster_path
|
|
|
|
|
|
|
|
click_link 'Health'
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page).to have_css('.prometheus-graphs')
|
|
|
|
expect(page).to have_text('Waiting for performance data')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'connected, prometheus returns data' do
|
|
|
|
before do
|
|
|
|
stub_connected
|
|
|
|
|
|
|
|
visit cluster_path
|
|
|
|
|
|
|
|
click_link 'Health'
|
|
|
|
|
|
|
|
wait_for_requests
|
2021-08-12 12:11:05 +00:00
|
|
|
end
|
2020-07-13 15:09:08 +00:00
|
|
|
|
2021-08-12 12:11:05 +00:00
|
|
|
it 'renders charts' do
|
2020-07-13 15:09:08 +00:00
|
|
|
expect(page).to have_css('.prometheus-graphs')
|
|
|
|
expect(page).to have_css('.prometheus-graph')
|
|
|
|
expect(page).to have_css('.prometheus-graph-title')
|
|
|
|
expect(page).to have_css('[_echarts_instance_]')
|
2021-08-12 12:11:05 +00:00
|
|
|
expect(page).to have_css('.prometheus-graph', count: 2)
|
2020-07-13 15:09:08 +00:00
|
|
|
expect(page).to have_content('Avg')
|
|
|
|
end
|
2021-08-12 12:11:05 +00:00
|
|
|
|
2021-08-26 15:10:41 +00:00
|
|
|
it 'focuses the single panel on toggle' do
|
|
|
|
click_button('More actions', match: :first)
|
2021-08-12 12:11:05 +00:00
|
|
|
click_button('Expand panel')
|
|
|
|
|
|
|
|
expect(page).to have_css('.prometheus-graph', count: 1)
|
|
|
|
|
|
|
|
click_button('Collapse panel')
|
|
|
|
|
|
|
|
expect(page).to have_css('.prometheus-graph', count: 2)
|
|
|
|
end
|
2020-07-13 15:09:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_empty_response
|
|
|
|
stub_prometheus_request(/prometheus-prometheus-server/, status: 204, body: {})
|
2021-06-10 21:10:02 +00:00
|
|
|
stub_prometheus_request(%r{prometheus/api/v1}, status: 204, body: {})
|
2020-07-13 15:09:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_connected
|
|
|
|
stub_prometheus_request(/prometheus-prometheus-server/, body: prometheus_values_body)
|
2021-06-10 21:10:02 +00:00
|
|
|
stub_prometheus_request(%r{prometheus/api/v1}, body: prometheus_values_body)
|
2020-07-13 15:09:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|