Fix setting Gitlab metrics content types
The method "content_type" on a controller does not always return the correct content type. On the other hand, the method "request_format" does _and_ immediately returns a Symbol (e.g. :json) instead of a mime-type name (e.g. application/json). With these changes metrics should again report their action names correctly. Fixes https://gitlab.com/gitlab-com/infrastructure/issues/3499
This commit is contained in:
parent
f4ef6b474c
commit
c003337729
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix setting Gitlab metrics content types
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -4,18 +4,6 @@ module Gitlab
|
|||
CONTROLLER_KEY = 'action_controller.instance'.freeze
|
||||
ENDPOINT_KEY = 'api.endpoint'.freeze
|
||||
|
||||
CONTENT_TYPES = {
|
||||
'text/html' => :html,
|
||||
'text/plain' => :txt,
|
||||
'application/json' => :json,
|
||||
'text/js' => :js,
|
||||
'application/atom+xml' => :atom,
|
||||
'image/png' => :png,
|
||||
'image/jpeg' => :jpeg,
|
||||
'image/gif' => :gif,
|
||||
'image/svg+xml' => :svg
|
||||
}.freeze
|
||||
|
||||
def initialize(env)
|
||||
super()
|
||||
@env = env
|
||||
|
@ -40,7 +28,7 @@ module Gitlab
|
|||
controller = @env[CONTROLLER_KEY]
|
||||
|
||||
action = "#{controller.action_name}"
|
||||
suffix = CONTENT_TYPES[controller.content_type]
|
||||
suffix = controller.request_format
|
||||
|
||||
if suffix && suffix != :html
|
||||
action += ".#{suffix}"
|
||||
|
|
|
@ -180,11 +180,11 @@ describe Gitlab::Metrics::WebTransaction do
|
|||
end
|
||||
|
||||
context 'when request goes to ActionController' do
|
||||
let(:content_type) { 'text/html' }
|
||||
let(:request_format) { :html }
|
||||
|
||||
before do
|
||||
klass = double(:klass, name: 'TestController')
|
||||
controller = double(:controller, class: klass, action_name: 'show', content_type: content_type)
|
||||
controller = double(:controller, class: klass, action_name: 'show', request_format: request_format)
|
||||
|
||||
env['action_controller.instance'] = controller
|
||||
end
|
||||
|
@ -195,7 +195,7 @@ describe Gitlab::Metrics::WebTransaction do
|
|||
end
|
||||
|
||||
context 'when the response content type is not :html' do
|
||||
let(:content_type) { 'application/json' }
|
||||
let(:request_format) { :json }
|
||||
|
||||
it 'appends the mime type to the transaction action' do
|
||||
expect(transaction.labels).to eq({ controller: 'TestController', action: 'show.json' })
|
||||
|
|
Loading…
Reference in New Issue