summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/metrics
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-06-13 16:23:17 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-06-14 13:06:46 +0200
commit509082bafb01e39f4dac6f45b4ea98129ed5109c (patch)
tree1a45467ff8f337e969ec6ac093b65e8054b930d2 /spec/lib/gitlab/metrics
parent0c0ef7dfb6afb1695b62037fc0fa5aba6ce697d7 (diff)
downloadgitlab-ce-509082bafb01e39f4dac6f45b4ea98129ed5109c.tar.gz
Instrument Grape Endpoint with Metrics::RackMiddleware18449-instrument-grape-endpoints
Generating the following tags Grape#GET /projects/:id/archive from Grape::Route objects like { :path => /:version/projects/:id/archive(.:format) :version => “v3”, :method => “GET” } Use an instance variable to cache raw_path transformations. This variable is only going to growth to the number of endpoints of the API, not with exact different requests We can store this cache as an instance variable because middleware are initialised only once
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r--spec/lib/gitlab/metrics/rack_middleware_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/rack_middleware_spec.rb b/spec/lib/gitlab/metrics/rack_middleware_spec.rb
index b99be4e1060..40289f8b972 100644
--- a/spec/lib/gitlab/metrics/rack_middleware_spec.rb
+++ b/spec/lib/gitlab/metrics/rack_middleware_spec.rb
@@ -31,6 +31,20 @@ describe Gitlab::Metrics::RackMiddleware do
middleware.call(env)
end
+
+ it 'tags a transaction with the method andpath of the route in the grape endpoint' do
+ route = double(:route, route_method: "GET", route_path: "/:version/projects/:id/archive(.:format)")
+ endpoint = double(:endpoint, route: route)
+
+ env['api.endpoint'] = endpoint
+
+ allow(app).to receive(:call).with(env)
+
+ expect(middleware).to receive(:tag_endpoint).
+ with(an_instance_of(Gitlab::Metrics::Transaction), env)
+
+ middleware.call(env)
+ end
end
describe '#transaction_from_env' do
@@ -60,4 +74,19 @@ describe Gitlab::Metrics::RackMiddleware do
expect(transaction.action).to eq('TestController#show')
end
end
+
+ describe '#tag_endpoint' do
+ let(:transaction) { middleware.transaction_from_env(env) }
+
+ it 'tags a transaction with the method and path of the route in the grape endpount' do
+ route = double(:route, route_method: "GET", route_path: "/:version/projects/:id/archive(.:format)")
+ endpoint = double(:endpoint, route: route)
+
+ env['api.endpoint'] = endpoint
+
+ middleware.tag_endpoint(transaction, env)
+
+ expect(transaction.action).to eq('Grape#GET /projects/:id/archive')
+ end
+ end
end