Commit 7c8d275a authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'sy-grafana-feature-test' into 'master'

Add feature test for grafana embeds

See merge request gitlab-org/gitlab!18536
parents 16dcfa3a dbd38caa
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidekiq_might_not_need_inline do describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidekiq_might_not_need_inline do
include PrometheusHelpers include PrometheusHelpers
include GrafanaApiHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:prometheus_project) } let(:project) { create(:prometheus_project) }
...@@ -14,11 +15,7 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek ...@@ -14,11 +15,7 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
before do before do
configure_host configure_host
import_common_metrics
stub_any_prometheus_request_with_response
project.add_developer(user) project.add_developer(user)
sign_in(user) sign_in(user)
end end
...@@ -26,31 +23,58 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek ...@@ -26,31 +23,58 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
restore_host restore_host
end end
it 'shows embedded metrics' do context 'internal metrics embeds' do
visit project_issue_path(project, issue) 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
let(:metrics_url) { metrics_project_environment_url(project, environment, **chart_params) }
expect(page).to have_css('div.prometheus-graph') let(:chart_params) do
expect(page).to have_text('Memory Usage (Total)') {
expect(page).to have_text('Core Usage (Total)') 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
end end
context 'when dashboard params are in included the url' do context 'grafana metrics embeds' do
let(:metrics_url) { metrics_project_environment_url(project, environment, **chart_params) } 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) }
let(:chart_params) do before do
{ stub_dashboard_request(grafana_base_url)
group: 'System metrics (Kubernetes)', stub_datasource_request(grafana_base_url)
title: 'Memory Usage (Pod average)', stub_all_grafana_proxy_requests(grafana_base_url)
y_label: 'Memory Used per Pod (MB)'
}
end end
it 'shows embedded metrics for the specifiec chart' do it 'shows embedded metrics' do
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
expect(page).to have_css('div.prometheus-graph') expect(page).to have_css('div.prometheus-graph')
expect(page).to have_text(chart_params[:title]) expect(page).to have_text('Expired / Evicted')
expect(page).to have_text(chart_params[:y_label]) expect(page).to have_text('expired - test-attribute-value')
end end
end end
......
...@@ -424,7 +424,7 @@ ...@@ -424,7 +424,7 @@
"format": "time_series", "format": "time_series",
"interval": "1m", "interval": "1m",
"intervalFactor": 2, "intervalFactor": 2,
"legendFormat": "expired", "legendFormat": "expired - {{ test_attribute }}",
"metric": "", "metric": "",
"refId": "A", "refId": "A",
"step": 240, "step": 240,
......
This diff is collapsed.
...@@ -29,4 +29,13 @@ module GrafanaApiHelpers ...@@ -29,4 +29,13 @@ module GrafanaApiHelpers
headers: { 'Content-Type' => 'application/json' } headers: { 'Content-Type' => 'application/json' }
) )
end end
def stub_all_grafana_proxy_requests(base_url)
stub_request(:any, /#{base_url}\/api\/datasources\/proxy/)
.to_return(
status: 200,
body: fixture_file('grafana/proxy_response.json'),
headers: { 'Content-Type' => 'application/json' }
)
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