Commit 58313de4 authored by Tiago Botelho's avatar Tiago Botelho Committed by Rémy Coutable

Render 404 when prometheus adapter is disabled in Prometheus metrics controller

parent a2dbca4a
...@@ -25,7 +25,7 @@ module Projects ...@@ -25,7 +25,7 @@ module Projects
end end
def require_prometheus_metrics! def require_prometheus_metrics!
render_404 unless prometheus_adapter.can_query? render_404 unless prometheus_adapter&.can_query?
end end
end end
end end
......
---
title: Render 404 when prometheus adapter is disabled in Prometheus metrics controller
merge_request: 19110
author:
type: fixed
...@@ -12,6 +12,7 @@ describe Projects::Prometheus::MetricsController do ...@@ -12,6 +12,7 @@ describe Projects::Prometheus::MetricsController do
end end
describe 'GET #active_common' do describe 'GET #active_common' do
context 'when prometheus_adapter can query' do
before do before do
allow(controller).to receive(:prometheus_adapter).and_return(prometheus_adapter) allow(controller).to receive(:prometheus_adapter).and_return(prometheus_adapter)
end end
...@@ -54,6 +55,28 @@ describe Projects::Prometheus::MetricsController do ...@@ -54,6 +55,28 @@ describe Projects::Prometheus::MetricsController do
end end
end end
context 'when prometheus_adapter cannot query' do
it 'renders 404' do
prometheus_adapter = double('prometheus_adapter', can_query?: false)
allow(controller).to receive(:prometheus_adapter).and_return(prometheus_adapter)
allow(prometheus_adapter).to receive(:query).with(:matched_metrics).and_return({})
get :active_common, project_params(format: :json)
expect(response).to have_gitlab_http_status(404)
end
end
context 'when prometheus_adapter is disabled' do
it 'renders 404' do
get :active_common, project_params(format: :json)
expect(response).to have_gitlab_http_status(404)
end
end
end
describe '#prometheus_adapter' do describe '#prometheus_adapter' do
before do before do
allow(controller).to receive(:project).and_return(project) allow(controller).to receive(:project).and_return(project)
......
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