diff options
Diffstat (limited to 'spec/lib/gitlab/metrics/web_transaction_spec.rb')
-rw-r--r-- | spec/lib/gitlab/metrics/web_transaction_spec.rb | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/spec/lib/gitlab/metrics/web_transaction_spec.rb b/spec/lib/gitlab/metrics/web_transaction_spec.rb index 47f1bd3bd10..12e98089066 100644 --- a/spec/lib/gitlab/metrics/web_transaction_spec.rb +++ b/spec/lib/gitlab/metrics/web_transaction_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Metrics::WebTransaction do +RSpec.describe Gitlab::Metrics::WebTransaction do let(:env) { {} } let(:transaction) { described_class.new(env) } let(:prometheus_metric) { double("prometheus metric") } @@ -70,6 +70,9 @@ describe Gitlab::Metrics::WebTransaction do end describe '#labels' do + let(:request) { double(:request, format: double(:format, ref: :html)) } + let(:controller_class) { double(:controller_class, name: 'TestController') } + context 'when request goes to Grape endpoint' do before do route = double(:route, request_method: 'GET', path: '/:version/projects/:id/archive(.:format)') @@ -77,8 +80,13 @@ describe Gitlab::Metrics::WebTransaction do env['api.endpoint'] = endpoint end + it 'provides labels with the method and path of the route in the grape endpoint' do - expect(transaction.labels).to eq({ controller: 'Grape', action: 'GET /projects/:id/archive' }) + expect(transaction.labels).to eq({ controller: 'Grape', action: 'GET /projects/:id/archive', feature_category: '' }) + end + + it 'contains only the labels defined for transactions' do + expect(transaction.labels.keys).to contain_exactly(*described_class.superclass::BASE_LABELS.keys) end it 'does not provide labels if route infos are missing' do @@ -92,24 +100,25 @@ describe Gitlab::Metrics::WebTransaction do end context 'when request goes to ActionController' do - let(:request) { double(:request, format: double(:format, ref: :html)) } - before do - klass = double(:klass, name: 'TestController') - controller = double(:controller, class: klass, action_name: 'show', request: request) + controller = double(:controller, class: controller_class, action_name: 'show', request: request) env['action_controller.instance'] = controller end 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 + + it 'contains only the labels defined for transactions' do + expect(transaction.labels.keys).to contain_exactly(*described_class.superclass::BASE_LABELS.keys) end context 'when the request content type is not :html' do let(:request) { double(:request, format: double(:format, ref: :json)) } 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 @@ -117,7 +126,14 @@ describe Gitlab::Metrics::WebTransaction do let(:request) { double(:request, format: double(:format, ref: 'http://example.com')) } 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 |