Commit dbd38caa authored by Sarah Yasonik's avatar Sarah Yasonik Committed by Ash McKenzie

Add feature test for grafana embeds

Creates a feature test for embedding grafana metrics charts
in GFM. Includes some additional helpers and fixtures.
parent 16dcfa3a
...@@ -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,6 +23,12 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek ...@@ -26,6 +23,12 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
restore_host restore_host
end end
context 'internal metrics embeds' do
before do
import_common_metrics
stub_any_prometheus_request_with_response
end
it 'shows embedded metrics' do it 'shows embedded metrics' do
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
...@@ -45,7 +48,7 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek ...@@ -45,7 +48,7 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
} }
end end
it 'shows embedded metrics for the specifiec chart' do it 'shows embedded metrics for the specific chart' 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')
...@@ -53,6 +56,27 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek ...@@ -53,6 +56,27 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
expect(page).to have_text(chart_params[:y_label]) expect(page).to have_text(chart_params[:y_label])
end end
end end
end
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) }
before do
stub_dashboard_request(grafana_base_url)
stub_datasource_request(grafana_base_url)
stub_all_grafana_proxy_requests(grafana_base_url)
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('Expired / Evicted')
expect(page).to have_text('expired - test-attribute-value')
end
end
def import_common_metrics def import_common_metrics
::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute ::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute
......
...@@ -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