Commit 96075be6 authored by Yorick Peterse's avatar Yorick Peterse

Ability to increment custom transaction values

This will be used to store/increment the total query/view rendering
timings on a per transaction basis. This in turn can greatly reduce the
amount of metrics stored.
parent cafc784e
......@@ -19,7 +19,8 @@ module Gitlab
@started_at = nil
@finished_at = nil
@tags = {}
@values = Hash.new(0)
@tags = {}
end
def duration
......@@ -44,6 +45,10 @@ module Gitlab
@metrics << Metric.new(series, values, tags)
end
def increment(name, value)
@values[name] += value
end
def add_tag(key, value)
@tags[key] = value
end
......@@ -54,7 +59,13 @@ module Gitlab
end
def track_self
add_metric(@series, { duration: duration }, @tags)
values = { duration: duration }
@values.each do |name, value|
values[name] = value
end
add_metric(@series, values, @tags)
end
def submit
......
......@@ -38,6 +38,18 @@ describe Gitlab::Metrics::Transaction do
end
end
describe '#increment' do
it 'increments a counter' do
transaction.increment(:time, 1)
transaction.increment(:time, 2)
expect(transaction).to receive(:add_metric).
with('rspec', { duration: 0.0, time: 3 }, {})
transaction.track_self
end
end
describe '#add_tag' do
it 'adds a tag' do
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