summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-05-15 17:37:19 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2018-05-15 17:38:39 +0200
commitc003337729e6a68df10878f77b11c7a24321df9c (patch)
tree1e17667be4468aa060e0b701b957657578002fa6
parentf4ef6b474c44eb8e7034034dd95152818ae33b4a (diff)
downloadgitlab-ce-c003337729e6a68df10878f77b11c7a24321df9c.tar.gz
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
-rw-r--r--changelogs/unreleased/fix-metrics-content-types.yml5
-rw-r--r--lib/gitlab/metrics/web_transaction.rb14
-rw-r--r--spec/lib/gitlab/metrics/web_transaction_spec.rb6
3 files changed, 9 insertions, 16 deletions
diff --git a/changelogs/unreleased/fix-metrics-content-types.yml b/changelogs/unreleased/fix-metrics-content-types.yml
new file mode 100644
index 00000000000..a418dccffc3
--- /dev/null
+++ b/changelogs/unreleased/fix-metrics-content-types.yml
@@ -0,0 +1,5 @@
+---
+title: Fix setting Gitlab metrics content types
+merge_request:
+author:
+type: fixed
diff --git a/lib/gitlab/metrics/web_transaction.rb b/lib/gitlab/metrics/web_transaction.rb
index 89ff02a96d6..7cf33ca9e8a 100644
--- a/lib/gitlab/metrics/web_transaction.rb
+++ b/lib/gitlab/metrics/web_transaction.rb
@@ -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}"
diff --git a/spec/lib/gitlab/metrics/web_transaction_spec.rb b/spec/lib/gitlab/metrics/web_transaction_spec.rb
index 1d162f53a13..c07b33a039a 100644
--- a/spec/lib/gitlab/metrics/web_transaction_spec.rb
+++ b/spec/lib/gitlab/metrics/web_transaction_spec.rb
@@ -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' })