Commit 728441a4 authored by Stan Hu's avatar Stan Hu

Merge branch 'fix-metrics-content-types' into 'master'

Fix setting Gitlab metrics content types

Closes gitlab-com/infrastructure#3499

See merge request gitlab-org/gitlab-ce!18975
parents bdf279b1 c0033377
---
title: Fix setting Gitlab metrics content types
merge_request:
author:
type: fixed
...@@ -4,18 +4,6 @@ module Gitlab ...@@ -4,18 +4,6 @@ module Gitlab
CONTROLLER_KEY = 'action_controller.instance'.freeze CONTROLLER_KEY = 'action_controller.instance'.freeze
ENDPOINT_KEY = 'api.endpoint'.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) def initialize(env)
super() super()
@env = env @env = env
...@@ -40,7 +28,7 @@ module Gitlab ...@@ -40,7 +28,7 @@ module Gitlab
controller = @env[CONTROLLER_KEY] controller = @env[CONTROLLER_KEY]
action = "#{controller.action_name}" action = "#{controller.action_name}"
suffix = CONTENT_TYPES[controller.content_type] suffix = controller.request_format
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(:content_type) { 'text/html' } let(:request_format) { :html }
before do before do
klass = double(:klass, name: 'TestController') 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 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(:content_type) { 'application/json' } let(:request_format) { :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