Commit aed714e4 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Include feature_category label in metrics

This adds the feature_category as a label to the requests for rails
controllers.
parent afd08055
...@@ -32,6 +32,10 @@ module Gitlab ...@@ -32,6 +32,10 @@ module Gitlab
action = "#{controller.action_name}" action = "#{controller.action_name}"
# Try to get the feature category, but don't fail when the controller is
# not an ApplicationController.
feature_category = controller.class.try(:feature_category_for_action, action).to_s
# Devise exposes a method called "request_format" that does the below. # Devise exposes a method called "request_format" that does the below.
# However, this method is not available to all controllers (e.g. certain # However, this method is not available to all controllers (e.g. certain
# Doorkeeper controllers). As such we use the underlying code directly. # Doorkeeper controllers). As such we use the underlying code directly.
...@@ -45,7 +49,7 @@ module Gitlab ...@@ -45,7 +49,7 @@ module Gitlab
action = "#{action}.#{suffix}" action = "#{action}.#{suffix}"
end end
{ controller: controller.class.name, action: action } { controller: controller.class.name, action: action, feature_category: feature_category }
end end
def labels_from_endpoint def labels_from_endpoint
......
...@@ -93,23 +93,23 @@ RSpec.describe Gitlab::Metrics::WebTransaction do ...@@ -93,23 +93,23 @@ RSpec.describe Gitlab::Metrics::WebTransaction do
context 'when request goes to ActionController' do context 'when request goes to ActionController' do
let(:request) { double(:request, format: double(:format, ref: :html)) } let(:request) { double(:request, format: double(:format, ref: :html)) }
let(:controller_class) { double(:controller_class, name: 'TestController') }
before do before do
klass = double(:klass, name: 'TestController') controller = double(:controller, class: controller_class, action_name: 'show', request: request)
controller = double(:controller, class: klass, action_name: 'show', request: request)
env['action_controller.instance'] = controller env['action_controller.instance'] = controller
end end
it 'tags a transaction with the name and action of a controller' do it 'tags a transaction with the name and action of a controller' do
expect(transaction.labels).to eq({ controller: 'TestController', action: 'show' }) expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: '' })
end end
context 'when the request content type is not :html' do context 'when the request content type is not :html' do
let(:request) { double(:request, format: double(:format, ref: :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', feature_category: '' })
end end
end end
...@@ -117,7 +117,14 @@ RSpec.describe Gitlab::Metrics::WebTransaction do ...@@ -117,7 +117,14 @@ RSpec.describe Gitlab::Metrics::WebTransaction do
let(:request) { double(:request, format: double(:format, ref: 'http://example.com')) } let(:request) { double(:request, format: double(:format, ref: 'http://example.com')) }
it 'does not append the MIME type to the transaction action' do it 'does not append the MIME type to the transaction action' do
expect(transaction.labels).to eq({ controller: 'TestController', action: 'show' }) expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: '' })
end
end
context 'when the feature category is known' do
it 'includes it in the feature category label' do
expect(controller_class).to receive(:feature_category_for_action).with('show').and_return(:source_code_management)
expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: "source_code_management" })
end end
end end
end end
......
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