Commit 19812e3e authored by Pawel Chojnacki's avatar Pawel Chojnacki

Make queries not die when underlying data cannot be found

parent 15b7b9ec
......@@ -5,7 +5,7 @@ module Gitlab
include QueryAdditionalMetrics
def query(deployment_id)
deployment = Deployment.find_by(id: deployment_id)
Deployment.find_by(id: deployment_id).try do |deployment|
query_context = {
environment_slug: deployment.environment.slug,
environment_filter: %{container_name!="POD",environment="#{deployment.environment.slug}"},
......@@ -18,4 +18,5 @@ module Gitlab
end
end
end
end
end
......@@ -5,7 +5,7 @@ module Gitlab
include QueryAdditionalMetrics
def query(environment_id)
environment = Environment.find_by(id: environment_id)
Environment.find_by(id: environment_id).try do |environment|
query_context = {
environment_slug: environment.slug,
environment_filter: %{container_name!="POD",environment="#{environment.slug}"},
......@@ -18,4 +18,5 @@ module Gitlab
end
end
end
end
end
......@@ -3,7 +3,7 @@ module Gitlab
module Queries
class DeploymentQuery < BaseQuery
def query(deployment_id)
deployment = Deployment.find_by(id: deployment_id)
Deployment.find_by(id: deployment_id).try do |deployment|
environment_slug = deployment.environment.slug
memory_query = raw_memory_usage_query(environment_slug)
......@@ -27,4 +27,5 @@ module Gitlab
end
end
end
end
end
......@@ -3,7 +3,7 @@ module Gitlab
module Queries
class EnvironmentQuery < BaseQuery
def query(environment_id)
environment = Environment.find_by(id: environment_id)
Environment.find_by(id: environment_id).try do |environment|
environment_slug = environment.slug
timeframe_start = 8.hours.ago.to_f
timeframe_end = Time.now.to_f
......@@ -21,4 +21,5 @@ module Gitlab
end
end
end
end
end
......@@ -141,7 +141,7 @@ describe Projects::DeploymentsController do
end
it 'returns a empty response 204 response' do
get :additional_metrics, deployment_params(id: deployment.id)
get :additional_metrics, deployment_params(id: deployment.id, format: :json)
expect(response).to have_http_status(204)
expect(response.body).to eq('')
end
......@@ -161,7 +161,7 @@ describe Projects::DeploymentsController do
end
it 'returns a metrics JSON document' do
get :additional_metrics, deployment_params(id: deployment.id)
get :additional_metrics, deployment_params(id: deployment.id, format: :json)
expect(response).to be_ok
expect(json_response['success']).to be(true)
......
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