Commit 80fec5c3 authored by Peter Leitzen's avatar Peter Leitzen Committed by Douwe Maan

Load environment metrics only for JSON endpoint

When showing the HTML version of the environment metrics we don't need
to fetch their metrics because we don't use them anymore on the HTML
version.

We use additional_metrics.json endpoint now.
parent ab9910f7
...@@ -135,13 +135,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -135,13 +135,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
def metrics def metrics
# Currently, this acts as a hint to load the metrics details into the cache
# if they aren't there already
@metrics = environment.metrics || {}
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
# Currently, this acts as a hint to load the metrics details into the cache
# if they aren't there already
@metrics = environment.metrics || {}
render json: @metrics, status: @metrics.any? ? :ok : :no_content render json: @metrics, status: @metrics.any? ? :ok : :no_content
end end
end end
......
...@@ -342,11 +342,9 @@ describe Projects::EnvironmentsController do ...@@ -342,11 +342,9 @@ describe Projects::EnvironmentsController do
end end
context 'when environment has no metrics' do context 'when environment has no metrics' do
before do
expect(environment).to receive(:metrics).and_return(nil)
end
it 'returns a metrics page' do it 'returns a metrics page' do
expect(environment).not_to receive(:metrics)
get :metrics, params: environment_params get :metrics, params: environment_params
expect(response).to be_ok expect(response).to be_ok
...@@ -354,6 +352,8 @@ describe Projects::EnvironmentsController do ...@@ -354,6 +352,8 @@ describe Projects::EnvironmentsController do
context 'when requesting metrics as JSON' do context 'when requesting metrics as JSON' do
it 'returns a metrics JSON document' do it 'returns a metrics JSON document' do
expect(environment).to receive(:metrics).and_return(nil)
get :metrics, params: environment_params(format: :json) get :metrics, params: environment_params(format: :json)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(204)
......
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