2019-07-25 21:41:54 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-02-24 19:09:12 -05:00
|
|
|
describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidekiq_inline do
|
2019-07-25 21:41:54 -04:00
|
|
|
include PrometheusHelpers
|
2019-11-11 19:06:21 -05:00
|
|
|
include GrafanaApiHelpers
|
2020-02-24 19:09:12 -05:00
|
|
|
include MetricsDashboardUrlHelpers
|
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:prometheus_project) }
|
|
|
|
let_it_be(:environment) { create(:environment, project: project) }
|
2019-07-25 21:41:54 -04:00
|
|
|
|
|
|
|
let(:issue) { create(:issue, project: project, description: description) }
|
|
|
|
let(:description) { "See [metrics dashboard](#{metrics_url}) for info." }
|
2020-02-24 19:09:12 -05:00
|
|
|
let(:metrics_url) { urls.metrics_project_environment_url(project, environment) }
|
2019-07-25 21:41:54 -04:00
|
|
|
|
|
|
|
before do
|
2020-02-24 19:09:12 -05:00
|
|
|
clear_host_from_memoized_variables
|
|
|
|
|
|
|
|
allow(::Gitlab.config.gitlab)
|
|
|
|
.to receive(:url)
|
|
|
|
.and_return(urls.root_url.chomp('/'))
|
|
|
|
|
2019-07-25 21:41:54 -04:00
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2020-02-24 19:09:12 -05:00
|
|
|
clear_host_from_memoized_variables
|
2019-07-25 21:41:54 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 19:06:21 -05:00
|
|
|
context 'internal metrics embeds' do
|
|
|
|
before do
|
|
|
|
import_common_metrics
|
|
|
|
stub_any_prometheus_request_with_response
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows embedded metrics' do
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
expect(page).to have_css('div.prometheus-graph')
|
|
|
|
expect(page).to have_text('Memory Usage (Total)')
|
|
|
|
expect(page).to have_text('Core Usage (Total)')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when dashboard params are in included the url' do
|
2020-02-24 19:09:12 -05:00
|
|
|
let(:metrics_url) { urls.metrics_project_environment_url(project, environment, **chart_params) }
|
2019-08-15 17:38:29 -04:00
|
|
|
|
2019-11-11 19:06:21 -05:00
|
|
|
let(:chart_params) do
|
|
|
|
{
|
|
|
|
group: 'System metrics (Kubernetes)',
|
|
|
|
title: 'Memory Usage (Pod average)',
|
|
|
|
y_label: 'Memory Used per Pod (MB)'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows embedded metrics for the specific chart' do
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
expect(page).to have_css('div.prometheus-graph')
|
|
|
|
expect(page).to have_text(chart_params[:title])
|
|
|
|
expect(page).to have_text(chart_params[:y_label])
|
|
|
|
end
|
|
|
|
end
|
2019-08-15 17:38:29 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 19:06:21 -05:00
|
|
|
context 'grafana metrics embeds' do
|
|
|
|
let(:grafana_integration) { create(:grafana_integration, project: project) }
|
|
|
|
let(:grafana_base_url) { grafana_integration.grafana_url }
|
|
|
|
let(:metrics_url) { valid_grafana_dashboard_link(grafana_base_url) }
|
2019-08-15 17:38:29 -04:00
|
|
|
|
2019-11-11 19:06:21 -05:00
|
|
|
before do
|
|
|
|
stub_dashboard_request(grafana_base_url)
|
|
|
|
stub_datasource_request(grafana_base_url)
|
|
|
|
stub_all_grafana_proxy_requests(grafana_base_url)
|
2019-08-15 17:38:29 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 19:06:21 -05:00
|
|
|
it 'shows embedded metrics' do
|
2019-07-25 21:41:54 -04:00
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
expect(page).to have_css('div.prometheus-graph')
|
2019-11-11 19:06:21 -05:00
|
|
|
expect(page).to have_text('Expired / Evicted')
|
|
|
|
expect(page).to have_text('expired - test-attribute-value')
|
2019-07-25 21:41:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def import_common_metrics
|
|
|
|
::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute
|
|
|
|
end
|
|
|
|
end
|