Commit 38d5c760 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add feature category to API latency histogram

This populates the `feature_category` label on the
`gitlab_transaction_duration_seconds` histogram.

This histogram already contains this information for regular
controller requests.

The feature category per endpoint is always the same, so this doesn't
really increase cardinality.
parent 11277843
...@@ -66,9 +66,10 @@ module Gitlab ...@@ -66,9 +66,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]
# Feature categories will be added for grape endpoints in grape_class = endpoint.options[:for]
# https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/462 feature_category = grape_class.try(:feature_category_for_app, endpoint).to_s
{ controller: 'Grape', action: "#{route.request_method} #{path}", feature_category: '' }
{ controller: 'Grape', action: "#{route.request_method} #{path}", feature_category: feature_category }
end end
end end
......
...@@ -80,13 +80,15 @@ RSpec.describe Gitlab::Metrics::WebTransaction do ...@@ -80,13 +80,15 @@ RSpec.describe Gitlab::Metrics::WebTransaction do
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)')
endpoint = double(:endpoint, route: route) endpoint = double(:endpoint, route: route,
options: { for: API::Projects, path: [":id/archive"] },
namespace: "/projects")
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', feature_category: '' }) expect(transaction.labels).to eq({ controller: 'Grape', action: 'GET /projects/:id/archive', feature_category: 'projects' })
end end
it 'contains only the labels defined for transactions' do it 'contains only the labels defined for transactions' do
......
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