Commit bead65a9 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'pl-env-metrics-json' into 'master'

Load environment metrics only for JSON endpoint

See merge request gitlab-org/gitlab-ce!27743
parents ab9910f7 80fec5c3
...@@ -135,13 +135,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -135,13 +135,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
def metrics def metrics
respond_to do |format|
format.html
format.json do
# Currently, this acts as a hint to load the metrics details into the cache # Currently, this acts as a hint to load the metrics details into the cache
# if they aren't there already # if they aren't there already
@metrics = environment.metrics || {} @metrics = environment.metrics || {}
respond_to do |format|
format.html
format.json do
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