Skip to content
Snippets Groups Projects
Commit 07f5a6f1 authored by Achilleas Pipinellis's avatar Achilleas Pipinellis
Browse files

Merge branch 'master' into docs_refactor

parents e8cf990d cd243b83
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -23,20 +23,29 @@ module Gitlab
@values = Hash.new(0)
@tags = {}
@action = action
@memory_before = 0
@memory_after = 0
end
 
def duration
@finished_at ? (@finished_at - @started_at) * 1000.0 : 0.0
end
 
def allocated_memory
@memory_after - @memory_before
end
def run
Thread.current[THREAD_KEY] = self
 
@started_at = Time.now
@memory_before = System.memory_usage
@started_at = Time.now
 
yield
ensure
@finished_at = Time.now
@memory_after = System.memory_usage
@finished_at = Time.now
 
Thread.current[THREAD_KEY] = nil
end
Loading
Loading
@@ -65,7 +74,7 @@ module Gitlab
end
 
def track_self
values = { duration: duration }
values = { duration: duration, allocated_memory: allocated_memory }
 
@values.each do |name, value|
values[name] = value
Loading
Loading
Loading
Loading
@@ -14,19 +14,12 @@ describe Gitlab::Metrics::Subscribers::ActionView do
 
before do
allow(subscriber).to receive(:current_transaction).and_return(transaction)
allow(Gitlab::Metrics).to receive(:last_relative_application_frame).
and_return(['app/views/x.html.haml', 4])
end
 
describe '#render_template' do
it 'tracks rendering of a template' do
values = { duration: 2.1 }
tags = {
view: 'app/views/x.html.haml',
file: 'app/views/x.html.haml',
line: 4
}
tags = { view: 'app/views/x.html.haml' }
 
expect(transaction).to receive(:increment).
with(:view_duration, 2.1)
Loading
Loading
Loading
Loading
@@ -11,6 +11,14 @@ describe Gitlab::Metrics::Transaction do
end
end
 
describe '#allocated_memory' do
it 'returns the allocated memory in bytes' do
transaction.run { 'a' * 32 }
expect(transaction.allocated_memory).to be_a_kind_of(Numeric)
end
end
describe '#run' do
it 'yields the supplied block' do
expect { |b| transaction.run(&b) }.to yield_control
Loading
Loading
@@ -43,8 +51,10 @@ describe Gitlab::Metrics::Transaction do
transaction.increment(:time, 1)
transaction.increment(:time, 2)
 
values = { duration: 0.0, time: 3, allocated_memory: a_kind_of(Numeric) }
expect(transaction).to receive(:add_metric).
with('transactions', { duration: 0.0, time: 3 }, {})
with('transactions', values, {})
 
transaction.track_self
end
Loading
Loading
@@ -54,8 +64,14 @@ describe Gitlab::Metrics::Transaction do
it 'sets a value' do
transaction.set(:number, 10)
 
values = {
duration: 0.0,
number: 10,
allocated_memory: a_kind_of(Numeric)
}
expect(transaction).to receive(:add_metric).
with('transactions', { duration: 0.0, number: 10 }, {})
with('transactions', values, {})
 
transaction.track_self
end
Loading
Loading
@@ -80,8 +96,13 @@ describe Gitlab::Metrics::Transaction do
 
describe '#track_self' do
it 'adds a metric for the transaction itself' do
values = {
duration: transaction.duration,
allocated_memory: a_kind_of(Numeric)
}
expect(transaction).to receive(:add_metric).
with('transactions', { duration: transaction.duration }, {})
with('transactions', values, {})
 
transaction.track_self
end
Loading
Loading
@@ -104,7 +125,7 @@ describe Gitlab::Metrics::Transaction do
hash = {
series: 'rails_transactions',
tags: { action: 'Foo#bar' },
values: { duration: 0.0 },
values: { duration: 0.0, allocated_memory: a_kind_of(Numeric) },
timestamp: an_instance_of(Fixnum)
}
 
Loading
Loading
Loading
Loading
@@ -13,15 +13,6 @@ describe Gitlab::Metrics do
end
end
 
describe '.last_relative_application_frame' do
it 'returns an Array containing a file path and line number' do
file, line = described_class.last_relative_application_frame
expect(line).to eq(__LINE__ - 2)
expect(file).to eq('spec/lib/gitlab/metrics_spec.rb')
end
end
describe '#submit_metrics' do
it 'prepares and writes the metrics to InfluxDB' do
connection = double(:connection)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment