Merge branch 'remove-more-influxdb-tags' into 'master'
See merge request !2328
This commit is contained in:
commit
61561a9eeb
|
@ -32,8 +32,8 @@ module Gitlab
|
|||
def transaction_from_env(env)
|
||||
trans = Transaction.new
|
||||
|
||||
trans.add_tag(:request_method, env['REQUEST_METHOD'])
|
||||
trans.add_tag(:request_uri, env['REQUEST_URI'])
|
||||
trans.set(:request_uri, env['REQUEST_URI'])
|
||||
trans.set(:request_method, env['REQUEST_METHOD'])
|
||||
|
||||
trans
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ module Gitlab
|
|||
class Transaction
|
||||
THREAD_KEY = :_gitlab_metrics_transaction
|
||||
|
||||
attr_reader :uuid, :tags
|
||||
attr_reader :tags, :values
|
||||
|
||||
def self.current
|
||||
Thread.current[THREAD_KEY]
|
||||
|
@ -12,7 +12,6 @@ module Gitlab
|
|||
|
||||
def initialize
|
||||
@metrics = []
|
||||
@uuid = SecureRandom.uuid
|
||||
|
||||
@started_at = nil
|
||||
@finished_at = nil
|
||||
|
@ -38,7 +37,6 @@ module Gitlab
|
|||
end
|
||||
|
||||
def add_metric(series, values, tags = {})
|
||||
tags = tags.merge(transaction_id: @uuid)
|
||||
prefix = sidekiq? ? 'sidekiq_' : 'rails_'
|
||||
|
||||
@metrics << Metric.new("#{prefix}#{series}", values, tags)
|
||||
|
@ -48,6 +46,10 @@ module Gitlab
|
|||
@values[name] += value
|
||||
end
|
||||
|
||||
def set(name, value)
|
||||
@values[name] = value
|
||||
end
|
||||
|
||||
def add_tag(key, value)
|
||||
@tags[key] = value
|
||||
end
|
||||
|
|
|
@ -40,9 +40,9 @@ describe Gitlab::Metrics::RackMiddleware do
|
|||
expect(transaction).to be_an_instance_of(Gitlab::Metrics::Transaction)
|
||||
end
|
||||
|
||||
it 'tags the transaction with the request method and URI' do
|
||||
expect(transaction.tags[:request_method]).to eq('GET')
|
||||
expect(transaction.tags[:request_uri]).to eq('/foo')
|
||||
it 'stores the request method and URI in the transaction as values' do
|
||||
expect(transaction.values[:request_method]).to eq('GET')
|
||||
expect(transaction.values[:request_uri]).to eq('/foo')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ describe Gitlab::Metrics::Transaction do
|
|||
end
|
||||
|
||||
describe '#add_metric' do
|
||||
it 'adds a metric tagged with the transaction UUID' do
|
||||
it 'adds a metric to the transaction' do
|
||||
expect(Gitlab::Metrics::Metric).to receive(:new).
|
||||
with('rails_foo', { number: 10 }, { transaction_id: transaction.uuid })
|
||||
with('rails_foo', { number: 10 }, {})
|
||||
|
||||
transaction.add_metric('foo', number: 10)
|
||||
end
|
||||
|
@ -50,6 +50,17 @@ describe Gitlab::Metrics::Transaction do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#set' do
|
||||
it 'sets a value' do
|
||||
transaction.set(:number, 10)
|
||||
|
||||
expect(transaction).to receive(:add_metric).
|
||||
with('transactions', { duration: 0.0, number: 10 }, {})
|
||||
|
||||
transaction.track_self
|
||||
end
|
||||
end
|
||||
|
||||
describe '#add_tag' do
|
||||
it 'adds a tag' do
|
||||
transaction.add_tag(:foo, 'bar')
|
||||
|
|
Loading…
Reference in New Issue