Commit 33af33d7 authored by Yorick Peterse's avatar Yorick Peterse

Fix GPM content types for Doorkeeper

Certain controllers (e.g. Doorkeeper::TokensController) don't expose the
method "request_format". This commit changes
Gitlab::Metrics::WebTransaction so we don't rely on this method, instead
using the underlying code this method uses.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/46412
parent 75f94fc3
...@@ -28,7 +28,11 @@ module Gitlab ...@@ -28,7 +28,11 @@ module Gitlab
controller = @env[CONTROLLER_KEY] controller = @env[CONTROLLER_KEY]
action = "#{controller.action_name}" action = "#{controller.action_name}"
suffix = controller.request_format
# Devise exposes a method called "request_format" that does the below.
# However, this method is not available to all controllers (e.g. certain
# Doorkeeper controllers). As such we use the underlying code directly.
suffix = controller.request.format.try(:ref)
if suffix && suffix != :html if suffix && suffix != :html
action += ".#{suffix}" action += ".#{suffix}"
......
...@@ -180,11 +180,11 @@ describe Gitlab::Metrics::WebTransaction do ...@@ -180,11 +180,11 @@ describe Gitlab::Metrics::WebTransaction do
end end
context 'when request goes to ActionController' do context 'when request goes to ActionController' do
let(:request_format) { :html } let(:request) { double(:request, format: double(:format, ref: :html)) }
before do before do
klass = double(:klass, name: 'TestController') klass = double(:klass, name: 'TestController')
controller = double(:controller, class: klass, action_name: 'show', request_format: request_format) controller = double(:controller, class: klass, action_name: 'show', request: request)
env['action_controller.instance'] = controller env['action_controller.instance'] = controller
end end
...@@ -195,7 +195,7 @@ describe Gitlab::Metrics::WebTransaction do ...@@ -195,7 +195,7 @@ describe Gitlab::Metrics::WebTransaction do
end end
context 'when the response content type is not :html' do context 'when the response content type is not :html' do
let(:request_format) { :json } let(:request) { double(:request, format: double(:format, ref: :json)) }
it 'appends the mime type to the transaction action' do it 'appends the mime type to the transaction action' do
expect(transaction.labels).to eq({ controller: 'TestController', action: 'show.json' }) expect(transaction.labels).to eq({ controller: 'TestController', action: 'show.json' })
......
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