Commit 166ef222 authored by Robert Speicher's avatar Robert Speicher Committed by Yorick Peterse

Merge branch 'fix-grape-internal-allowed-action' into 'master'

Fix setting of "action" for Grape transactions

After wondering why we're not getting all the data in Grafana that I
wanted I realized I wasn't setting the "action" field properly here.

See merge request !3842
parent d793dc8b
...@@ -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