Commit 7b10cb6f authored by Yorick Peterse's avatar Yorick Peterse

Store request methods/URIs as values

Since filtering by these values is very rare (they're mostly just
displayed as-is) we don't need to waste any index space by saving them
as tags. By storing them as values we also greatly reduce the number of
series in InfluxDB.
parent 364b07cf
...@@ -32,8 +32,8 @@ module Gitlab ...@@ -32,8 +32,8 @@ module Gitlab
def transaction_from_env(env) def transaction_from_env(env)
trans = Transaction.new trans = Transaction.new
trans.add_tag(:request_method, env['REQUEST_METHOD']) trans.set(:request_uri, env['REQUEST_URI'])
trans.add_tag(:request_uri, env['REQUEST_URI']) trans.set(:request_method, env['REQUEST_METHOD'])
trans trans
end end
......
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
class Transaction class Transaction
THREAD_KEY = :_gitlab_metrics_transaction THREAD_KEY = :_gitlab_metrics_transaction
attr_reader :tags attr_reader :tags, :values
def self.current def self.current
Thread.current[THREAD_KEY] Thread.current[THREAD_KEY]
...@@ -46,6 +46,10 @@ module Gitlab ...@@ -46,6 +46,10 @@ module Gitlab
@values[name] += value @values[name] += value
end end
def set(name, value)
@values[name] = value
end
def add_tag(key, value) def add_tag(key, value)
@tags[key] = value @tags[key] = value
end end
......
...@@ -40,9 +40,9 @@ describe Gitlab::Metrics::RackMiddleware do ...@@ -40,9 +40,9 @@ describe Gitlab::Metrics::RackMiddleware do
expect(transaction).to be_an_instance_of(Gitlab::Metrics::Transaction) expect(transaction).to be_an_instance_of(Gitlab::Metrics::Transaction)
end end
it 'tags the transaction with the request method and URI' do it 'stores the request method and URI in the transaction as values' do
expect(transaction.tags[:request_method]).to eq('GET') expect(transaction.values[:request_method]).to eq('GET')
expect(transaction.tags[:request_uri]).to eq('/foo') expect(transaction.values[:request_uri]).to eq('/foo')
end end
end end
......
...@@ -50,6 +50,17 @@ describe Gitlab::Metrics::Transaction do ...@@ -50,6 +50,17 @@ describe Gitlab::Metrics::Transaction do
end end
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 describe '#add_tag' do
it 'adds a tag' do it 'adds a tag' do
transaction.add_tag(:foo, 'bar') transaction.add_tag(:foo, 'bar')
......
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