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 ...@@ -432,6 +432,9 @@ production: &base
# pool_size: 16 # pool_size: 16
# The timeout of a connection in seconds. # The timeout of a connection in seconds.
# timeout: 10 # 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: development:
<<: *base <<: *base
......
...@@ -16,6 +16,10 @@ module Gitlab ...@@ -16,6 +16,10 @@ module Gitlab
!!Settings.metrics['enabled'] !!Settings.metrics['enabled']
end end
def self.method_call_threshold
Settings.metrics['method_call_threshold'] || 10
end
def self.pool def self.pool
@pool @pool
end end
......
...@@ -99,9 +99,11 @@ module Gitlab ...@@ -99,9 +99,11 @@ module Gitlab
retval = __send__(#{alias_name.inspect}, *args, &block) retval = __send__(#{alias_name.inspect}, *args, &block)
duration = (Time.now - start) * 1000.0 duration = (Time.now - start) * 1000.0
trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES, if duration >= Gitlab::Metrics.method_call_threshold
{ duration: duration }, trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES,
method: #{label.inspect}) { duration: duration },
method: #{label.inspect})
end
retval retval
else else
......
...@@ -42,6 +42,9 @@ describe Gitlab::Metrics::Instrumentation do ...@@ -42,6 +42,9 @@ describe Gitlab::Metrics::Instrumentation do
end end
it 'tracks the call duration upon calling the method' do 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). allow(described_class).to receive(:transaction).
and_return(transaction) and_return(transaction)
...@@ -51,6 +54,15 @@ describe Gitlab::Metrics::Instrumentation do ...@@ -51,6 +54,15 @@ describe Gitlab::Metrics::Instrumentation do
@dummy.foo @dummy.foo
end 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 end
describe 'with metrics disabled' do describe 'with metrics disabled' do
...@@ -84,6 +96,9 @@ describe Gitlab::Metrics::Instrumentation do ...@@ -84,6 +96,9 @@ describe Gitlab::Metrics::Instrumentation do
end end
it 'tracks the call duration upon calling the method' do 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). allow(described_class).to receive(:transaction).
and_return(transaction) and_return(transaction)
...@@ -93,6 +108,15 @@ describe Gitlab::Metrics::Instrumentation do ...@@ -93,6 +108,15 @@ describe Gitlab::Metrics::Instrumentation do
@dummy.new.bar @dummy.new.bar
end 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 end
describe 'with metrics disabled' do 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