diff options
Diffstat (limited to 'spec/lib/gitlab/metrics/web_transaction_spec.rb')
-rw-r--r-- | spec/lib/gitlab/metrics/web_transaction_spec.rb | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/spec/lib/gitlab/metrics/web_transaction_spec.rb b/spec/lib/gitlab/metrics/web_transaction_spec.rb index dc59fa804c4..139091eb456 100644 --- a/spec/lib/gitlab/metrics/web_transaction_spec.rb +++ b/spec/lib/gitlab/metrics/web_transaction_spec.rb @@ -64,7 +64,7 @@ RSpec.describe Gitlab::Metrics::WebTransaction do describe '#labels' do context 'when request goes to Grape endpoint' do before do - route = double(:route, request_method: 'GET', path: '/:version/projects/:id/archive(.:format)') + route = double(:route, request_method: 'GET', path: '/:version/projects/:id/archive(.:format)', origin: '/:version/projects/:id/archive') endpoint = double(:endpoint, route: route, options: { for: API::Projects, path: [":id/archive"] }, namespace: "/projects") @@ -76,7 +76,12 @@ RSpec.describe Gitlab::Metrics::WebTransaction do 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', feature_category: 'projects' }) + expect(transaction.labels).to eq({ + controller: 'Grape', + action: 'GET /projects/:id/archive', + feature_category: 'projects', + endpoint_id: 'GET /:version/projects/:id/archive' + }) end it 'contains only the labels defined for transactions' do @@ -99,11 +104,14 @@ RSpec.describe Gitlab::Metrics::WebTransaction do before do controller = double(:controller, class: controller_class, action_name: 'show', request: request) + allow(controller_class).to receive(:endpoint_id_for_action) + .with(controller.action_name) + .and_return("#{controller_class.name}##{controller.action_name}") 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', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT }) + expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT, endpoint_id: 'TestController#show' }) end it 'contains only the labels defined for transactions' do @@ -113,8 +121,14 @@ RSpec.describe Gitlab::Metrics::WebTransaction do context 'when the request content type is not :html' do let(:request) { double(:request, format: double(:format, ref: :json)) } + before do + allow(controller_class).to receive(:endpoint_id_for_action) + .with("show.json") + .and_return("#{controller_class.name}#show.json") + end + it 'appends the mime type to the transaction action' do - expect(transaction.labels).to eq({ controller: 'TestController', action: 'show.json', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT }) + expect(transaction.labels).to eq({ controller: 'TestController', action: 'show.json', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT, endpoint_id: 'TestController#show.json' }) end end @@ -122,7 +136,7 @@ RSpec.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', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT }) + expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT, endpoint_id: 'TestController#show' }) end end @@ -131,7 +145,7 @@ RSpec.describe Gitlab::Metrics::WebTransaction do # This is needed since we're not actually making a request, which would trigger the controller pushing to the context ::Gitlab::ApplicationContext.push(feature_category: 'source_code_management') - expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: "source_code_management" }) + expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: 'source_code_management', endpoint_id: 'TestController#show' }) end end end @@ -147,9 +161,12 @@ RSpec.describe Gitlab::Metrics::WebTransaction do let(:controller) { double(:controller, class: controller_class, action_name: 'show', request: request) } let(:transaction_obj) { described_class.new({ 'action_controller.instance' => controller }) } - let(:labels) { { controller: 'TestController', action: 'show', feature_category: 'projects' } } + let(:labels) { { controller: 'TestController', action: 'show', feature_category: 'projects', endpoint_id: 'TestController#show' } } before do + allow(controller_class).to receive(:endpoint_id_for_action) + .with(controller.action_name) + .and_return("#{controller_class.name}##{controller.action_name}") ::Gitlab::ApplicationContext.push(feature_category: 'projects') end end |