diff options
author | Stan Hu <stanhu@gmail.com> | 2018-05-15 21:25:32 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-05-15 21:25:32 +0300 |
commit | 728441a4080332d567a881d9ad833c211d6ab643 (patch) | |
tree | 2722b9e1755e6a9fcafe4bc578826fa7c46b7075 | |
parent | bdf279b151c2a530155425f352daac0576f1ec60 (diff) | |
parent | c003337729e6a68df10878f77b11c7a24321df9c (diff) |
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
-rw-r--r-- | changelogs/unreleased/fix-metrics-content-types.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/metrics/web_transaction.rb | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/web_transaction_spec.rb | 6 |
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' }) |