Skip to content
Snippets Groups Projects
Verified Commit a257d117 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

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
No related branches found
No related tags found
2 merge requests!4779Test/#123 Master,!3842Fix setting of "action" for Grape transactions
Pipeline #
Loading
@@ -23,7 +23,7 @@ module API
Loading
@@ -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
   
Loading
Loading
Loading
@@ -115,6 +115,15 @@ module Gitlab
Loading
@@ -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?
Loading
Loading
Loading
@@ -123,4 +123,28 @@ describe Gitlab::Metrics do
Loading
@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment