Commit 892ff3a3 authored by Rémy Coutable's avatar Rémy Coutable

Check for env[Grape::Env::GRAPE_ROUTING_ARGS] instead of endpoint.route

`endpoint.route` is calling `env[Grape::Env::GRAPE_ROUTING_ARGS][:route_info]`
but `env[Grape::Env::GRAPE_ROUTING_ARGS]` is `nil` in the case of a 405 response
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 707570ac
---
title: Check for env[Grape::Env::GRAPE_ROUTING_ARGS] instead of endpoint.route
merge_request: 8544
author:
...@@ -71,10 +71,17 @@ module Gitlab ...@@ -71,10 +71,17 @@ module Gitlab
def tag_endpoint(trans, env) def tag_endpoint(trans, env)
endpoint = env[ENDPOINT_KEY] endpoint = env[ENDPOINT_KEY]
# endpoint.route is nil in the case of a 405 response begin
if endpoint.route route = endpoint.route
path = endpoint_paths_cache[endpoint.route.request_method][endpoint.route.path] rescue
trans.action = "Grape##{endpoint.route.request_method} #{path}" # endpoint.route is calling env[Grape::Env::GRAPE_ROUTING_ARGS][:route_info]
# but env[Grape::Env::GRAPE_ROUTING_ARGS] is nil in the case of a 405 response
# so we're rescuing exceptions and bailing out
end
if route
path = endpoint_paths_cache[route.request_method][route.path]
trans.action = "Grape##{route.request_method} #{path}"
end end
end end
......
...@@ -126,5 +126,16 @@ describe Gitlab::Metrics::RackMiddleware do ...@@ -126,5 +126,16 @@ describe Gitlab::Metrics::RackMiddleware do
expect(transaction.action).to eq('Grape#GET /projects/:id/archive') expect(transaction.action).to eq('Grape#GET /projects/:id/archive')
end end
it 'does not tag a transaction if route infos are missing' do
endpoint = double(:endpoint)
allow(endpoint).to receive(:route).and_raise
env['api.endpoint'] = endpoint
middleware.tag_endpoint(transaction, env)
expect(transaction.action).to be_nil
end
end end
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