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'
describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidekiq_might_not_need_inline do
include PrometheusHelpers
include GrafanaApiHelpers
let(:user) { create(:user) }
let(:project) { create(:prometheus_project) }
......@@ -14,11 +15,7 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
before do
configure_host
import_common_metrics
stub_any_prometheus_request_with_response
project.add_developer(user)
sign_in(user)
end
......@@ -26,31 +23,58 @@ describe 'Metrics rendering', :js, :use_clean_rails_memory_store_caching, :sidek
restore_host
end
it 'shows embedded metrics' do
visit project_issue_path(project, issue)
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
let(:metrics_url) { metrics_project_environment_url(project, environment, **chart_params) }
expect(page).to have_css('div.prometheus-graph')
expect(page).to have_text('Memory Usage (Total)')
expect(page).to have_text('Core Usage (Total)')
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
end
context 'when dashboard params are in included the url' do
let(:metrics_url) { metrics_project_environment_url(project, environment, **chart_params) }
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) }
let(:chart_params) do
{
group: 'System metrics (Kubernetes)',
title: 'Memory Usage (Pod average)',
y_label: 'Memory Used per Pod (MB)'
}
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 for the specifiec chart' do
it 'shows embedded metrics' 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])
expect(page).to have_text('Expired / Evicted')
expect(page).to have_text('expired - test-attribute-value')
end
end
......
......@@ -424,7 +424,7 @@
"format": "time_series",
"interval": "1m",
"intervalFactor": 2,
"legendFormat": "expired",
"legendFormat": "expired - {{ test_attribute }}",
"metric": "",
"refId": "A",
"step": 240,
......
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"test_attribute": "test-attribute-value"
},
"values": [
[1570768177, "54"],
[1570768237, "54"],
[1570768297, "54"],
[1570768357, "54"],
[1570768417, "54"],
[1570768477, "54"],
[1570768537, "54"],
[1570768597, "54"],
[1570768657, "54"],
[1570768717, "54"],
[1570768777, "54"],
[1570768837, "54"],
[1570768897, "54"],
[1570768957, "54"],
[1570769017, "54"],
[1570769077, "54"],
[1570769377, "54"],
[1570769437, "54"],
[1570769497, "54"],
[1570769557, "54"],
[1570769617, "54"],
[1570769677, "54"],
[1570769737, "54"],
[1570769797, "54"],
[1570769857, "54"],
[1570769917, "54"],
[1570769977, "54"],
[1570770037, "54"],
[1570770097, "54"],
[1570770157, "54"],
[1570770217, "54"],
[1570770277, "54"],
[1570770337, "54"],
[1570770397, "54"],
[1570770457, "54"],
[1570770517, "54"],
[1570770577, "54"],
[1570770637, "54"],
[1570770697, "54"],
[1570770757, "54"],
[1570770817, "54"],
[1570770877, "54"],
[1570770937, "54"],
[1570770997, "54"],
[1570771057, "54"],
[1570771117, "54"],
[1570771177, "54"],
[1570771237, "54"],
[1570771297, "54"],
[1570771357, "54"],
[1570771417, "54"],
[1570771477, "54"],
[1570771537, "54"],
[1570771597, "54"],
[1570771657, "54"],
[1570771717, "54"],
[1570771777, "54"],
[1570771837, "54"],
[1570771897, "54"],
[1570771957, "54"],
[1570772017, "54"],
[1570772077, "54"],
[1570772137, "54"],
[1570772197, "54"],
[1570772257, "54"],
[1570772317, "54"],
[1570772377, "54"],
[1570772437, "54"],
[1570772497, "54"],
[1570772557, "54"],
[1570772617, "54"],
[1570772677, "54"],
[1570772737, "54"],
[1570772797, "54"],
[1570772857, "54"],
[1570772917, "54"],
[1570772977, "54"],
[1570773037, "54"],
[1570773097, "54"],
[1570773157, "54"],
[1570773217, "54"],
[1570773277, "54"],
[1570773337, "54"],
[1570773397, "54"],
[1570773457, "54"],
[1570773517, "54"],
[1570773577, "54"],
[1570773637, "54"],
[1570773697, "54"],
[1570773757, "54"],
[1570773817, "54"],
[1570773877, "54"],
[1570773937, "54"],
[1570773997, "54"],
[1570774057, "54"],
[1570774117, "54"],
[1570774177, "54"],
[1570774237, "54"],
[1570774297, "54"],
[1570774357, "54"],
[1570774417, "54"],
[1570774477, "54"],
[1570774537, "54"],
[1570774597, "54"],
[1570774657, "54"],
[1570774717, "54"],
[1570774777, "54"],
[1570774837, "54"],
[1570774897, "54"],
[1570774957, "54"],
[1570775017, "54"],
[1570775077, "54"],
[1570775137, "54"],
[1570776937, "54"],
[1570776997, "54"],
[1570777057, "54"],
[1570777117, "54"],
[1570777177, "54"],
[1570777237, "54"],
[1570777297, "54"],
[1570777357, "54"],
[1570777417, "54"],
[1570777477, "54"],
[1570777537, "54"],
[1570777597, "54"],
[1570777657, "54"],
[1570777717, "54"],
[1570778017, "54"],
[1570778077, "54"],
[1570778137, "54"],
[1570778197, "54"],
[1570778257, "54"],
[1570778317, "54"],
[1570778377, "54"],
[1570778437, "54"],
[1570778497, "54"],
[1570778557, "54"],
[1570778617, "54"],
[1570778677, "54"],
[1570778737, "54"],
[1570778797, "54"],
[1570778857, "54"],
[1570778917, "54"],
[1570778977, "54"],
[1570779037, "54"],
[1570779097, "54"],
[1570779157, "54"],
[1570779217, "54"],
[1570779277, "54"],
[1570779337, "54"],
[1570779397, "54"],
[1570779457, "54"],
[1570779517, "54"],
[1570779577, "54"],
[1570779637, "54"],
[1570779697, "54"],
[1570779757, "54"],
[1570779817, "54"],
[1570779877, "54"],
[1570779937, "54"],
[1570779997, "54"],
[1570780057, "54"],
[1570780117, "54"],
[1570780177, "54"],
[1570780237, "54"],
[1570780297, "54"],
[1570780357, "54"],
[1570780417, "54"],
[1570780477, "54"],
[1570780537, "54"],
[1570780597, "54"],
[1570780657, "54"],
[1570780717, "54"],
[1570780777, "54"],
[1570780837, "54"],
[1570780897, "54"],
[1570780957, "54"],
[1570781017, "54"],
[1570781077, "54"],
[1570781137, "54"],
[1570781197, "54"],
[1570781257, "54"],
[1570781317, "54"],
[1570781377, "54"],
[1570781437, "54"],
[1570781497, "54"],
[1570781557, "54"],
[1570781617, "54"],
[1570781677, "54"],
[1570781737, "54"],
[1570781797, "54"],
[1570781857, "54"],
[1570781917, "54"],
[1570781977, "54"],
[1570782037, "54"],
[1570782097, "54"],
[1570782157, "54"],
[1570782217, "54"],
[1570782277, "54"],
[1570782337, "54"],
[1570782397, "54"],
[1570782457, "54"],
[1570782517, "54"],
[1570782577, "54"],
[1570782637, "54"],
[1570782697, "54"],
[1570782757, "54"],
[1570782817, "54"],
[1570782877, "54"],
[1570782937, "54"],
[1570782997, "54"],
[1570783057, "54"],
[1570783117, "54"],
[1570783177, "54"],
[1570783237, "54"],
[1570783297, "54"],
[1570783357, "54"],
[1570783417, "54"],
[1570783477, "54"],
[1570783537, "54"],
[1570783597, "54"],
[1570783657, "54"],
[1570783717, "54"],
[1570783777, "54"],
[1570783837, "54"],
[1570783897, "54"],
[1570783957, "54"],
[1570784017, "54"],
[1570784077, "54"],
[1570784137, "54"],
[1570784197, "54"],
[1570784257, "54"],
[1570784317, "54"],
[1570784377, "54"],
[1570784437, "54"],
[1570784497, "54"],
[1570784557, "54"],
[1570784617, "54"],
[1570784677, "54"],
[1570784737, "54"],
[1570784797, "54"],
[1570784857, "54"],
[1570784917, "54"],
[1570784977, "54"],
[1570785037, "54"],
[1570785097, "54"],
[1570785157, "54"],
[1570785217, "54"],
[1570785277, "54"],
[1570785337, "54"],
[1570785397, "54"],
[1570785457, "54"],
[1570785517, "54"],
[1570785577, "54"],
[1570785637, "54"],
[1570785697, "54"],
[1570785757, "54"],
[1570785817, "54"],
[1570785877, "54"],
[1570785937, "54"],
[1570785997, "54"],
[1570786057, "54"],
[1570786117, "54"],
[1570786177, "54"],
[1570786237, "54"],
[1570786297, "54"],
[1570786357, "54"],
[1570786417, "54"],
[1570786477, "54"],
[1570786537, "54"],
[1570786597, "54"],
[1570786657, "54"],
[1570786717, "54"],
[1570786777, "54"],
[1570786837, "54"],
[1570786897, "54"],
[1570786957, "53"],
[1570787017, "54"],
[1570787077, "54"],
[1570787137, "54"],
[1570787197, "54"],
[1570787257, "54"],
[1570787317, "54"],
[1570787377, "54"],
[1570787437, "54"],
[1570787497, "54"],
[1570787557, "54"],
[1570787617, "54"],
[1570787677, "54"],
[1570787737, "54"],
[1570787797, "54"],
[1570787857, "54"],
[1570787917, "54"],
[1570787977, "54"],
[1570788037, "54"],
[1570788097, "54"],
[1570788157, "54"],
[1570788217, "54"],
[1570788277, "54"],
[1570788337, "54"],
[1570788397, "54"],
[1570788457, "54"],
[1570788517, "54"],
[1570788577, "54"],
[1570788637, "54"],
[1570788697, "54"],
[1570788757, "54"],
[1570788817, "54"],
[1570788877, "54"],
[1570788937, "54"],
[1570788997, "54"],
[1570789057, "54"],
[1570789117, "54"],
[1570789177, "54"],
[1570789237, "54"],
[1570789297, "54"],
[1570789357, "54"],
[1570789417, "54"],
[1570789477, "54"],
[1570789537, "54"],
[1570789597, "54"],
[1570789657, "54"],
[1570789717, "54"],
[1570789777, "54"],
[1570789837, "54"],
[1570789897, "54"],
[1570789957, "54"],
[1570790017, "54"],
[1570790077, "54"],
[1570790137, "54"],
[1570790197, "54"],
[1570790257, "54"],
[1570790317, "54"],
[1570790377, "54"],
[1570790437, "54"],
[1570790497, "54"],
[1570790557, "54"],
[1570790617, "54"],
[1570790677, "54"],
[1570790737, "54"],
[1570790797, "54"],
[1570790857, "54"],
[1570790917, "54"],
[1570790977, "54"],
[1570791037, "54"],
[1570791097, "54"],
[1570791157, "54"],
[1570791217, "54"],
[1570791277, "54"],
[1570791337, "54"],
[1570791397, "54"],
[1570791457, "54"],
[1570791517, "54"],
[1570791577, "54"],
[1570791637, "54"],
[1570791697, "54"],
[1570791757, "54"],
[1570791817, "54"],
[1570791877, "54"],
[1570791937, "54"],
[1570791997, "54"],
[1570792057, "54"],
[1570792117, "54"],
[1570792177, "54"],
[1570792237, "54"],
[1570792297, "54"],
[1570792357, "54"],
[1570792417, "54"],
[1570792477, "54"],
[1570792537, "54"],
[1570792597, "54"],
[1570792657, "54"],
[1570792717, "54"],
[1570792777, "54"],
[1570792837, "54"],
[1570792897, "54"],
[1570792957, "54"],
[1570793017, "54"],
[1570793077, "54"],
[1570793137, "54"],
[1570793197, "54"],
[1570793257, "54"],
[1570793317, "54"],
[1570793377, "54"],
[1570793437, "54"],
[1570793497, "54"],
[1570793557, "54"],
[1570793617, "54"],
[1570793677, "54"],
[1570793737, "54"],
[1570793797, "54"],
[1570793857, "54"],
[1570793917, "54"],
[1570793977, "54"],
[1570794037, "54"],
[1570794097, "54"],
[1570794157, "54"],
[1570794217, "54"],
[1570794277, "54"],
[1570794337, "54"],
[1570794397, "54"],
[1570794457, "54"],
[1570794517, "54"],
[1570794577, "54"],
[1570794637, "54"],
[1570794697, "54"],
[1570794757, "54"],
[1570794817, "54"],
[1570794877, "54"],
[1570794937, "54"],
[1570794997, "54"],
[1570795057, "54"],
[1570795117, "54"],
[1570795177, "54"],
[1570795237, "54"],
[1570795297, "54"],
[1570795357, "54"],
[1570795417, "54"],
[1570795477, "54"],
[1570795537, "54"],
[1570795597, "54"],
[1570795657, "54"],
[1570795717, "54"],
[1570795777, "54"],
[1570795837, "54"],
[1570795897, "54"],
[1570795957, "54"],
[1570796017, "54"],
[1570796077, "54"],
[1570796137, "54"],
[1570796197, "54"],
[1570796257, "54"],
[1570796317, "54"],
[1570796377, "54"],
[1570796437, "55"],
[1570796497, "54"],
[1570796557, "54"],
[1570796617, "54"],
[1570796677, "54"],
[1570796737, "54"],
[1570796797, "54"],
[1570796857, "54"],
[1570796917, "54"],
[1570796977, "54"]
]
}
]
}
}
......@@ -29,4 +29,13 @@ module GrafanaApiHelpers
headers: { 'Content-Type' => 'application/json' }
)
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
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