Commit a41287d8 authored by Yorick Peterse's avatar Yorick Peterse

Only track method calls above a certain threshold

This ensures we don't end up wasting resources by tracking method calls
that only take a few microseconds. By default the threshold is 10
milliseconds but this can be changed using the gitlab.yml configuration
file.
parent 13dbd663
......@@ -432,6 +432,9 @@ production: &base
# pool_size: 16
# The timeout of a connection in seconds.
# timeout: 10
# The minimum amount of milliseconds a method call has to take before it's
# tracked. Defaults to 10.
# method_call_threshold: 10
development:
<<: *base
......
......@@ -16,6 +16,10 @@ module Gitlab
!!Settings.metrics['enabled']
end
def self.method_call_threshold
Settings.metrics['method_call_threshold'] || 10
end
def self.pool
@pool
end
......
......@@ -99,9 +99,11 @@ module Gitlab
retval = __send__(#{alias_name.inspect}, *args, &block)
duration = (Time.now - start) * 1000.0
trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES,
{ duration: duration },
method: #{label.inspect})
if duration >= Gitlab::Metrics.method_call_threshold
trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES,
{ duration: duration },
method: #{label.inspect})
end
retval
else
......
......@@ -42,6 +42,9 @@ describe Gitlab::Metrics::Instrumentation do
end
it 'tracks the call duration upon calling the method' do
allow(Gitlab::Metrics).to receive(:method_call_threshold).
and_return(0)
allow(described_class).to receive(:transaction).
and_return(transaction)
......@@ -51,6 +54,15 @@ describe Gitlab::Metrics::Instrumentation do
@dummy.foo
end
it 'does not track method calls below a given duration threshold' do
allow(Gitlab::Metrics).to receive(:method_call_threshold).
and_return(100)
expect(transaction).to_not receive(:add_metric)
@dummy.foo
end
end
describe 'with metrics disabled' do
......@@ -84,6 +96,9 @@ describe Gitlab::Metrics::Instrumentation do
end
it 'tracks the call duration upon calling the method' do
allow(Gitlab::Metrics).to receive(:method_call_threshold).
and_return(0)
allow(described_class).to receive(:transaction).
and_return(transaction)
......@@ -93,6 +108,15 @@ describe Gitlab::Metrics::Instrumentation do
@dummy.new.bar
end
it 'does not track method calls below a given duration threshold' do
allow(Gitlab::Metrics).to receive(:method_call_threshold).
and_return(100)
expect(transaction).to_not receive(:add_metric)
@dummy.new.bar
end
end
describe 'with metrics disabled' do
......
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