Commit 79d177c1 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add `feature_category`-label to grape metrics

This adds the `feature_category` label to the metrics for grape
endpoints. This is needed so the metrics have the same labels as the
ones for controllers.

This also adds a spec so we don't forget about it in the future.
parent d868d313
...@@ -65,7 +65,10 @@ module Gitlab ...@@ -65,7 +65,10 @@ module Gitlab
if route if route
path = endpoint_paths_cache[route.request_method][route.path] path = endpoint_paths_cache[route.request_method][route.path]
{ controller: 'Grape', action: "#{route.request_method} #{path}" }
# Feature categories will be added for grape endpoints in
# https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/462
{ controller: 'Grape', action: "#{route.request_method} #{path}", feature_category: "" }
end end
end end
......
...@@ -70,6 +70,9 @@ RSpec.describe Gitlab::Metrics::WebTransaction do ...@@ -70,6 +70,9 @@ RSpec.describe Gitlab::Metrics::WebTransaction do
end end
describe '#labels' do 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 context 'when request goes to Grape endpoint' do
before 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)')
...@@ -77,8 +80,9 @@ RSpec.describe Gitlab::Metrics::WebTransaction do ...@@ -77,8 +80,9 @@ RSpec.describe Gitlab::Metrics::WebTransaction do
env['api.endpoint'] = endpoint env['api.endpoint'] = endpoint
end end
it 'provides labels with the method and path of the route in the grape endpoint' do 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 end
it 'does not provide labels if route infos are missing' do it 'does not provide labels if route infos are missing' do
...@@ -92,9 +96,6 @@ RSpec.describe Gitlab::Metrics::WebTransaction do ...@@ -92,9 +96,6 @@ RSpec.describe Gitlab::Metrics::WebTransaction do
end end
context 'when request goes to ActionController' do context 'when request goes to ActionController' do
let(:request) { double(:request, format: double(:format, ref: :html)) }
let(:controller_class) { double(:controller_class, name: 'TestController') }
before do before do
controller = double(:controller, class: controller_class, action_name: 'show', request: request) controller = double(:controller, class: controller_class, action_name: 'show', request: request)
...@@ -129,6 +130,19 @@ RSpec.describe Gitlab::Metrics::WebTransaction do ...@@ -129,6 +130,19 @@ RSpec.describe Gitlab::Metrics::WebTransaction do
end end
end end
it 'returns the same labels for API and controller requests' do
route = double(:route, request_method: 'GET', path: '/:version/projects/:id/archive(.:format)')
endpoint = double(:endpoint, route: route)
api_env = { 'api.endpoint' => endpoint }
api_labels = described_class.new(api_env).labels
controller = double(:controller, class: controller_class, action_name: 'show', request: request)
controller_env = { 'action_controller.instance' => controller }
controller_labels = described_class.new(controller_env).labels
expect(api_labels.keys).to contain_exactly(*controller_labels.keys)
end
it 'returns no labels when no route information is present in env' do it 'returns no labels when no route information is present in env' do
expect(transaction.labels).to eq({}) expect(transaction.labels).to eq({})
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