Commit a257d117 authored by Yorick Peterse's avatar Yorick Peterse

Fix setting of "action" for Grape transactions

Merely setting the "action" tag will only result in the transaction
itself containing a value for this tag. To ensure other metrics also
contain this tag we must set the action using Transaction#action=
instead.
parent 832cdd3d
...@@ -23,7 +23,7 @@ module API ...@@ -23,7 +23,7 @@ module API
end end
post "/allowed" do post "/allowed" do
Gitlab::Metrics.tag_transaction('action', 'Grape#/internal/allowed') Gitlab::Metrics.action = 'Grape#/internal/allowed'
status 200 status 200
......
...@@ -115,6 +115,15 @@ module Gitlab ...@@ -115,6 +115,15 @@ module Gitlab
trans.add_tag(name, value) if trans trans.add_tag(name, value) if trans
end end
# Sets the action of the current transaction (if any)
#
# action - The name of the action.
def self.action=(action)
trans = current_transaction
trans.action = action if trans
end
# When enabled this should be set before being used as the usual pattern # When enabled this should be set before being used as the usual pattern
# "@foo ||= bar" is _not_ thread-safe. # "@foo ||= bar" is _not_ thread-safe.
if enabled? if enabled?
......
...@@ -123,4 +123,28 @@ describe Gitlab::Metrics do ...@@ -123,4 +123,28 @@ describe Gitlab::Metrics do
end end
end end
end end
describe '.action=' do
context 'without a transaction' do
it 'does nothing' do
expect_any_instance_of(Gitlab::Metrics::Transaction).
not_to receive(:action=)
Gitlab::Metrics.action = 'foo'
end
end
context 'with a transaction' do
it 'sets the action of a transaction' do
trans = Gitlab::Metrics::Transaction.new
expect(Gitlab::Metrics).to receive(:current_transaction).
and_return(trans)
expect(trans).to receive(:action=).with('foo')
Gitlab::Metrics.action = 'foo'
end
end
end
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